PiTraffic review
By Russell Barnes. Posted
Program a robot arm, with Raspberry Pi and Python code
Setting up LED lights is a common starter project, so much so that we frequently feature it in our beginner’s guides. Just set up an LED and use a bit of code to turn a light on and off.
It’s common for educators to turn to traffic lights as inspiration for a quick follow-on project: LEDs are readily available in red, yellow (amber) and green. Students can see the relationship between the code they create and physical objects being controlled in the real world.
This article was written by Lucy Hattersley and appears in The MagPi #65.
Setting up traffic lights is a hassle, though. You need at least three LEDs for each light, plus a button if you’re creating a pelican crossing. Setting up more than one set of lights quickly becomes a tangled bird’s nest of wires, resistors, buttons, and LEDs.
The PiTraffic HAT solves this by placing four traffic light sticks on top of the board. It also features a button to one side, and a piezo buzzer in the middle of the traffic lights (so your pelican crossing can beep, just like in the real world).
Setup is simple. Just plug the four traffic light sticks into the four sets of pins on top, and connect the PiTraffic HAT to the GPIO pins on any Raspberry Pi that has a 40-pin header. Then you should download test code from GitHub, which can be done with: git clone https://github.com/sbcshop/PiTraffic
After importing the PiTraffic code, you create instances of Traffic objects for each light, such as SouthRed = Traffic("SOUTH", "RED"). Once created, these are controlled using on() and off() methods, such as SouthRed.on() and SouthRed.off().
The only thing missing for us was Scratch support, which SB Components inform us is coming soon. The inclusion of Scratch will make this a compelling starter project for students. In the meantime we enjoyed using the Python API to code our lights.
Last word
4/5
A great starter HAT that takes much of the tangle out of a classic project. Students can test out traffic light code and see their results running in a miniature recreation.
Russell runs Raspberry Pi Press, which includes The MagPi, Hello World, HackSpace magazine, and book projects. He’s a massive sci-fi bore.
Subscribe to Raspberry Pi Official Magazine
Save up to 37% off the cover price and get a FREE Raspberry Pi Pico 2 W with a subscription to Raspberry Pi Official Magazine.
More articles
Programming station
Spot the microcontroller: we can see an Arduino Uno, Arduino Nano, a pair of ESP32 boards, and a Raspberry Pi Pico, all waiting to be played with.
Read more →
Solder fume extractor
This device has adjustable fan speeds and light levels, courtesy of Raspberry Pi Pico.
Read more →
Program a robot arm in Raspberry Pi Official Magazine 162
Worried about hackers stealing your zeroes and ones? How about transmitting data over an air-gapped pair of Raspberry Pi computers, so that information can go one way but not the other? The maker of this system is calling it a data diode, and you can ead all about it in this issue. If you’ve a […]
Read more →