bluetooth controlled I/O board


10 posts
by legionlabs » Thu May 24, 2012 6:15 pm
Greetings from Foulab (Montreal Hackerspace),

Got my raspberry pi in the mail 3 days ago. First project was to make a bluetooth controlled I/O board with 24 pins, ADC and PWM options. Why? Robotics, motor control, remote sensing, etc without cables and with good isolation. Also, while I am more or less comfortable connecting/soldering things directly to the board, some people I work with are not. I'll document the project as it progresses here in case it is useful to others. For the purpose of brevity I'll avoid topics already covered in the datasheets of the relevant devices, and assume you can install software.

Day 1: Installed Debian Squeeze. Got SSH/vncserver running. Had connected an Apple II monochrome screen to start, which was fun, but got tired of that fast.

Day 2: Got the serial port (/dev/tty/AMA0) playing nicely with python. Built a circuit to convert the 3v3 serial to TTL serial, provide some isolation, and clean up spurious signals (really just a pull-up transistor, diode protection, and a scmitt trigger hex inverter). It's a trivial circuit but I'll provide it if someone wants it.

Day 3: Had this bluetooth dongle lying around, and this bluetooth to serial adapter:
http://www.dealextreme.com/p/super-mini ... ible-11866
http://www.dealextreme.com/p/wireless-b ... 711?item=8

I can confirm both work with the raspberry pi. For the bluetooth dongle, just plug it in. For the bluetooth serial port, you'll need to do the following:

#hcitool scan
This should give you the address and name of the bluetooth adapter (in my case, address 00:12:02:28:76:87 name: linvor)

#hcitool cc 00:12:02:28:76:87
This connects to the bluetooth device at address 00:12:02:28:76:87

#rfcomm connect 0 00:12:02:28:76:87 1
This creates serial device /dev/rfcomm0 located at this address on bluetooth channel 1
#ls /dev
This will output a list of devices, make sure something with rfcomm# is there

Now in python:
-----
import serial
ser=serial.Serial(port='/dev/rfcomm0',baud='9600')
x=7
ser.write('x')
-----
You'll see 3v3 volt serial data come out of the transceiver. Convert to 5v TTL serial and you're ready to connect to an MCU over bluetooth (skip this step if your MCU already uses 3v3). Keep in mind pyserial sends ASCII characters, so if you want to send the number 5, not the date for the ASCII character 5, you need to do this (in python):

x=55
x1=chr(x)
ser.write(x)

To come: Now it should be a simple matter of writing some assembly for an MCU, then a driver for the python end. The MCU just has to receive and echo commands (for error correction) and then enable/disable/send data at the various MCU I/O. Should not be difficult, I've done this before.
Posts: 5
Joined: Wed May 23, 2012 5:20 pm
by legionlabs » Thu May 24, 2012 8:12 pm
Silly me: The last line of python should read:

ser.write(x1)
Posts: 5
Joined: Wed May 23, 2012 5:20 pm
by legionlabs » Sat May 26, 2012 12:26 am
Day 4: Wrote the assembly code (AVR assembly) in about 4 hours. Completely untested, but no errors during assembly. Unlikely to work, will debug another day.

I attached the un-debugged code (all 8kb) so it can be later compared to what works later. It is a zipped .txt file.

A full feature list is in the code comments. For some reason I added 8 independent ADC channels (only 8 bit resolution though, could expand this to 10 if useful).

The protocol/driver for the board is trivial and happens over 9600 baud serial over bluetooth (maybe faster later):
Step 1: Initialize: 0x01
Step 2: Command: 0x01-0x16
Step 3: Data:0x00-0xFF

It is possible to make it sample and send data continuously without further input (to get higher bandwidth), in which case it can be interrupted by sending 0x01 at it.

The code is public domain, just don't forget to give credit if you use it.
Attachments
raspiIO2.zip
(2.21 KiB) Downloaded 179 times
Posts: 5
Joined: Wed May 23, 2012 5:20 pm
by Stateside » Mon May 28, 2012 3:21 am
The Scribbler Robot- a tool for teaching programming

