Amarino with SoftwareSerial

Post date: Jan 5, 2012 7:17:50 PM

https://sites.google.com/site/doubleoops/mini-blog/amarinowithsoftwareserial/MeetAndroid.cpp?attredirects=0&d=1I wanted to use Amarino such that the Bluetooth module was communicating with an Arduino via SoftwareSerial. I have nefarious plans for later that require the regular hardware-based Serial for something other than Bluetooth (hint: XBee!).

This diff, applied to Amarino's MeetAndroid library v.4, adds SoftwareSerial capability (compiled against Arduino version 1.0). [Update: Added the actual MeetAndroid.cpp and MeetAndroid.h files as attachments to this page.]

Usage

Since this is based on SoftwareSerial, some caveats apply (scroll down to the "Limitations" section). Otherwise:

  1. Anytime you use this patched library you MUST #include <SoftwareSerial.h> in your sketch, even if you only want to use the standard Serial for Bluetooth. This is a limitation of the Arduino IDE.
  2. class MeetAndroid now defines an additional constructor MeetAndroid(int rxPin, int txPin, long int baud). Using this constructor forces a MeetAndroid object to use SoftwareSerial, with the indicated pins and baud rate, instead of Serial. Note that, unlike when using Serial, MeetAndroid calls Stream.begin(baud) automatically when using SoftwareSerial.

Other than the new constructor, MeetAndroid's API is unchanged. All other public methods work exactly as before.

Testing

My test setup was an Arduino UNO with a Bluesmirf Gold Bluetooth modem running the sketch below and a Motorola XOOM, running Amarino, logging Bluetooth events. I discovered no conflicts (blocking, etc.) using both streams interspersed.

#include <MeetAndroid.h>
#include <Wire.h>
#include <SoftwareSerial.h>
// inits a SoftwareSerial BT connection on rxPin=4, txPin=3, with baud=115200
MeetAndroid meetAndroid(4,3, 115200);
void setup()
{ 
  Serial.begin(115200);
}
void loop()
{
  if(Serial.available() > 0)
  {
    char incomingByte = Serial.read();
    meetAndroid.send(incomingByte);
    meetAndroid.send('\0');
    Serial.println(incomingByte, HEX);
  }
}