Saturday 15 September 2012

bluetooth - Receiving multiple chars at once with Software Serial -



bluetooth - Receiving multiple chars at once with Software Serial -

i have arduino uno r3 , bluetooth mate. when linking mate arduino hardware serial (pin 0,1) can send multiple characters @ 1 time connected device when seek create same thing software serial (using pin 4,2 example) first character , rest of chars messed up.

my code:

#include <softwareserial.h>   int bluetoothtx = 4;   int bluetoothrx = 2;   softwareserial bluetooth(bluetoothtx, bluetoothrx); void setup() {  serial.begin(115200);    bluetooth.begin(115200);   } void loop() {  if(bluetooth.available())  {    serial.print((char)bluetooth.read());    } }

for illustration if send chars: abcd android device in serial monitor: a±,รถ

this code uses hardware serial (i link bluetooth pins 0 , 1) works fine:

void setup() {  serial.begin(115200);   } void loop() {  if(serial.available())  {    serial.print((char)serial.read());    } }

i tried changing baud rate didn't helped

if send chars 1 1 works fine able send them string.

as pointed out @hyperflexed in comments baudrate related issue. had take baudrate low 9600 create work.

this code worked:

#include "softwareserial.h"; int bluetoothtx = 4; int bluetoothrx = 2; softwareserial bluetooth(bluetoothtx, bluetoothrx); void setup() { serial.begin(9600); delay(500); bluetooth.begin(115200); delay(500); bluetooth.print("$$$"); delay(500); bluetooth.println("u,9600,n"); delay(500); bluetooth.begin(9600); } void loop() { if(bluetooth.available()) { char tosend = (char)bluetooth.read(); serial.print(tosend); } if(serial.available()) { char tosend = (char)serial.read(); bluetooth.print(tosend); } }

for changing baudrate had set big delays create sure commands executed otherwise won't work.

bluetooth arduino software-serial

No comments:

Post a Comment