Three Fun Things to Try with your Raspberry Pi – Off The Shelf!

Posted: April 8, 2013 in Other Products, Raspberry Pi

There is a lot of great kit available for the Raspberry Pi to experiment and learn from, and they don’t have to cost a lot of money.  Here are 3 great examples!

Adafruit’s 8×8 LED Matrix Backpack:

Adafruit's 8x8 Bi-Colour LED Backpack

Adafruit’s 8×8 Bi-Colour LED Backpack

Cost:

$15.99 (USD) – Bi-Colour http://adafruit.com/products/902

$9.95 (USD) – Single Colour i.e. http://www.adafruit.com/products/872

Details:

This little I2C module neatly connects to the Raspberry Pi with 4 pins (3V3, Gnd, I2C Data and Clock), and potentially can be connected in multiples.

Create a range of designs and animations with the LEDs

Create a range of designs and animations

For a bit of fun it is excellent, particularly for creative kids (or 8bit junkies from BBC/Z80 Spectrum days) to design tiny cute icons.

Scratch the Cat seems to end up everywhere!

Scratch the Cat seems to end up everywhere!

Keep an eye out for my follow up to this, as I’ve been experimenting with it with great results.

Wiring:
I2C Uses 4 Wires (VCC, GND, SDA, SCL)

I2C Uses 4 Wires (VCC, GND, SDA, SCL)

The kit comes in three parts, the pin header (I’ve used my own to add a socket on top), the PCB and the 8×8 module, which are easy to solder together.

For I2C, the following pins are used.

3V3 (VCC) – P1 Pin1

Gnd (GND) – P1 Pin6

I2C Data (SDA) – P1 Pin3

I2C Clock (SCL) – P1 Pin5

3V3 (VCC) - P1 Pin1 - Red, Gnd (GND) - P1 Pin6 - Yellow, I2C Data (SDA) - P1 Pin3 - Green, I2C Clock (SCL) - P1 Pin5 - Blue

3V3 (VCC) – P1 Pin1 – Red, Gnd (GND) – P1 Pin6 – Yellow, I2C Data (SDA) – P1 Pin3 – Green, I2C Clock (SCL) – P1 Pin5 – Blue

Software:

The Adafruit tutorial contains links and details of the python libraries used for controlling the backpack.  With several useful commands to set individual pixels, or Rows in various colours.

Note: The Bi-Colour module allows for 3 different colours, using Red and Green combined to make Yellow.

Inspired by:

http://learn.adafruit.com/matrix-7-segment-led-backpack-with-the-raspberry-pi

Playing with Servos:

Cost:

$5.95 (USD) from Adafruit – http://www.adafruit.com/products/169

R2D2 with a servo controlled head!

R2D2 with a servo controlled head!

I came across Adafruit’s guide on using the PWM pin of the Raspberry Pi to control a servo and saw it was relatively easy to do.  So I ordered a ultra-cheap Servo (from Hong-Kong) and waited a few weeks for it to arrive (I had other projects to play with, so I didn’t mind waiting).

When the servo arrived and I immediately hooked it up.  You’ll note that the guides below recommend using a separate power supply for the Servo, and I do too (I have used it directly from the RPi 5V supply, but you can expect a reset if you connect it while it is running, and don’t be surprised if it causes lock-ups and resets when it needs to move, depending on your power supply).

I’ll spare you all the fine details of how to wire it up and the software side, since the two guides below cover it extremely well indeed.

