Arduino Bits and Pieces

I've recently been dabling with some Arduino boards, and while I've not done anything particulary clever with them yet, here are a few bits that might be usefull to someone.

Getting started with the Bluetooth Shield

The Stackable Bluetooth Shield v2.1(slave) arrived from ebay and I hooked it up to my UNO board... and then nothing happened!!! It took a bit of searching to find any instructions and there wasn't a definitive source, so I thought I'd post them in one place.

Assuming you've got your Arduino set up and working in the first place it's actually pretty trivial to work with the BT board, but can be confusing until you work out what's supposed to be happening.

Step one is of course to plug your shield into your arduino. Pretty idiot proof you'd think but it doesn't help that they've put a nice voltage select switch on the thing. A jumper would have been a but more friendly, but I suppose that having a "blow my device up" switch is a good way to sell more devices. Assuming you're using an UNO or similar this should be set to 5V and never changed.

Step two is to pair your computer with the BT shield. This just lets them talk to each other. I'm using OSX Lion - exact details might be different for your OS. Select "Setup Bluetooth Device..." from the BT menu or control panel,and you should be able to locate and pair with your device. Mine came up as "ITEAD", but different manufacturers might be different. You can change this later if you want something more personal or if you have more than one device. When you select the device it'll ask you how to verify. The boards default to a passcode of 1234, so enter this as the default passcode and you should be good to go.

Now make sure your shield is switched to its connected "to FT232". Hook up your USB cable if you haven't already and you should be good to go, programming your device from the IDE as per usual. The shield is acting as a passthrough at this stage so everything is working as normal.

Try the simple variant on "Blink":

/*Serial Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Print Diagnostics on the serial port.

This example code is in the public domain.
*/

void setup() { 
pinMode(13, OUTPUT);
Serial.begin(9600); // set up serial port 
}

void loop() {
digitalWrite(13, HIGH); // set the LED on
Serial.println("On");
delay(1000);// wait for a second

digitalWrite(13, LOW); // set the LED off
Serial.println("Off");
delay(1000); // wait for a second
}

When you run this you should get the usual status LED blink, but in addition if you select "Serial Monitor" from the IDE Tools menu you should get the On/Off messages printed in the monitor window.

So far so good, but we haven't actually done any Bluetooth. Well the neat thing is that the BT works just like the USB serial interface. On your computer fire up a terminal emulator (CoolTerm works great on the mac) and select a serial port that looks something like the name your bluetooth device paired with: On my system that came out as "tty.itead-DevB". The other settings should probably be 9600 baud, 8 data bits, no parity, 1 stop bit but again devices can be configured differently.

Now on the BT shield, move the switch to "To Board", then hit "Connect" in CoolTerm. If all is good then the "D1" LED that's been flashing on the shield should go solid to indicate its connected. Once you're connected if all is good (and the blink code above is still running) then you should see the On/Off messages suddenly appear in CoolTerm. You can keep the USB connected to provide power, but thats a but pointless - hook up some batteries, do a reset and your mobile device should still be able to feed diagnostics back to your host PC!!!

That's it! Once you're set up you can send data back to the host PC either via USB (to FT232 setting), or BT (to board) setting without having to change your code. However as far as I can get it to work you can only download code through USB, not BT (which would be cool!).

Reconfiguring Your Board

You shouldn't need to do much more that the above, at least until you get the hang of things, but if you have more than one board, need higher data rates, or just want a better name for your device to appear in the BT pairing menu, then you need to reconfigure it.

Start by downloading the "BareMinimum" example sketch into your device - to effectively take the Arduino out of the equation. Then quit the Arduino IDE, but before you do make note of the serial port your device is connected to (via USB). Now fire up CoolTerm again, and select the USB serial port, then connect so we can talk directly to the shield.

Whatever you type you shouldn't see much back until you type "AT" which should wake up the bluetooth modem and it should reply "OK".

To change the baud rate (speed) type "AT+BAUD4" or some other number between 1 and 8. 1 is slowest and 8 us fastest:

1---------1200
2---------2400
3---------4800
4---------9600
5---------19200
6---------38400
7---------57600
8---------115200

Most usefully to change your device name use "AT+NAMEmynewname", and to change the pun code type "AT+PINxxxx" where xxxx is the new number.

Once you've done these you'll off course need to reconfigure your PC to connect to the new name with the new pin at the new speed. Also remember to reset the speed in the setup() function of your sketch.

Hope this helps - it had me head scratching till I found few forum posts which cleared things up. It's all obvious in retrospect but not when you're a newbie pulling a strange circuit board from a box which has NO INSTRUCTIONS in it!.


DCT Systems
NCCA, Bournemouth University