#include const int Rx = 2; const int Tx = 3; SoftwareSerial ModuleBluetooth(Rx, Tx); unsigned long time=0; /////////////////////////////// void sendCommand(char * chaine){ unsigned long time=0; Serial.print("sending AT command: "); Serial.print(chaine); Serial.print(" -> "); while ((*chaine)!=0){ ModuleBluetooth.write(*chaine); chaine++; } ModuleBluetooth.write('\r'); ModuleBluetooth.write('\n'); time=micros(); while (micros()-time<500000){ //Laisse du temps au module pour répondre, et affiche la réponse dans la console Serial if (ModuleBluetooth.available()) { Serial.write(ModuleBluetooth.read()); } } Serial.println(""); delay(100); } /////////////////////////////// void setup() { // Ouvre la liaison série classique pour communiquer avec le PC Serial.begin(9600); Serial.println("salut"); // Ouvre la liaison série software pour communiquer avec le module bluetooth ModuleBluetooth.begin(9600); time=micros(); delay(200); //sendCommand("AT+RENEW"); //configuration usine sendCommand("AT+RESET"); //reboot sendCommand("AT"); delay(1000); sendCommand("AT+ADDR"); sendCommand("AT+VERSION"); //affiche la version du firmware delay(5000); sendCommand("AT"); sendCommand("AT+ROLE0"); //module en mode Peripheral (0) sendCommand("AT+ROLE"); //module en mode Peripheral (0) Serial.println("c'est parti!"); } /////////////////////////////// void loop() { // put your main code here, to run repeatedly: if (ModuleBluetooth.available()) { Serial.write(ModuleBluetooth.read()); } if (Serial.available()) { ModuleBluetooth.write(Serial.read()); } /* if ((micros()-time)>100000) { Serial.print("+"); time=micros(); } */ /* Serial.print("+"); delay(100); */ }