0

I use Amarino with SoftwareSerial (from here: http://www.double-oops.org/mini-blog/amarinowithsoftwareserial ) but I have a strange issue. It seems that there are some strange behaviour in the MeetAndroid Library. In order to receive events I had to make this changes:

in init() I had to change

ack = 19; 

with

ack = 226; 

because this is the char I received from the phone at the end of a message

and in receive() I had to change

uint8_t lastByte;

with

char lastByte;

otherwise the

if(lastByte == ack) 

won't be true ever

Does anyone have any idea why I had this problems? Why do i get another ack char and why is the if not working for char (ack) and uint8_t (lastByte)

This is my sketch:

/*
  Receives Test Events from your phone.
  After it gets a test message the led 13 will blink
  for one second.
*/

#include <MeetAndroid.h>
#include <SoftwareSerial.h>

MeetAndroid meetAndroid(4, 2, 115200);
int onboardLed = 13;

void setup()   
{
  meetAndroid.registerFunction(testEvent, 'A');  

  pinMode(onboardLed, OUTPUT);
  digitalWrite(onboardLed, HIGH);

}

void loop()
{
  meetAndroid.receive(); // you need to keep this in your loop() to receive events
}

void testEvent(byte flag, byte numOfValues)
{  
  flushLed(300);
  flushLed(300);
}

void flushLed(int time)
{
  digitalWrite(onboardLed, LOW);
  delay(time);
  digitalWrite(onboardLed, HIGH);
  delay(time);
}
dsolimano
  • 8,870
  • 3
  • 48
  • 63
amarkovits
  • 776
  • 1
  • 10
  • 17

1 Answers1

0

I found the problem, it is baudrate related. When using software serial I have to use a lower baudrate (9600 for example), otherwise when receiving multiple characters at once it won't work. And since amarino library sends multiple library at once (signaling the start and the end of the message for example) it caused problems when using software serial on slower hardware (like the Arduino Uno used by me). Probably with better hardware (Arduino Mega) changing the baudrate is not necessary.

Example for changing the baudrate is available here:

Receiving multiple chars at once with Software Serial

Long answered short:

When using SoftwareSerial on slower hardware use a low baudrate (like 9600). Also make sure to set the bluetooth board work on the lower baudrate.

Community
  • 1
  • 1
amarkovits
  • 776
  • 1
  • 10
  • 17