PiTraffic review
By Russell Barnes. Posted
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
Make a Smart Home in Raspberry Pi Official Magazine issue 167
The dream of smart, connected devices controlling your home automatically, is especialy appealing on a lazy day when we’re trying to get work done in a heatwave. Maybe this will be the year we finally integrate temperature sensors with fans and a drinks dispenser to keep us cool, or maybe not, but we do know […]
Read more →
Win 1 of 3 Pironman 5 Pro Max cases!
Transform your Raspberry Pi with this amazing case
Read more →
Learning to code in an AI age
A new Raspberry Pi Foundation course helps young people learn to code.
Read more →