I am going to be at the Bay Area Maker Faire on Saturday and Sunday (19th and 20th of May 2012). I will be on the McGraw Hill stand (most of the time) so please come and say hello.
I am giving a talk and demonstration of Arduino on Saturday at 7:30 in the Makershed.
MGH Marketing made it worryingly easy to make me look mad!
You take the life of your Raspberry Pi in your hands when you start messing with the GPIO pins. The safe approach is to use a proper buffered board that protects the Pi's system on a chip, or use an Arduino as described in a previous post of mine.
However, I just couldn't resist trying out the GPIO pins directly.
IF YOU DESTROY YOUR RASPBERRY PI DON'T BLAME ME. YOU HAVE BEEN WARNED!
So, what I have done is use the Slice of Pi and attach an LED and current limiting resistor to it. Then use the RPi.GPIO library to control the LED from the Raspberry Pi.
The 'Slice' is a very low cost entirely passive breakout board for the Pi's GPIO connector.
It is primarily intended to house X-bee format radio modules and I hope to try these out in a later post, but for now I was just using it as a convenient means of connecting to the GPIO pins.
If you prefer, you could just connect header sockets to the appropriate pins on the Pi board itself, but this avoids the risk of accidental shorting of pins.
My first step was to assemble the 'Slice', which comes as a kit that you have to solder together yourself. Its all nice big pads and easy to solder.
I also added a 3 pin header socket for the three power connections 5V, 3.3V and GND. IMHO it would be nice if the slice came with this. It does however come with a header kit in case your Pi does not have one ready soldered. My Pi came with one of these already soldered in, so I didn't need the one that came with the Slice.
The low profile header sockets are for radio modules. Definitely something to look forward to there!
The Pi's GPIO pins are 3.3V and low current. Low An LED will glow with just 1 or 2 mA flowing through it, which shouldn't do the Pi any harm. By using a 1kΩ resistor, if the LED forward voltage is 2V, and the supply voltage is 3.3V, that leaves 1.3V across the resistor, using Ohms Law, I = V / R so I = 1.3mA.
I just twisted one leg of the resistor around the negative lead of the LED. The negative lead is the shorter lead.
Put the positive lead of the LED into the 3.3V power socket on the slice and the free end of the resistor into the socket on the Slice labelled GP0.
You can now fit the slice onto your Pi.
Now its time to sort out the software side of things.
Step 1. If you are not reading this page on your Pi, then switch now, so you can copy and paste.
Step 2. Browse to here and download RPi.GPIO-0.1.0.tar.gz and save it somewhere convenient. I saved it to the 'other' folder on the Desktop.
Step 3. This is a gziped tar file. Which needs unzipping and untaring. To unzip it open a Terminal, which you will find from the 'start menu' under 'accessories'. Now paste the following commands into it. cd /home/pi/Desktop/other gunzip FPi.GPIO-0.1.0.tar.gz tar - xvf FPi.GPIO-0.1.0.tar
Step 4. Install GPIO, by typing these lines in your terminal window: cd FPi.GPIO-0.1.0 sudo python setup.py install
Step 5. Run Python 2. You will find this from the menu under Programming - Use Python 2 not 3.
We now need to enter some commands: >>> import RPi.GPIO as GPIO >>> GPIO.setup(11, GPIO.OUT)
After we enter this second command, the LED should light. That is because the pin will have been set to an output and initially be low. A low pin will light the LED, a high pin and it will turn off. >>> GPIO.output(11, True)
This should have turned the LED back off.
Let's now write a little program to make the LED blink.
>>> import time >>> while True : >>> GPIO.output(11, True) >>> time.sleep(1) >>> GPIO.output(11, False)
>>> time.sleep(1)
Press the enter key twice. When you have had enough of the LED blinking press the key combination ctrl-C.
Here is a short video of this.
You may have noticed that the LED is connected to pin GPIO0 and not 11 as we are using in Python. The library uses different pin numbers to the names on the Pi. I'm not sure why. But anyway, I mapped a few of them as shown below.
library name Pi name 11 0 12 1 13 2
After that, the mapping changes.
I wanted to know how fast the GPIO library was, so I took off the LED and attached my oscilloscope to the output and then ran the following test program.
>>> state = True >>> while True : GPIO.output(11, state) state = not state
The 'scope measured the frequency as 800Hz. Not very fast, but fast enough for PWM and servo control.
About the Author These are my books. Click on the image below to find out more about them.
We helped presenter Jason Bradbury develop a Frizmarang, a kind of cross between a well known brand of flying disk and a boomerang. Designed to be flown at night, it has a 3W RGB LED in a centre 3D-printed plastic insert. The module cycles through the colour spectrum. I lent a hand, designing the light insert, using an ATTiny and a 3W RGB LED, the power source is a scavenged battery from a dead RC helicopter.
The boomerang was designed in Google Sketchup and CNC milled from plywood. For the full unveil, you will have to wait for the Gadget Show in about a months time.
About the Author These are my books. Click on the image below to find out more about them.
The Raspberry Pi is creating quite a storm of interest. I have just got mine and one of the first things that I wanted to try was to get it talking to an Arduino over USB using Python.
.. and you know what? It proved to be a lot easier than I expected. This is mainly because, after all, despite its diminutive price tag, the Pi is just a Linux box. I got communication working both ways, with the Arduino sending 'Hello Pi' to the Pi and at the same time, testing for a digit coming in. When it receives a digit, it flashes the number of times indicated by the digit.
Arduino
Let's start with the Arduino end. I used an Arduino Uno and Arduino software version 1.0. I haven't tried an older board, but I suspect the FTDI generation Arduinos before the Uno may have trouble with USB.
Here is the sketch - paste it into a new Arduino IDE window and load it up onto your Arduino using your regular computer.
const int ledPin = 13; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { Serial.println("Hello Pi"); if (Serial.available()) { flash(Serial.read() - '0'); } delay(1000); } void flash(int n) { for (int i = 0; i < n; i++) { digitalWrite(ledPin, HIGH); delay(100); digitalWrite(ledPin, LOW); delay(100); } }
Raspberry Pi
There is a Python library for serial communications called 'pySerial' which has history with Arduino. So, I stood on the shoulders of giants and adapted the instructions found here.
Step 1. If you are not reading this page on your Pi, then switch now, so you can copy and paste.
Step 2. Browse to here and download pyserial-2.5.tar.gz (106.3 kB)and save it somewhere convenient. I saved it to the 'other' folder on the Desktop.
Step 3. This is a gziped tar file. Which needs unzipping and untaring. To unzip it open a Terminal, which you will find from the 'start menu' under 'accessories'. Now paste the following commands into it. cd /home/pi/Desktop/other gunzip pyserial-2.5.tar.gz tar - xvf pyserial-2.5.tar
Step 4. Install pySerial, by typing these lines in your terminal window: cd pyserial-2.5 sudo python setup.py install
Step 5. Run Python 2. You will find this from the menu under Programming - Use Python 2 not 3.
Thats it! Now we just need to write some Python to access the Serial port. So type the commands shown in the transcript below.
You type the parts after >>>
import serial ser = serial.Serial('/dev/ttyACM0', 9600)
Note that the second argument here (9600) is the baud rate and should match whatever you put in your Arduino sketch.
/dev/ttyACM0 is the name for the USB interface to the Uno, at least it was for my Uno. The way to discover the port name is to run the following command in the terminal without the Uno plugged in.
ls /dev/tty*
Then plug in your Arduio and run the command again. If there is a new name, then this is the name of your port.
Now lets start a loop listening for messages from the Arduino.
while 1 : ser.readline()
You will need two hit enter twice after you type the second line. Messages should now start to appear!
You can see in the Blue writing where the Arduino is talking to the Pi. Then some error trace as you press ctrl-C to interrupt the messages coming from the Arduino.
When you type
ser.write('5')
you should see the LED on the Arduino flash 5 times.
There are many possibilities here, we could put a motor shield or LCD shield onto the Arduino and control it from your Pi.
About the Author These are my books. Click on the image below to find out more about them.
I don't think I would recommend building it the way I describe here. There are a few unsatisfactory things about it. Mainly its difficult to tune - the pot tends to drift a little. Perhaps a vernier dial, or better a rotary encoder. It could also do with a pre-amplifier - the output from the TEA5767 just isn't that high. As a receiver, its also not that sensitive and needs a better antenna than the 2ft of solid core wire dangling out the back that I gave it. Although to be fair I live on the wrong side of a hill for good FM reception,
Anyway, because I don't like to see projects without any details given of how they work, here it is, help your selves and may it inspire you to do it better.
It uses the amp and speaker from a scavenged PC USB powered speaker (right hand side) the TEA5767 module and breakout, described in an earlier post, and a small ATTiny45 board, that has ICSP connector and a 7805 voltage regulator - from another project.
Tuning is accomplished by turning the pot read by an ADC on the ATTiny. This then maps to a frequency that is sent to the TEA5767 by I2C.
It uses the TinyWireM library to the I2C communications. Note you will need to change the header TinyWireM.h to 8MHz instead of 1. See the instructions on the link above.
I have been working on a Steampunk FM Radio receiver for a while now. It works and looks pretty good, but there are a few things I would like to improve.
Sorry the video is not very good quality. Key features are the illuminated knob, which is made from a copper plumbing fitting that has a hole in the top and is filled with hot-glue-gun glue. There is an LED underneath the knob that lights it up with the glue acting as a diffuser.
The sound does come out of the trumpet like copper thing. This came from an old copper jug that I cut with a rotary tool. This is glued into a hole in the lid, with the speaker mounted directly underneath it.
The box came from eBay and the coil of wire was made by wrapping very small bore copper pipe around a rolling pin.
I consider this a first prototype. Its actually very over engineered internally, and I would like to simplify it, probably by disassembling an off-the-shelf radio.
About the Author These are my books. Click on the image below to find out more about them.