Raspberry pi projects


edsard boelen, 14 july 2012


The raspberry pi is a low cost development board with specs that blows the competetion away. For example the arduino which I used for a lot of other projects is about the same price but is a factor 10 slower, has 10 times less memory, no operating system etc.
I finally got one after months of waiting. I have a couple of ideas:
1: alarm clock / radio / bedroom tv
2: mame emulator game console
3: rowing interface





the hardware interfaces


The raspberry pi has among many other connectors, a gpio header, see the image below for the pinout.

As you can see, the layout is a bit borked, so I will try to use the I2C interface. (GPIO 0 and GPIO 1) I will use the PCF8574 I2C to 8 bit expanders to connect other stuff to the raspberry pi.

the I2C interface


The pins 3 and 5 on the connector are the I2C pins. The pins 2 and 6 are the power pins. You can power the raspberry pi from there instead of via the micro USB.
I Made a small test board as shown on the image below.

Note:
The schematics have been made using kicad


To use the i2c devices in linux, you need to have the i2c-dev module compiled and loaded into your kernel.
that can be done with modprobe or load it on boot by adding it to the /etc/modules.conf.
Install i2c-tools with apt-get install i2c-tools

The command i2cdetect should now detect a device on address 0x20 as the pins a0,a1 and a2 are connected to gnd.
If that works, control some leds with i2cset.
- i2cset -y 0 0x20 0x00
- i2cset -y 0 0x20 0x40
etc.

buttons

The top 4 connections will be used for some buttons, I will use 2 normal push buttons, and one rotary pulse switch. One side of the switches are connected to the ground. The pins on the IC are all pulled up with 10K resistors.

LCD


Driving an lcd screen is a bit trickier. I will add another PCF8574 but put a0 to +5v with a 10k resistor so it will be addressed at 0x21.
Most LCD screens are HD44780 compatible, I have a couple of them. Some python libraries are already available. So I will use python for this, but it still needed some tweaking to make it work in my setup.





I have connected the lcd in 4 bit mode as follows to the PCF8574:
P0 - D4
P1 - D5
P2 - D6
P3 - D7
P4 - RS
P5 - R/W
P6 - E

the python code can be found pylcd2.py and testlcd.py


7 segment digits


Although more primitive, it takes a lot more soldering to build the 7 segment drivers.
The driver IC CD4511 will be used. The first 4 bits of the PCF8574 will be used as bcd input. The higher 4 bits will be used to select the digit.





The code that drives them. can be found at pydigit.py and a test app which shows the time is: pytime.py

casing

The casing looks as follows:

and opened up:


play music

To let the raspberry pi play music, only a speaker needs to be added. The rest is all in software.
First the sound module needs to be loaded into the kernel. As it is still in beta.
modprobe snd-bcm2835
apt-get install alsa-utls mpg123
a better alternative is mplayer, it can handle all sorts of audio formats and streams.
add the module in /etc/modules.conf
set volume with amixer and store it with alsactl

When I connected a small speaker to the raspberrypi, I noticed that the power output was very low. So made a small power amplifier of two transistors I had lying around.

start on bootup

To have the clock, the lcd and the music to run automatically after boot,
just add some scripts to /etc/rc.local.