lesson 01 - working with the Pico W
posted: Tue, Jun 13, 2023 |
tagged: projects | dev | electronics | fec
return to project home | resources
Getting started with your Pico
Let's flash your Pico.
We'll be following this guide from learn.adafruit.com
- Plug your Pico in via USB with the cable from your kit.
- If the Pico does not appear in your file explorer, unplug the Pico, hold the reset button and then plug the Pico back in. After 2-3 seconds, release the reset button. You should hear a tone as the device registers with your laptop.
- Return to file explorer. In the RPI-RP2 mount you will see 2 files, index.htm and info_uf2.txt.
- index.htm will redirect you to the Raspberry Pi official site
- info_uf2.txt will give you version information for the currently installed firmware on the board.
- From within your CircuitPython-bins folder (in Downloads), drag the UF2 file onto the RPI-RP2 device. This will cause the device to load the updated bootloader and restart. The file may take 30-40 seconds to copy.
- When the device has rebooted, you should now see a device named CIRCUITPY in your file explorer.
- Congratulations, you have flashed your board and it now is running Cirucit Python.
If you explore the device from your file explorer, you'll see a new arrangement of files, as follows:
- lib folder - contains library / module files from Adafruit and the Community bundles to make interacting with components easier
- boot_out.txt - provides firmware, serial number and mac address information
- code.py - this is the default filename the board will expect to see that will containe the code it will execute
- settings.toml - an empty file for now
Let's get into Mu
Head over to your downloads folder, and double click on the MuEditor file with your Pico connected via USB. This will launch the coding environment we'll use for our work.
- The first load will take a few minutes
- When the editor is launching, you may be prompted for an environment to select, pick Circuit Python.
Example 01
Hello World with onboard LED
Reference Links
import board
import digitalio
import time
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
time.sleep(0.75)
led.value = False
time.sleep(0.75)
Example 02
Hello World with external LED
- Approach
- We'll use the 3V3 (3.3 volts DC) output on the Pico to supply power to the project
- We need to determine how much resistance is needed to not overwhelm the Red LED (note, different colored LEDs have different values)
- Red LED Sample Spec Sheet
- We need to know the forward current (IF) and the forward voltage (VF)
- From the spec sheet, we find IF to be 20 mA and VF to be 1.8-2.2V
- Given Ohms Law (the equation _V = I _ R), we can derive the necessary value for R
- R = (VSupply - VF) / I
- Note: VSupply is the supply voltage from the Pico
- R = (3.3V - 2V) / .02 = 130 Ohms
- We don't have a 130 Ohm resistor in the kit, so we go to the next higher value available, 220 Ohm
- Looking at the resister decoder, we see 220R is red-red-black
- V = Volts | I = Current (Amps) | R = Resistance (Ohms)
- Using an oversized resistor with LEDs is fine, the LED will appear dimmer than it's maximum value
- Wiring
- Do not connect the Pico to USB at this point, it should be disconnected from any power source
- Insert the pico into the Freenove Breakout Board for the Pico
- Loosen the terminals near the top right for GND, 3V3 and GP20
- Connect a black hookup wire to GND to the negative (-) rail of the breadboard
- Connect a red hookup wire to 3V3 to the positive (+) rail of the breadboard
- Connect a blue hookup wire to GP20 to row 13f of a the breadboard
- Connect the Anode (long leg, +) of the LED to an open position on row 13
- Connect the Cathode (short leg, -) of the LED to an open position on row 16
- Connect one leg of a 220R to row 16
- Connect the other leg of a 220R to the negative (-) rail of the breadboard
- Code
- In Mu, enter the following code and save the file as code.py to the Pico
import board
import digitalio
import time
led = digitalio.DigitalInOut(board.GP20)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
time.sleep(0.75)
led.value = False
time.sleep(0.75)
The above code block can be found here.
- Last step - Connect the USB port on the Pico to the USB port on your laptop. This will supply the Pico with 5VDC of supply voltage - Note that as the Red LED illuminates on the breadboard, the yellow LED on the breakout board illuminates to let you know current is flowing through the GP20 GPIO pin
return to project home