In this tutorial we will be using the Raspberry Pi Pico, the PiStop module from PiMoroni and a simple button switch. This tutorial is very similar to the previous tutorial with the only difference being that the Red, Amber, Green LED’s are by default switched off and they light up in a sequence once the push button switch has been pressed.
PiStop by PiMoroni : The PiStop module from PiMoroni is a simple traffic light module consisting of three LED’S i.e. Green, Amber, Red along with resistors on board to allow you directly interface with any maker board. In our case we chose to use PiStop from PiMoroni along with the Raspberry Pi Pico. The PiStop includes resistors in line with each of the LED’s along with a separate Vcc (power) and GND (ground) line, thus making it really easy for anyone to get started with their traffic light project. The entire package makes it very easy to work with the LED’s and allows embedding the PiStop into various maker projects where a visual traffic light setup might be required.
You can purchase the PiStop from PiMoroni from the following link – PiStop at PiMoroni
Raspberry Pi Pico – Raspberry Pi Pico is a tiny, fast, and versatile board built using RP2040, the flagship microcontroller chip designed by Raspberry Pi in the UK. From light displays and IoT devices to signage and manufacturing processes, Raspberry Pi Pico gives the maker the power to control countless home, hobby, and industrial projects. Programmable in C and MicroPython, the Pi Pico is adaptable to a vast range of applications and skill levels, and getting started is as easy as dragging and dropping a file. More experienced users can take advantage of Raspberry Pi Pico’s rich peripheral set, including SPI, I2C, and eight Programmable I/O (PIO) state machines for custom peripheral support.
Here’s the specifications (from Raspberry Pi Foundation website) of the Raspberry Pi Pico in case you are interested –
- 21 mm × 51 mm form factor
- RP2040 microcontroller chip designed by Raspberry Pi in the UK
- Dual-core Arm Cortex-M0+ processor, flexible clock running up to 133 MHz
- 264kB on-chip SRAM
- 2MB on-board QSPI flash
- 2.4GHz 802.11n wireless LAN (Raspberry Pi Pico W and WH only)
- 26 multifunction GPIO pins, including 3 analogue inputs
- 2 × UART, 2 × SPI controllers, 2 × I2C controllers, 16 × PWM channels
- 1 × USB 1.1 controller and PHY, with host and device support
- 8 × Programmable I/O (PIO) state machines for custom peripheral support
- Supported input power 1.8–5.5V DC
- Operating temperature -20°C to +85°C (Raspberry Pi Pico and Pico H); -20°C to +70°C (Raspberry Pi Pico W and Pico WH)
- Castellated module allows soldering direct to carrier boards (Raspberry Pi Pico and Pico W only)
- Drag-and-drop programming using mass storage over USB
- Low-power sleep and dormant modes
- Accurate on-chip clock
- Temperature sensor
- Accelerated integer and floating-point libraries on-chip
Pinout diagram for the Raspberry Pi Pico – To help you work out which pins are located where and what they are called you can refer to the pinout diagram for the Raspberry Pi Pico provided below.
Circuit Diagram –
The above diagram was put together in Fritzing, not being able to access a PiStop module within Fritzing we have displayed the PiStop as three LED’s with attached resistors in line with each LED. The connections for the PiStop module are to be made as follows –
- Red LED connected to GPIO 18
- Amber LED connected to GPIO 17
- Green LED connected to GPIO 16
- One pin of the push button switch going to 3V3 OUT or Vcc rail
- The second pin of the push button switch going to GPIO 14
- Vcc connected to Vcc or 3V3 OUT
- GND (Ground) connected to GND
If you are using the PiStop PiMoroni module you do not have to use the resistors we’ve shown above. These PiStop module includes SMD resistors on the module. The switch has been setup to work with GPIO 14. Every time you hit the switch it should light up the LED’s. The LED’s should be turned off when the switch is not pressed.
Here’s the code for the tutorial that you’ll need to put together. You are encourage to not just copy the code, but rather ask yourself the meaning of each of the lines of code as you type them out and use Google where you need additional support.
from machine import Pin #importing relevant modules & classes import time # Setting up the different pins which we'll use to blink the onboard LED: led_green = Pin(16, Pin.OUT) led_amber = Pin(17, Pin.OUT) led_red = Pin(18, Pin.OUT) # Setting up the button switch as an Input pin button = Pin(14, Pin.IN, Pin.PULL_DOWN) while True: if button.value() == 1: # Blinking the Green LED led_green.on() time.sleep(.1) led_green.off() # Blinking the Amber LED led_amber.on() time.sleep(.1) led_amber.off() # Blinking the Red LED led_red.on() time.sleep(.1) led_red.off() # Sleeping for 3s time.sleep(1) else: # Turning all the LED's off led_green.off() led_red.off() led_amber.off()
Summary – We hope you’ve enjoyed this tutorial on the PiStop PiMoroni module and the Raspberry Pi Pico. In this module we learned how to setup the PiStop module, connect each of the pins on the PiStop module to the Raspberry Pi Pico, connect up a push button switch and program it in Micropython to get it all working. Please drop us a note at trevor at hack2 dot live if you have any questions.