Also, if you are serious about using Servos (and why not, since you can make many types of robots and creations using servos) then Adafruit also have a 16 channel module ($14.95 (USD) http://www.adafruit.com/products/815) which was featured in Issue 6 of the MagPi in the PiGauge article (see article on Issuu).

Wiring:

1. Connect the Gnd (usually black or brown) of the servo to your GND/negative terminal of the power supply (4xAA batteries or similar) and also to the GND pin of the Raspberry Pi (Pin 6 of P1)

2. Connect the +V (usually red wire) of the servo to your power supply positive terminal.

3. Connect the Servo signal wire (usually white, yellow or orange) of the servo to GPIO#18 (Pin12 of P1)

Software:

1. Use a spare SD-card (or backup your current one) and install Occientalis 0.2.

Note:  You can install the kernel on your current set-up, but I didn’t find it easy to undo, and Occientalis 0.2 lacks a lot of the tweaks from the recent Raspbian images which makes the Raspberry stable and faster (so I would recommend only using it for experimenting with).  No doubt, the Raspbian build will be updated to include the PWM support later on (or even software PWMs) and Occientalis may get updated.

2. See the guides for example Python code, which writes to the PWM pin and controls the position of the Servo.

Note: You may wish to remove anything connected to the analogue audio, since there is a certain amount of interference generated.

As you can see, I placed my servo into my Little R2D2 (my desk tidy for spare resistors and wires) with the help of some tape.  He can sit on my desk shaking his head at me all day long.

Installing a servo inside R2D2

Installing a servo inside R2D2

Inspired by:

http://learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor

http://raspi.tv/2013/how-to-make-your-own-raspberry-pi-flag-waving-demo

ADC and DAC:

Introducing the PCF8591P – catchy name isn’t it!

The 16-Pin PCF8591P 8-Bit 4Ch ADC and DAC chip

The 16-Pin PCF8591P 8-Bit 4 Channel ADC and DAC chip

Cost:

~£4 (GBP) for Chip from RS/Farnell

$4.50 (USD) for full module – http://dx.com/p/pcf8591-8-bit-a-d-d-a-converter-module-150190

Now this little chip is rather useful since not only does it provide us with some well needed analogue inputs (4 channel 8-Bit ADC (Analogue-to-Digital-Converter) – provides input values 0 to 255), but also throws in an analogue output too (8-Bit DAC (Digital-to-Analogue-Converter)).

I was looking into this chip in order to create a new kit, so I was testing it out using one of my breadboards.

My PCF8591P test board (sorry too much of a mess to copy)

My PCF8591P test board (sorry too much of a mess to copy)

However, following some investigations I came across this useful blog by John Newbigin:

http://blog.chrysocome.net/2012/12/i2c-analog-to-digital-converter.html

He does an excellent job at providing some simple commands to quickly test out the operation of the chip (what I was looking for), but he also points you in the direction of another of my favourite sites, Deal Extreme.  I’ve often brought kit from Deal Extreme so it was great to see they stock the following item:

http://dx.com/p/pcf8591-8-bit-a-d-d-a-converter-module-150190

PCF8591 8-Bit A/D D/A Converter Module (image from DX.com)

Not only does the module include the surface mount version of the chip I was testing with, but it also includes a light sensor, temperature sensor and a variable resistor (so you have inputs right there to test with immediately or they can even be used in your project).  I shall confirm when I get mine, if they are connected to the jumpers to select between them and the input pins (I expect this is the case).

All for $4.50 delivered – Hence why there isn’t much point me attempting to create a kit!

The good news is that this module can easily add analogue inputs and outputs to your Raspberry Pi and being I2C based, it is easy to control and multiple modules can be put on the same I2C bus.

Wiring:
PCF8591 Pinoput (taken from NXP datasheet - click to see)

PCF8591 Pinoput (taken from NXP datasheet – click to see)

Again, for I2C the following pins are used.

3V3 (VCC) – P1 Pin1

Gnd (GND) – P1 Pin6

I2C Data (SDA) – P1 Pin3

I2C Clock (SCL) – P1 Pin5

Since my first test was using the bare chip, it wasn’t too pretty but it worked!

Software:

As I was simply testing out the chip, I only made use of the i2cget() and i2cset() commands to make up a quick script to poll and read the channels.

adc_pcf8591p.sh:

#!/bin/sh
echo "PCF8591P ADC and DAC Test Program"
echo "================================="
echo "Simple test program to demo the PCF8591P"
echo "Connected to I2C bus"

i2c_chan = 1
i2c_adc = 0x48
adc_channel = 0

i2cset -y $i2c_chan $i2c_adc $adc_channel
while true:
  do
  i2cget -y $i2c_chan $i2c_adc
  sleep 0.5
  done
#End

For my testing I connected up a variable resistor to act as a potential divider, and later on some IR proximity sensors and they all seemed to work nicely.

I manually tested the analogue output using similar commands separately, using a multimeter to monitor the output (i2cset -y 1 0x48 0x41 0x88) – where 0x88 is the output value 0x00 (LOW) to 0xFF (HIGH).

Again, watch out for an update when I get the DX module (and the thing I have planned to connect to it).

Enjoy!

Advertisements
Comments
  1. […] Via Meltwater with a nice review of the bicolor LED square pixel matrix – […]

  2. AndrewS says:

    The PCF8591 is also used by the Quick2Wire analogue board http://store.quick2wire.com/i2c-pcf8591-analogue-board.html but that’s much more expensive than the DealExtreme module you found 😉

  3. did you get the dx module? hint I have one, and itching to understand how to use….

    • Yes I did. Only started using it properly in the last few weeks, was using wiringpi2 since that is Python3 friendly. The principle is the same as using i2c tools, but using i2c.read and i2c.write. Will post an update when I get time.

  4. […] Such as Three Fun Things to Try with your Raspberry Pi – Off The Shelf! […]

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