Can I program the bluetooth module itself?
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); }
}


