Raspberry Pi Big Trak vehicle

Raspberry Pi BigTrak

BigTrak converted to use a Raspberry Pi and L298 motor driver.

I’ve had an original Big Trak since the late 1980’s when I bought one to connect to my Jupiter Ace. Time passed and it eventually gained a PICAXE and then more recently it gained a Raspberry Pi.

The Big Trak electronics are fairly simple to work with, although I have a feeling that the original motors are only rated at 3v rather than 6v or anything higher. I tried a 7.2v battery pack and it went off rather too fast. It’s now running a 4.8v “SubC” NiCd rechargeable racing pack.

The motors are controlled by an L298 H-bridge motor which I’ve covered previously. The actual remote control is handled here from a wireless keyboard – the receiver is in the USB slot. I eventually want to make it more autonomous with an ultrasonic sensor fitted on the servo at the front.

From a software point-of-view, it’s all fairly simple. The main program is written in Scratch and uses ScratchGPIO to control the outputs. It looks for keypresses (up, down, left, right) and turns on the relevant outputs. The “b” key makes a piezo buzzer beep (useful for warning pedestrians who don’t look at their feet!) and also requires space bar to bring it to a halt.

I had originally intended to use my “Flirc” device to control this from a TV handset, but it seems to have died just prior to exhibiting. It partially works but I can’t fully program the keys. A shame, as it also did double duty as a remote for my Raspberry Pi Kodi media centre.

The following video was taken by an attendee at the Raspberry Jam in Exeter – I’m not driving either!


Raspberry Pi Arcade Machine

Overall view of the Arcade Machine.

Overall view of the Arcade Machine.

Something I’ve been wanting to do for a while… and something that seemed to interest the students – A Raspberry Pi Arcade Machine!

It’s pretty straightforward but the end result could prove to be rather good. We needed the following:

  • Case – some Melamine-faced chipboard left over from a lab refit
  • Push-to-make switches – the more the merrier
  • Some switch bezels – cut on the CNC router
  • An audio amplifier (built from a kit) with two 8Ω loudspeakers
  • Speaker bezels – converted from the Raspberry Pi logo and cut on the router
  • Raspberry Pi, second-hand LCD monitor, HDMI-VGA adapter.
  • Software: Stella Atari Emulator, Scratch, Python and PyGame.
  • Python and uinput to handle switches and turn them into keypresses.

Continue reading

i2c LCD and Digital Temperature Sensor

DS18B20 temperature sensor on breadboard

DS18B20 digital temperature sensor – only three wires and a resistor needed!

These DS18B20 devices are pretty nifty. I remember all of the hassle connecting an LM35 to a computer, sorting out the changes in current into something a BBC analogue port can handle, calibrating and scaling. And now… One little device, a 4k7 resistor and a few lines of code.

Here I’ve combined the sensor and the i2c display together to give me the Pi temperature and the room temperature. It’s been quite mild this autumn even without the central heating on!

There are a number of tutorials on the internet (such as this one)showing how these devices are used. I’m more familiar with using them with a PICAXE but they’re just as simple with the Raspberry Pi. It’s important to note that each of the sensors has their own address, so make sure you check carefully.

The code is straightforward:

import os
import commands
import time
import pylcdlib
import datetime

lcd = pylcdlib.lcd(0x27,0)
lcd.lcd_puts("                 ",1) #display on line 1
lcd.lcd_puts("                 ",2) #display on line 2

def get_cpu_temp():
	tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
	cpu_temp = tempFile.read()
	return float(cpu_temp)/1000

while True:
	tfile = open("/sys/bus/w1/devices/28-0000011628bf/w1_slave")
	text = tfile.read()
	secondline = text.split("\n")[1]
	temperaturedata = secondline.split(" ")[9]
	floattemperature = (float(secondline[29: ])/1000)
	lcd.lcd_puts("Temp: "+str(floattemperature),2) #display on line 2

	lcd.lcd_puts("CPU :"+str(get_cpu_temp())+"       ",1) #display on line 1

The LCD is really hard to photograph. I’ve tried a whole number of settings on the point’n’squirt camera at home, as well as my phone, but neither really shows up how well these LCDs show text.

Having used the LCDs with the PICAXE, I’m sure it’s possible to access the degrees symbol! Another challenge is using i2c with Python3. It seems that the libraries are unavailable, although trawling the ‘net has shown some leads that I’ll follow up.

