Yes, you can re-program the bluetooth module using AT commands. Here's a way to do that wwith your Sparki robot by using a custom program.
Plug in the bluetooth module as you normally would, and upload the attached program to Sparki.
After the module is plugged in and Sparki is reset, the RGB will change to yellow as it attempts to program the bluetooth, then green for a good re-program, or red for a bad re-program.
#include int timeBetweenTests = 600; void setup() { // initialize the digital pin as an output. Serial.begin(9600); Serial1.begin(9600); } char incoming=0; char outgoing=0; // the loop routine runs over and over again forever: void loop() { sparki.RGB(255,255,0); Serial1.begin(9600); while(Serial1.available() != 0){ incoming = Serial1.read(); Serial.print(incoming); } delay(timeBetweenTests); Serial.println("~~Programming~~"); // Set the device to operate at baud 9600 Serial.println("Sending: AT+BAUD4"); Serial1.print("AT+BAUD4"); Serial.print("Received: "); delay(timeBetweenTests); Serial1.begin(9600); delay(timeBetweenTests); while(Serial1.available() != 0){ incoming = Serial1.read(); Serial.print(incoming); } Serial.println(); delay(timeBetweenTests); // Send AT to test for basic AT command set functionality Serial.println("Sending: AT"); Serial1.print("AT"); String correctReply = "OK\0"; char reply[20] = ""; int replyCounter = 0; char incoming; int test1 = 0; Serial.print("Received: "); delay(timeBetweenTests); while(Serial1.available() != 0){ incoming = Serial1.read(); reply[replyCounter] = incoming; reply[replyCounter+1] = '\0'; replyCounter++; Serial.print(incoming); } Serial.println(); Serial.print("Good?: "); if(String(reply) ==correctReply){ test1 = 1; Serial.println("PASS!"); } else{ Serial.println("FAIL!"); } Serial.println(); delay(timeBetweenTests); // Test the linvor version to maker sure the command set is compatible Serial.println("Sending: AT+VERSION"); Serial1.print("AT+VERSION"); correctReply = "OKlinvorV1.8"; replyCounter = 0; int test2 = 0; Serial.print("Received: "); delay(timeBetweenTests); while(Serial1.available() != 0){ incoming = Serial1.read(); reply[replyCounter] = incoming; reply[replyCounter+1] = '\0'; replyCounter++; Serial.print(incoming); } Serial.println(); Serial.print("Good?: "); if(String(reply).equals(correctReply)){ test2 = 1; Serial.println("PASS!"); } else{ Serial.println("FAIL!"); } Serial.println(); delay(timeBetweenTests); // Set the broadcast name Serial.println("Sending: AT+NAMEArcBotics"); Serial1.print("AT+NAMEArcBotics"); correctReply = "OKsetname"; replyCounter = 0; int test3 = 0; Serial.print("Received: "); delay(timeBetweenTests); while(Serial1.available() != 0){ incoming = Serial1.read(); reply[replyCounter] = incoming; reply[replyCounter+1] = '\0'; replyCounter++; Serial.print(incoming); } Serial.println(); Serial.print("Good?: "); if(String(reply) ==correctReply){ test3 = 1; Serial.println("PASS!"); } else{ Serial.println("FAIL!"); } Serial.println(); delay(timeBetweenTests); // Test the security pin to be autmatically compatible for OSX and windows Serial.println("Sending: AT+PIN0000"); Serial1.print("AT+PIN0000"); correctReply = "OKsetPIN"; replyCounter = 0; int test4 = 0; Serial.print("Received: "); delay(timeBetweenTests); while(Serial1.available() != 0){ incoming = Serial1.read(); reply[replyCounter] = incoming; reply[replyCounter+1] = '\0'; replyCounter++; Serial.print(incoming); } Serial.println(); Serial.print("Good?: "); if(String(reply) ==correctReply){ test4 = 1; Serial.println("PASS!"); } else{ Serial.println("FAIL!"); } Serial.println(); delay(timeBetweenTests); // Completed! Tally up and see if it worked. Serial.print("Final Result: "); if(test1 & test2 & test3 & test4){ Serial.println("all good!"); sparki.RGB(RGB_GREEN); sparki.beep(5000, 50); delay(100); sparki.beep(5000, 50); } else{ Serial.println("FAILED PROGRAMMING"); sparki.RGB(RGB_RED); sparki.beep(500, 500); } Serial.println("~~Done!~~"); while(true){ delay(1000); } }
0 Comments