How do I resolve the issue the device must be connected to the computer via usb port and “AT + ROLE0” command must be entered on Arduino serial monitor page in order to establish the BLE communication on the device as a slave. if you power down the device via a battery switch you must go thru the same process above.
Does the AT+ROLE0 command need to be in non volatile memory?
I also tried to add the AT+RELE0 in the setup function.
I want to be able to have the device independent from the computer.
I have enclosed the sample sketch
#include “xadow.h”
/************************************************************************************************
** Function name: setup
** Descriptions: Start the i2c and serial data protocols
************************************************************************************************/
void setup(){
Serial.begin(9600); // Opens serial connection at 9600 baud.
Serial1.begin(9600); // Opens serial to bluetooth at 9600 baud.
while (!Serial.available());
Serial1.print(“AT+ROLE0”); // Sets the bluetooth module as a slave but doesn’t work
// This must also be sent through the serial monitor
printhelp();
delay(1000);
}
/************************************************************************************************
** Function name: printhelp
** Descriptions:
************************************************************************************************/
void printhelp() {
Serial1.println(“To check the battery send a ‘b’”);
}
/************************************************************************************************
** Function name: showbat
** Descriptions: Show the battery level
************************************************************************************************/
void showbat() {
Serial1.println(Xadow.getBatVol());
}
/***********************************************************************************************
** Function name: loop
** Descriptions:
************************************************************************************************/
void loop(){
for(int i = 0; i<20; i++){ // BLE waits for 20 characters before switching to the position
if(Serial.available()) { // data collection state. The 20 is arbitrary, it can be reduced
Serial1.println(Serial.read()); // down to maybe around 5 because using the commands properly
} // yields input that should not be longer than 5 characters…
if(Serial1.available()) { // unless the athlete is lifting more that 4 digits of weight
char c = Serial1.read(); // which is unlikely.
Serial.println©;
if (c == '?') {
printhelp();
}
else if (c == 'b') {
showbat();
else {
}
}
}
}