This project uses the Raspberry Pi Pico 2WH SC1634 (wireless, with header pins).
Each team must provide a micro-USB cable that connects to their laptop to plug into the Pi Pico. The cord must have the data pins connected. Splitter cords with multiple types of connectors fanning out may not have data pins connected. Such micro-USB cords can be found locally at Microcenter, convenience stores, etc. The student laptop is used to program the Pi Pico. The laptop software to program and debug the Pi Pico works on macOS, Windows, and Linux.
This miniproject focuses on using MicroPython using Thonny IDE. Other IDE can be used, including Visual Studio Code or rshell.
- Raspberry Pi Pico WH SC1634 (WiFi, Bluetooth, with header pins)
- Freenove Pico breakout board FNK0081
- Piezo Buzzer SameSky CPT-3095C-300
- 10k ohm resistor
- 2 tactile switches
The photoresistor uses the 10k ohm resistor as a voltage divider circuit. The 10k ohm resistor connects to "3V3" and to ADC2. The photoresistor connects to the ADC2 and to AGND. Polarity is not important for this resistor and photoresistor.
The MicroPython
machine.ADC
class is used to read the analog voltage from the photoresistor.
The machine.ADC(id) value corresponds to the "GP" pin number.
On the Pico W, GP28 is ADC2, accessed with machine.ADC(28).
PWM (Pulse Width Modulation) can be used to generate analog signals from digital outputs. The Raspberry Pi Pico has eight PWM groups each with two PWM channels. The Pico WH pinout diagram shows that almost all Pico pins can be used for multiple distinct tasks as configured by MicroPython code or other software. In this exercise, we will generate a PWM signal to drive a speaker.
GP16 is one of the pins that can be used to generate PWM signals. Connect the speaker with the black wire (negative) to GND and the red wire (positive) to GP16.
In a more complete project, we would use additional resistors and capacitors with an amplifer to boost the sound output to a louder level with a bigger speaker. The sound output is quiet but usable for this exercise.
Musical notes correspond to particular base frequencies and typically have rich harmonics in typical musical instruments. An example soundboard showing note frequencies is clickable. Over human history, the corresspondance of notes to frequencies has changed over time and location and musical cultures. For the question below, feel free to use musical scale of your choice!
Pico MicroPython time.sleep() doesn't error for negative values even though such are obviously incorrect--it is undefined for a system to sleep for negative time. Duty cycle greater than 1 is undefined, so we clip the duty cycle to the range [0, 1].
- Pico 2WH pinout diagram shows the connections to analog and digital IO.
- Getting Started with Pi Pico book