PiTraffic review
By Russell Barnes. Posted

Advertisement
The desktop computer you've been waiting for: Raspberry Pi 500+
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

Win one of ten M.2 HAT+ Compact
The ability to connect NVME SSD drives to Raspberry Pi 5 is very cool, although it does slightly limit the cases you can use. With the M.2 HAT+ Compact, you can even fit an SSD-powered Raspberry Pi into the official case – and we have ten to give away below. Win one of ten M.2 […]
Read more →

Raspberry Pi 500+ in Raspberry Pi Official Magazine issue 158
We’re quite taken with Raspberry Pi 500+. But when you don’t need all that processing power, and just want a board that will make a plastic skeleton jump around in a terrifying manner, you’ll find Raspberry Pi Pico more than up to the job. There’s more terror in the magazine (which is only right as […]
Read more →

Win one of five Raspberry Pi SSD 1TB
Raspberry Pi prides itself on high quality hardware, and this 1TB Raspberry Pi SSD is no different. You can use it with a standard Raspberry Pi or even in your desktop PC – the choice is yours. We have five to give away and you can enter below Win 1 of 5 Raspberry Pi SSD […]
Read more →
Sign up to the newsletter
Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.