Can The Raspberrypi replace the IPRE Fluke Add-On Board ?

http://find.botmag.com/508125
http://www.parallax.com/go/S2
http://www.betterbots.com/
http://wiki.roboteducation.org/Main_Page
PyCon 2011: Python and Robots: Teaching Programming in High School
http://blip.tv/pycon-us-videos-2009-201 ... ol-4898767
Posts: 67
Joined: Sun May 13, 2012 12:26 pm
by coliscip » Tue Jun 19, 2012 11:42 am
Hi!

"Built a circuit to convert the 3v3 serial to TTL serial, provide some isolation, and clean up spurious signals (really just a pull-up transistor, diode protection, and a scmitt trigger hex inverter). It's a trivial circuit but I'll provide it if someone wants it."
Can you post the schematics? I need them and I think there are many people in my case.

Thank you in advance!

Ciprian
Posts: 9
Joined: Wed May 30, 2012 10:14 am
by legionlabs » Sun Jul 01, 2012 5:09 am
Sorry for the late reply. Suddenly I live in Vietnam. I found a cat5 cable being used as a clothesline, the other end seems plugged in to something that works. So, a description will have to do until I can find something to write with and a camera for pencil-and-paper-CAD.

Anyway, just make a standard transistor NOT gate with an N2222 NPN transistor. Power it with regulated 5 volts.

Now, either use another NOT gate in series, or (preferable) use a schmitt-trigger hex inverter (once again powered by 5 volts) to invert the signal again.

The hysteresis of the schmitt trigger will add some noise immunity. The 3.3 volt serial out will be sufficient to trigger everything and give you 5 volt serial. To convert this to RS232, just use any max232 chip with the reference design in the datasheet.
Posts: 5
Joined: Wed May 23, 2012 5:20 pm
by legionlabs » Sun Jul 01, 2012 7:06 am
Hex inverter I used: CD4069UBE

For the non-hardware-inclined, here's what a transistor NOT gate looks like:

http://www.transtutors.com/university/i ... 20Gate.JPG
Posts: 5
Joined: Wed May 23, 2012 5:20 pm
by TIR » Sun Oct 14, 2012 7:46 pm
Hi

I have a problem pairing the Raspberry Pi and a bluetooth module (link).

The setup:
I have the module connected to Arduino Uno. Every 30 seconds it sends the time as a string. On the raspberry i have a standard USB BT dongle.

I have bluetooth service running. When i write hcitool scan i get the address and the name of the bluetooth module, but when I write hcitool cc [address] nothing happens i just get a new line. The led of the module is still blinking witch means it is not paired.

PS. the linvor has a passkey by default (1234) where should i enter it.
Posts: 3
Joined: Sun Oct 14, 2012 7:31 pm
by smith11 » Mon Jul 29, 2013 9:04 am
i create a webcam with the raspbery pi and myassignmenthelp.net help me with my project....
http://www.myassignmenthelp.net/ :) :)
Posts: 1
Joined: Mon Jul 29, 2013 8:51 am
by cswanson » Tue Oct 15, 2013 10:49 pm
Yes, I am interested in that very same thing. I want to be able to write python code on my PC, then download the code via bluetooth to the Raspberry Pi. Then the Pi executes the code.

I currently have a bluetooth connection working between my PC and the Pi. Any ideas on what is my next step?


Stateside wrote:The Scribbler Robot- a tool for teaching programming

Can The Raspberrypi replace the IPRE Fluke Add-On Board ?

http://find.botmag.com/508125
http://www.parallax.com/go/S2
http://www.betterbots.com/
http://wiki.roboteducation.org/Main_Page
PyCon 2011: Python and Robots: Teaching Programming in High School
http://blip.tv/pycon-us-videos-2009-201 ... ol-4898767
Posts: 5
Joined: Wed Sep 25, 2013 5:40 pm