Display showing the temperature.

LCD showing processor temperature and the temperature returned by the DS18B20.

Where next? My earliest experiments involved using the sensor with a PICAXE, which then sent the data to the Raspberry Pi as a serial data stream. These results were then uploaded to COSM (now known as Xively, having had a brief spell as Pachube). It was interesting to watch COSM plot the graphs over a period of time. It wouldn’t take much imagination to see how this could easily become an environmental monitoring and control platform – and many have succeeded!

Fischertechnik, Scratch and Motor Control through the GPIO.

Fischertechnik robot arm connected to two L298 driver boards and controlled through Scratch.

Fischertechnik robot arm connected to two L298 driver boards and controlled through Scratch.

My greatest interest in the Raspberry Pi lies in those 26 little pins tucked down on the side of the board. They just invite things to be connected to them. Having found a pile of dusty Fischertechnik (loosely assembled in a sort-of robot arm shape) in a cupboard, I decided that something could be done with it.
The arm was so dusty it needed disassembling and washing. I left the motors and sensors out of the wash but I figured that everything else would cope. Sure enough, it looked like new again.

I found some L298 motor driver boards on Ebay and these easily connect to the Raspberry Pi GPIO connections. There are four motors in this arm:

  • Rotation of the base
  • Lifting of the “forearm”
  • Lifting the “upper arm”
  • Closing the jaws

Continue reading

Raspberry Pi with a Glockenspiel

Raspberry Pi and Glockenspiel

This glockenspiel has been converted to play automatically.

I found a glockenspiel in the local recycling centre and decided to have a go at automating it after seeing details on the Raspberry Pi forum and also on the PICAXE website.

It’s quite a straightforward design, using motors to rotate the hammers downwards and then using a rubber band to lift the hammer upwards one the chime has been struck.

Programming this in Python is relatively straightforward – just allocate most of the GPIO outputs to controlling the motors and then trigger them sequentially. The motors are connected to the GPIO outputs using a pair of ULN2803 darlington driver IC’s. It’s quick but as we’ll see, not the best solution.

I haven’t yet found out how to make the software do a clean exit when CTRL-C is pressed – something to do with creating an exception and then using this to shut down the GPIO outputs. Without this, it’s possible to exit while the motors are energised meaning that the peak stall current is passed through the darlington drivers. I’ve had to replace a couple already.

When I design a PCB for this, I think I’ll use a bunch of discrete darlington transistors (BCX38C) along with a current limiting device.

Overall, the sound is pleasant to listen to. I’d like to refine the software and also include the possibility of using RTTTL ringtones. I’ll probably need to filter out sharps/flats and add some kind of a transpose function. Probably a challenge for later!

GPIO and a PIR


Raspberry Pi connected to a PIR and an LED.

I’ve finally got around to connecting a Passive Infra-Red Sensor (PIR) through the GPIO port of the Raspberry Pi. It’s been a long time coming and I wasn’t sure if the output of my PIR would be limited to 3.3 volts, or alternatively would run from 3.3 volts. In the end, I got out the multimeter and then I decided to try it.

This kind of thing is pretty easy with the PICAXE, which is where I spend a lot of my time. I’m a little more concerned about connecting up to GPIO as it’s a more expensive device all together. The PICAXE has quite robust inputs and outputs (sorry to say – I have tested this, and so have my students).

Ultimately, the PIR connects between the 5v terminal, Gnd and any available GPIO input. I’ve used pin 7. I’ve also connected an LED (through 330 ohms) so that I’ve got something to flash. I’d recommend this to anyone – testing GPIO outputs is much easier with an LED connected somewhere – we all need reassurance, right?

Circuit diagram showing the PIR connected to the GPIO

Raspberry Pi connected to a PIR and an LED – circuit diagram

From here, the Python program required was simple. Turn off the LED, check if the PIR has been triggered and flash an LED if it has. Then go back to the beginning…

The next step was to link to espeak using os.system. It works well as an intruder alert system!

What’s really amazing is the sensitivity that these little PIRs can manage. They can detect movement from a great distance and all for a few quid from “a well known auction site”. The current consumption is tiny so it doesn’t load your power supply down. Another advantage of this particular PIR is that the sensitivity and “on-time” are adjustable with two on-board preset resistors. I reckon they’re an absolute bargain.