A2A

A2Alogo

Arduino to Android || Android to Arduino

A tiny project (work in progress) aimed to design the building blocks of the bidirectionnal Arduino-Android communication, through Bluetooth.

Basically, one should be able to control lights, electric plugs (or whatever connected to an Arduino board) with an Android phone.

One of the features is to store remotely the local pins states (i.e. for each Arduino board, on their own memory) to allow multi-remote controler to control the connected environment. When booting up, the dedicated Android app will ask known blutooth devices about their state(s) and update accordingly its UI.

Codes (the Arduino template code and the Android one (early alpha)) are available on GitHub (soon…)

String inputString;
boolean stringComplete = false;

/***************************************************************************
* Protocole
* =========
* Letter:Valuen
* [A-Z]:[nnnn]
*
****************************************************************************/

void setup()
{
Serial.begin(115200);
inputString.reserve(10);

}

void loop()
{
if(stringComplete){

char letter = ‘-‘;
char p[15];
char v[5];
char *ptr = p;
char *str;

inputString.toCharArray(p, 15);

while ((str = strtok_r(ptr, « : », &ptr)) != NULL){
if(letter == ‘-‘){
letter = *str;
}
else {
String stringOne = str;
stringOne.trim();
stringOne.toCharArray(v, 5);
}
}

switch(letter){
case ‘A’:
Serial.print(« A case: « );
Serial.println(v);
break;

case ‘B’:
Serial.print(« B case: « );
Serial.println(v);
break;

case ‘C’:
Serial.print(« C case: « );
Serial.println(v);
break;

case ‘D’:
Serial.print(« D case: « );
Serial.println(v);
break;

case ‘E’:
Serial.print(« E case: « );
Serial.println(v);
break;

case ‘F’:
Serial.print(« F case: « );
Serial.println(v);
break;
}
stringComplete = false;
inputString= » »;
}
}

void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == ‘n’) {
stringComplete = true;
}
}
}

Les commentaires sont clos.