XBee and BTM-182 configured via Arduino

I finally got my Ardunio to successfully configure both the XBee and this BTM-182 bluetooth serial module. Why would you want to do that? Well the XBee has six 10-bit resolution Analog to Digital Converter channels, and about 8 digital IO channels (all ADC channels double as DIO channels, so in total about 8 to play with). Another reason is if you want to only talk to one remote xbee module rather than them all, you could change it on the fly. For the bluetooth module, you can perform scanning of available BT things, and connect to them, all using the ‘Command’ mode.

This is another lesson for KISS I think, since when I first started to tackle this problem, I made these fancy functions to handle it. Well that didn’t work at first, but after some massaging, I got it working. Then I tried to get software serial working, but that didn’t work out. (I thought I configured it correctly, turns out I needed to declare inputs/outputs for the SW serial port)

Ultimately I decided to try the simplest while loop to handle the response, which worked out really well. I found out how to get the SW serial working by looking at this example which had SW serial running (the default examples in Arduino 1.0 IDE didn’t setup the input/output). I’ve attached the code below, it’s not pretty, but sharing is caring šŸ˜›

What you see in the picture are two NunChucks that I intend to get setup and running, and once they are running, I can send the joystick response anywhere šŸ˜› Once I get some parts in for the controller, I’ll go ahead and build it up. Then something to interface with (plant waterer). Fun times!!!

Ugly code below šŸ˜› Pretty code here: http://pastebin.com/HYCDTL89

http://pastebin.com/embed_iframe.php?i=HYCDTL89


#include "SoftwareSerial.h" //change " to greater than and less than symbols
#include "ShiftRegLCD.h" //change " to greater than and less than symbols
//
SoftwareSerial xbeeser(1, 0);
SoftwareSerial btser(7, 8);
//
const byte enPin = 5; // SR Clock from Arduino pin 11
const byte dataPin = 4; // SR Data from Arduino pin 10
const byte clockPin = 3; // SR Clock from Arduino pin 11
//
ShiftRegLCD srlcd(dataPin, clockPin, enPin);
//
//want simple XBEE config
#define XBEESLEEP 6 //Pin 12 for XBee sleep control, goes to pin 9 on xbee
//
void setup()
{
int result;
char state=0, temp;
//xbee
pinMode (1,INPUT);
pinMode (0,OUTPUT);
pinMode(XBEESLEEP,OUTPUT); //6
//bt
pinMode (7,INPUT);
pinMode (8,OUTPUT);

//
xbeeser.begin(19200);
btser.begin(19200);
//
srlcd.clear();
//
//setup xbee
digitalWrite(XBEESLEEP, LOW);
xbeeser.listen();
srlcd.print(“XBee”);
delay(1000);
xbeeser.print(“+++”); // xbeeser.write(0x0D);
delay(1000);
while(state != 6)
{
if(state == 3)
{
state++;
xbeeser.print(“ATCN”);
xbeeser.write(0x0D);
delay(100);
}
if(xbeeser.available())
{
temp = xbeeser.read();
if(temp == 0x0D)
{
state++;
continue;
}
if(temp == ‘O’)
state++;
if(temp == ‘K’)
state++;
srlcd.print((char)temp);
}
}
digitalWrite(XBEESLEEP, HIGH);
//xbee done, now BT
btser.listen();
btser.write(0x0D);
delay(1000);
btser.print(“ATA”); btser.write(0x0D);
delay(1000);
while(state != 3)
{
if(btser.available())
{
temp = btser.read();
if(temp == 0x0D || temp == 0x0A)
{
state++;
continue;
}
if(temp == ‘O’)
state++;
if(temp == ‘K’)
state++;
srlcd.print((char)temp);
}
}
//free of loop šŸ˜›
//delay(1000);
srlcd.clear();
// Print a message to the LCD.
srlcd.print(“HELLO, WORLD!”);
}
void loop()
{
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s