Skip to content

Exploring the Raspberry Pi Pico with 12 Projects from The Pi Hut

Notifications You must be signed in to change notification settings

olirooker/the-pi-hut-advent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Pi Hut Advent

Exploring the Raspberry Pi Pico with 12 Projects from The Pi Hut

This repo is for me to keep track of the projects I build with the components in the the Pi Hut Advent Calendar and to have as a reference for myself.

I'll be following some of the projects in the guide but coming up with more challenging projects that use the components each day.

Day 1 - Set up

The first day focuses on setting up and getting familiar with the Pico.

Pico Info:

Software set up with Thonny.

The instructions here didn't work for me as there is a known issue with Mac. There's a blog post from Raspberry Pi going into detail on this, but their suggested fixes didn't work for me. After some reading for potential fixes, I did the following, which ended up being closer to the actual Raspberry Pi docs:

  • connected Pico to Mac holding the BOOTSEL button on the Pico
  • A drive called RP1-RP2 appears in the sidebar in finder
  • Navigate to the Raspberry Pi Docs for MicroPython. Or go through the Pico by:
    • Open the RP1-RP2 drive
    • Open the index.htm file (takes you here)
    • Open the link to the Getting help with MicroPython
  • Go to section on Drag and Drop MicroPython
  • Download the correct MicroPython UF2 file for the Pico board
  • Drag and drop the UF2 file from downloads to the RP1-RP2 drive
  • The file copies over and the Pico reboots
  • Here you'll encounter the bug, a message is displayed saying Disk Not Ejected Properly - ignore it
  • Disconnect/reconnect the USB without holding the BOOTSEL button - the drive should not appear in the sidebar
  • Open a terminal and run this command ls -ls /dev/cu.*
  • Listed you should see something like /dev/cu.usb... - showing the Pico is connected
  • Open Thonny
  • In the bottom right hand corner click on Local Python 3 - Thonny Python
  • Select MicroPython (Raspberry Pi Pico) - you should see /dev/cu.usb... referenced after on the same line
  • That should be it, try writing some code to run on the Pico!

Following on from this I did check the day 1 instructions on the Pi Hut's website under 'Setting up Thonny' and did the following when the Pico was connected:

  • Open Thonny and navigate to Run > Configure Interpreter in the menu bar
  • Under Port, there's drop down which should have your Pico listed something like Board in FS Mode (/dev/cu.usb...)

Setting up with VS Code

  • Install MicroPico extension.
  • In project folder open the command pallet using sft cmd p.
  • Run MicroPico > Configure Project.

Day 2 - LEDs

Day 2 Circuit Diagram

  • 330 ohm resistors
  • LEDs have a specific polarity, electricity can only flow in one direction. The long leg is the Anode (+) and the short leg is the Cathode (-). Current must always flow from the anode to the cathode.
  • It doesn't matter which side of the LED the resistor sits, as long as it's there limiting the flow of current for the entire circuit

Projects


Day 3 - Buttons

Day 3 Circuit Diagram

Pull Downs

# Using pull downs
Pin.PULL_DOWN
# Pass as an argument in Pin() function
redButton = Pin(3, Pin.IN, Pin.PULL_DOWN)

A button sends 3.3V to the GPIO pin to set it to HIGH. It needs to be LOW first or the code might not be able to detect a change / trigger randomly. A GPIO pin without a pull down can be 'floating' between 0V and 3.3V. Pulling down the pin to 0V ensures it always starts on LOW.

Projects

  • LED Memory Game - Randomly generate a sequence of lights and using the buttons, enter the combination back to the Pico with three difficulty levels.

Day 4 - Analogue Inputs with a Potentiometer

  • Digital inputs are strictly 1 and 0 (HIGH/LOW, ON/OFF). Analogue inputs have a wide range of numbers to represent values.
  • The potentiometer can pass these analogue signals in the form of voltage to the Pico.
  • A potentiometer is a variable resistor.
  • The potentiometer here is a 10K potentiometer, it can be set anywhere from 0 ohms to 10,000 ohms (resistance is measured in ohms).

Circuit

Day 4 Circuit Diagram

  • The right pin needs to connect to the 3V3(OUT) pin (physical pin 36), the middle pin to GPIO 27 (physical pin 32) and the left pin to GND (use the blue lane as we already have that connected to GND for the LEDs).

ADC Pins (Analogue to Digital Converter)

  • An ADC is an Analogue to Digital Converter. The ADC pins on our Pico have the special ability of being able to convert an analogue input into a digital form we can use. We have to import ADC in our code to use this feature.
  • from machine import ADC to use.
  • GPIO26, 27 and 28 (physical pins 31,32 and 34) - a map of Pico pins here.
  • The Pico's ADC pins are 12-bit, however MicroPython scales this to a 16-bit range which is 0-65535.
  • Invoke .read_u16() to scale to 16-bit.

