Archive for July, 2012
Configuring the DFRobot BluetoothV3
aka: What to do when your computer’s serial port uses different voltages than your bluetooth modem.
As part of the brainstorming on things I may want to do with my Raspberry PI, one thing that had occurred to me (and many others) would be to inter-work it with an Arduino. Now, this could be done via a USB cable, but I like to explore, and so instead I looked into a Bluetooth connection. I found on the Robotshop site a nice little module from DFRobot for $24 that could connect directly to the TTL serial port on an Arduino.
http://www.robotshop.com/ca/productinfo.aspx?pc=RB-Dfr-10&lang=en-US
But once I had this in hand, the question was how I am going to program it, set the baud rate etc? I comes set at 9600, and I wanted to turn it up to 38400. Since it uses TTL serial instead of RS-232 levels I could not directly connect it to a normal computer unless I used a level shifter. I didn’t at the time have a level shifter. My solution was to use the Arduino to act as an interface between the USB port on my computer and the TTL serial interface on the BluetoothV3.
I put a simple sketch onto the Arduino to connect the BluetoothV3 via a softserial port on pins D9 and D10. I then used the serial monitor that comes installed in the Arduino package to talk thru the Arduino the the Bluetooth device.
Notes:
1) In the serial monitor set it so that you are sending CR/LF terminations or else you won’t ever get a response from the BluetoothV3
2) On the BluetoothV3 you need to set the AT DIP switch to, “on” to indicate that the device should look for AT commands. Slide it back to off once you have completed your programming.
3) The BluetoothV3 does not remember pairing during a power cycle. Thus when communicating via bluetooth with other devices you may have to delete and re-pair the V3 after start-up. For example from an Android tablet, the tablet believed it was still paired with the V3, but would return a “Connect failed” error when trying to connect to the V3; but if I deleted the V3 from the Android’s known devices list it would then pair and connect without issue.
References:
1) This document lists the AT commands that the BluetoothV3 accepts: http://www.dfrobot.com/image/data/TEL0026/TEL0026_Datasheet.pdf
Here is the sketch that I ran on the Arduino. Change the baud rate in procedure, “setupBlueToothConnection” to 9600 for when you first start with the programming. Change it to 38400 after you have sent an, “AT+ORGL” command. Or set it the whatever speed you have set using an, “AT+UART” command.
/*
Based on example code from others
Uses softserial on D9 (RxD),D10 (TxD) to talk to bluetooth modem
*/
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 9
#define TxD 10
SoftwareSerial blueToothSerial(RxD,TxD);
char incoming;
void setup()
{
Serial.begin(9600);
delay(1000);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
Serial.println("Started");
}
void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothV3 baud rate to 38400
delay(1000);
}
void loop()
{
if (blueToothSerial.available())
Serial.write(blueToothSerial.read());
if (Serial.available())
blueToothSerial.write(Serial.read());
}
Notta photo: Geeking out with a Raspberry PI
So I am sitting at my Windows 7 PC, running Cygwin-X Xwin server, and I have this xterm window open which is connecting me via wired ethernet to the command line interface of a Raspberry PI (GNU/Linux computer). The Raspberry PI is running headless (no keyboard, monitor, nor mouse) and has the SSH daemon running for remote access. Now on this Raspberry PI I have inserted a Bluetooth dongle, and over said dongle I am then running minicom through bluetooth SP protocol using the Bluez package. The other end of this wireless link is a DFRobots BluetoothV3 modem. The bluetooth modem is connected via a soft-serial port on an Arduino Nano micro-controller which is running a simple sketch which listens to the serial port for numerals 1 through 4. If/when the Arduino receives any of these numerals it then toggles the state of one of 4 LEDs connected to the Arduino GPIO pins. So in the end of this chain of improbably connected hardware and software I can make some lights go on and off, on and off, on and off, on and off…
So the simple drawing:
PC –ethernet–> RaspberryPI –USB–> BluetoothDongle –wireless–> BlutoothModem –TTLserial–> ArduinoNano –> shiny lights
———————————————————————————
And some pictures since this sometimes is a photo blog:
\
The PC, basically a terminal

The Raspberry PI GNU/Linux computer with USB Bluetooth dongle

The Arduino Nano and the Bluetooth modem/serial adapter

ACHTUNG!
ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS!
DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKSEN.
IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS.
ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN.
——————————————————–
So getting the Raspberry PI to pair and then communicate with the DF Robots Bluetooth modem took a lot longer than I expected. In the end the problem was that I need to use the appplication, “bluetooth-agent” to provide the PIN to pair the devices. This was not clear as most online references for bluez refer to either using the GUI, or using “/etc/bluetooth/hcid.conf”. But I eventually found some info that said hcid.conf was no longer part of bluez, and that for command line pairing you could use bluetooth-agent.
For all of this example I am running linux image: 2012-07-15-wheezy-raspbian
A short summary of commands, all of these are run as root or using sudo:
1) To install bluez and minicom
apt-get install bluez minicom
2) Make sure bluetooth services are running
/etc/init.d/bluetooth start
3) Clean up before we start
rfcomm release hci0 hciconfig -a hci0 reset
4) Check that your bluetooth device is working (third line of response says UP)
hciconfig -a hci0: Type: BR/EDR Bus: USB BD Address: 00:15:83:3D:0A:57 ACL MTU: 192:8 SCO MTU: 64:8 UP RUNNING PSCAN RX bytes:12234 acl:112 sco:0 events:427 errors:0 TX bytes:3253 acl:78 sco:0 commands:177 errors:0 ...
5) Find the address for the far-end bluetooth modem (address is XX:XX:XX:XX:XX:XX in response)
hcitool scan Scanning ... 00:12:04:20:50:55 H-C-2010-06-01
6) Optionall try pinging to see if we can talk to the far device
l2ping 00:12:04:20:50:55 Ping: 00:12:04:20:50:55 from 00:15:83:3D:0A:57 (data size 44) ... 4 bytes from 00:12:04:20:50:55 id 0 time 13.51ms 4 bytes from 00:12:04:20:50:55 id 1 time 75.69ms 4 bytes from 00:12:04:20:50:55 id 2 time 36.93ms
7) Find the channel used for SP (serial protocol) on the far-end bluetooth modem (channel info in protocol descriptor section)
sdptool search SP 00:12:04:20:50:55
Inquiring ...
Searching for SP on 00:12:04:20:50:55 ...
Service Name: Dev B
Service RecHandle: 0x10000
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
8. Start (and leave running) the bluetooth agent to send the PIN to the far end when it is asked for. In this case my PIN is 1234.
bluetooth-agent 1234 hci0 &
9) Start the connection from /dev/rfcomm0 device to the far end. Here we use our address and channel “00:12:04:20:50:55 1″
sudo rfcomm connect hci0 00:12:04:20:50:55 1
11) Now in another window, as a regular user, we can use minicom to connect over the link. In this case I am using 38,400 bps as this is what is in my Arduino sketch and what is set in the DF Robot BluetoothV3.
sudo minicom -D /dev/rfcomm0 -b 38400
-or to run minicom without using sudo-
sudo ln /dev/rfcomm0 /dev/ttyS0 sudo chmod 766 /dev/ttyS0 minicom -D /dev/ttyS0 -b 38400
——————————————————————————
Wow, that was a lot of crap.
But how did you initially setup the DFRobot BluetoothV3?
What sketch is running on the Arduino?
I’ll do that in another post. It is getting late.






