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.]
Since this is based on
SoftwareSerial, some caveats apply (scroll down to the "Limitations" section). Otherwise:
- Anytime you use this patched library you MUST
#include <SoftwareSerial.h>in your sketch, even if you only want to use the standard
Serialfor Bluetooth. This is a limitation of the Arduino IDE.
class MeetAndroidnow defines an additional constructor
MeetAndroid(int rxPin, int txPin, long int baud). Using this constructor forces a
MeetAndroidobject 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.
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.
// inits a SoftwareSerial BT connection on rxPin=4, txPin=3, with baud=115200
MeetAndroid meetAndroid(4,3, 115200);
if(Serial.available() > 0)
char incomingByte = Serial.read();