A Digital Logic Shield for the Raspberry Pi Pico

In both quarters of Experimental Physics, we work with digital signals.  The first major experiment uses discrete chips and then an FPGA board to study AND, OR, and XOR operations.  The inputs are controlled by switches and the output is displayed by LEDs.  The second major experiment uses two digital outputs from a DAQ card to control a stepper motor.  The FPGA board and the DAQ card work well for these experiments but because they are capable of so much more, they are expensive and include a lot of overhead in the programming.  For example, the FPGA board shown in the picture at the right includes thousands of gates and more inputs and outputs than we can even use in a whole quarter of labs.  The programming suite for it takes well over 1 GB on the hard drive of the host machine.

With the rise of the Raspberry Pi ecosystem, we have another option.  The Pico costs about $5 and can be programmed with Thonny which only uses about 40 MB on the host machine.  The Pico has a limited number of digital outputs and inputs but they are more than adequate for lab use.  The only problem is that the Pico does not have any switches and only one LED on it.  This project produces a board that has four switches and four LEDs connected for easy student use.

Board Design

In the picture below, the schematic (left) and board file (right) are shown.  The LEDs are 5mm and can be any color.  The resistors are 100 ohm.  The switches are 5mm sliders.  Connections to the LEDs and switches within Python are:   

  • led1 = Pin(2, Pin.OUT)
  • led2 = Pin(6, Pin.OUT)
  • led3 = Pin(10, Pin.OUT)
  • led4 = Pin(14, Pin.OUT)
  • switch1 = Pin(28, Pin.IN, Pin.PULL_DOWN)
  • switch2 = Pin(26, Pin.IN, Pin.PULL_DOWN)
  • switch3 = Pin(20, Pin.IN, Pin.PULL_DOWN)
  • switch4 = Pin(16, Pin.IN, Pin.PULL_DOWN)

The board file can be downloaded by clicking here.

Completed Project

The completed board is shown below with the Pico installed on the left one and the bare shield at the right.  Headers were used so the Pico can be removed easily but they are not required.  Further refinements could be to add a couple of digital lines to the shield.  The complete python code (run from Thonny) to turn LED 1 off and on based on switch input from #1 or #4 is

  • from machine import Pin
  • import time
  •  
  • led1 = Pin(2, Pin.OUT)
  • switch1 = Pin(28, Pin.IN, Pin.PULL_DOWN)
  • switch4 = Pin(16, Pin.IN, Pin.PULL_DOWN)
  •  
  • while True:
    • if switch1.value() | switch4.value():
      • led1.value(1)
    • else:
      • led1.value(0)