Bluetooth communication between Android and Arduino using Processing -
i trying make two-way bluetooth communication between android , arduino using processing android. have success transferring data android arduino serial.begin(9600). , have success transferring data arduino android using softwareserial in arduino program , bluetooth.begin(9600) in place of serial.begin(9600).
however, when trying transfer data android arduino using bluetooth.x commands, not work. here arduino code:
if (bluetooth.available()) // wait until character received { char val = (char)bluetooth.read(); //serial.println(val); switch(val) // perform action depending on command { case 'w'://turn light on when 'w' received on(); break; case 'q'://turn light off when 'q' received off(); break; //default://otherwise remain in previous state //idle(); break; } }
the on() , off() functions switch on , off led on arduino. mentioned, works when i'm using serial.x commands , not bluetooth.x commands. also, using ketai processing android. using processing 2.0.1, arduino 1.0.5, android 2.3.6.
here relevant beginning code:
#include <softwareserial.h> softwareserial bluetooth(0,1); //tx 0, rx 1
a little more code appreciated...
have included that?
#include <softwareserial.h> int bluetoothtx = 2; int bluetoothrx = 3; softwareserial bluetooth(bluetoothtx, bluetoothrx);
edit:
that's similar use. first upload code without bluetooth wired , wire bluetooth. can use serial.dosomething()
because using same pins, don't need #include <softwareserial.h>
. need make sure baudrate same.
you can try code make sure works fine:
void setup(){ serial.begin(9600); // or wathever bluetooth module baudrate } void loop(){ serial.println("hello world!"); // make sure works. delay(500); }
you should make sure you arduino connected computer via bluetooth.
Comments
Post a Comment