PiStop with Pi Pico and a Push Button Switch

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

PiStop by PiMoroni (Image : courtesy Pi Moroni)

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 –

  1. 21 mm × 51 mm form factor
  2. RP2040 microcontroller chip designed by Raspberry Pi in the UK
  3. Dual-core Arm Cortex-M0+ processor, flexible clock running up to 133 MHz
  4. 264kB on-chip SRAM
  5. 2MB on-board QSPI flash
  6. 2.4GHz 802.11n wireless LAN (Raspberry Pi Pico W and WH only)
  7. 26 multifunction GPIO pins, including 3 analogue inputs
  8. 2 × UART, 2 × SPI controllers, 2 × I2C controllers, 16 × PWM channels
  9. 1 × USB 1.1 controller and PHY, with host and device support
  10. 8 × Programmable I/O (PIO) state machines for custom peripheral support
  11. Supported input power 1.8–5.5V DC
  12. 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)
  13. Castellated module allows soldering direct to carrier boards (Raspberry Pi Pico and Pico W only)
  14. Drag-and-drop programming using mass storage over USB
  15. Low-power sleep and dormant modes
  16. Accurate on-chip clock
  17. Temperature sensor
  18. 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.

Raspberry Pi Pico Pinout Diagram

Circuit Diagram

Raspberry Pi Pico with PiStop (3 LED’s, SMD resistors)

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 –

  1. Red LED connected to GPIO 18
  2. Amber LED connected to GPIO 17
  3. Green LED connected to GPIO 16
  4. One pin of the push button switch going to 3V3 OUT or Vcc rail
  5. The second pin of the push button switch going to GPIO 14
  6. Vcc connected to Vcc or 3V3 OUT
  7. 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.

Code

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.

Leave a Reply

Your email address will not be published.