PWM (Pulse Width Modulation)

  • A type of digital signal where we, over a set period of time, decide how long the signal is ON (HIGH) and how long it's OFF (LOW).
  • This can create a fading effect for LEDs but also is used for things like servos.
  • Our code needs some values from us to enable it to run PWM for us - Duty Cycle and Frequency.
  • The duty cycle is the percentage of the time that our LED will be ON. The higher the duty cycle, the longer the LED will be ON, and the brighter our LED will appear.
  • Duty cycle for the Pico in MicroPython can range from 0 to 65535, which matches the output of the potentiometer (0-65535) so we can use this value directly without having to manipulate it.
  • Frequency is the number of times per second that we will repeat the ON/OFF cycle.

Projects

  • Testing effects using PWN programmatically rather than with the potentiometer.
  • Pulse LEDs
  • Fade LEDs

Day 5 - Sound

Circuit

Red into pin 17, black into the GND pin at 18.

PWM Frequency and Duty Cycle with Buzzers

  • Frequency changes the tone (between 10 and 10000)
  • Duty Cycle changes the volume. The range is 0 to 65535. 10000 seems good. 0 is mute.

Projects

Day 6 - Analogue readings from a light sensor

In the box

  • 1x Photo Transistor
  • 1x 10k Resistor
  • 3x Male to male jumper wires

Circuit

Day 6 Circuit Diagram

Now we need to add three wires and the resistor:

  • Connect the right (short) leg to the 3.3V pin (physical pin 36)
  • Connect the left (long) leg to GPIO 26 (physical pin 31)
  • Add the resistor to connect the left leg over to another empty unused lane on your breadboard
  • Connect the other end of the resistor to a GND pin on your Pico (we're using the blue lane as it's already connected to GND for our LEDs)

Day 7 - Monitoring Motion

In the box

  • 1x Mini PIR (Passive Infra-Red) Sensor - detects movement via heat.
  • 3x Male to male jumper wires

Circuit

Keep the same from day 5 with the below on the breakout board.

Day 7 Circuit Diagram


Day 7 PIR Orientation

Day 8 - Temperature

In the box

  • 1x Custom waterproof temperature sensor with male jumper wires
  • 1x 4.7k resistor

The metal tip houses the sensor inside (specifically a DS18B20-compatible 1-wire sensor). 1-wire is a serial communication protocol for devices to communicate to a controller. 1-wire allows a special device like our temperature sensor to talk to a controller, like our Pico, enabling it to send data to the Pico to be used in a program.

Despite it's name, you actually need at least two wires to use 1-wire devices, and in some examples (like our sensor) we're using three wires. The name is related to the data communication - you only need one wire to allow the devices to talk to each other both ways.

Circuit

Same as day 5 with the below on the breakout board.

Day 8 Circuit Diagram

1-wire Code

Specify we're using the DS18B20 sensor using:

sensor = ds18x20.DS18X20(onewire.OneWire(SensorPin))

We also need to scan for 1-wire devices on the GPIO pin we have set up. 1-wire devices such as our sensor have a unique registration number in their read-only memory (rom). The following line in our code below scans for sensors (roms) connected to our pin:

roms = sensor.scan()

Day 9 - Tilt Switches

In the box

  • 1x Tilt sensor/switch - HIGH when tilted and LOW when not.
  • 2x Male to male jumper wires
  • 2x Male to female jumper wires

Circuit

Same as day 5 with the below on the breakout board.

Day 9 Circuit Diagram

Day 10 - Break Beam Sensor

In the box

  • 1x Custom Break Beam Sensor (emitter and receiver) with male jumper wire ends
    • Emitter has two wires
    • Receiver has three wires
  • 1x 10k resistor

Break beam sensor

  • When the beam is broken (the receiver doesn't detect a signal) sends LOW to the pin.
  • When the beam is intact sends HIGH to the pin.
  • Watch for LOW signals.

Circuit

Same as day 5 with the below on the breakout board.

Day 10 Circuit Diagram

Day 11 - OLED Screen

In the box

  • 1x Pre-soldered 0.96" IC2 OLED I2C display (128x32)

I2C, sometimes referred to as IIC, stands for Inter-Integrated Circuit. It's another type of communication protocol which allows multiple I2C devices to communicate to a controller.

I2C requires just two wires to communicate (along with 3.3V and GND for our display) and has benefits over some other communication options.

Circuit

Day 11 Circuit Diagram Part 1

Day 11 Circuit Diagram Part 2

Need to install the micropython-ssd1306 library.

Projects

Day 12 - LED Strip

In the box

  • Addressable LED Strip

Circuit

Day 12 Circuit Diagram

Projects

About

Exploring the Raspberry Pi Pico with 12 Projects from The Pi Hut

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages