I am trying to make two-way bluetooth communication between Android and Arduino using Processing for Android. I have success transferring data from the Android to the Arduino with serial.begin(9600). And I have success transferring data from the Arduino to the Android by using SoftwareSerial in the Arduino program and bluetooth.begin(9600) in place of serial.begin(9600).
However, when trying to transfer data from the Android to the Arduino using bluetooth.x commands, it does not work. Here is the Arduino code:
if (bluetooth.available()) // Wait until a character is received
{
char val = (char)bluetooth.read();
//Serial.println(val);
switch(val) // Perform an action depending on the command
{
case 'w'://turn the light on when a 'w' is received
on();
break;
case 'q'://turn the light off when a 'q' is received
off();
break;
//default://otherwise remain in the previous state
//idle();
break;
}
}
The on() and off() functions switch on and off an LED on the Arduino. As mentioned, this works when I'm using serial.x commands and not bluetooth.x commands. Also, I am using Ketai for Processing for Android. I am using Processing 2.0.1, Arduino 1.0.5, Android 2.3.6.
Here is the relevant beginning code:
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(0,1); //TX 0, RX 1