MicroPython on Raspberry Pi Pico

From Embedded Workshop
Revision as of 15:28, 16 May 2021 by JMerkle (talk | contribs) (Created page with "Last weekend, I picked up two Raspberry Pi Pico boards at the local Microcenter.<br> Once you have a Pico, you should visit the following website:<br> https://www.raspberrypi....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Last weekend, I picked up two Raspberry Pi Pico boards at the local Microcenter.
Once you have a Pico, you should visit the following website:
https://www.raspberrypi.org/documentation/rp2040/getting-started/

If you plan on installing MicroPython onto your Pico, I recommend downloading and reading the following two resources (books):
(Both of them detail how to install MicroPython onto your device.)
https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf
https://hackspace.raspberrypi.org/books/micropython-pico/pdf/download

CircuitPython is available via this webpage:
https://circuitpython.org/board/raspberry_pi_pico/

I recommend using Thonny when using MicroPython with the Pico.
It allows storing (and retrieving) programs to/from your host's hard drive.

Here is my version of the "blinky" program for the board:

#led_blink.py
#With the Raspberry Pi Pico board, blink the on-board LED
from machine import Pin
import utime
led=Pin(25,Pin.OUT) # on-board LED is GPIO 25
while True:
    led.on()
    utime.sleep(0.2)
    led.off()
    utime.sleep(0.2)
If you change the GPIO to 0 (upper left corner of the board), select that GPIO for your LED output,
and remove the delays, you'll get a 66.9KHz square wave output from GPIO_0. Not too bad for an interpreter....
from machine import Pin
led=Pin(0,Pin.OUT)
while True:
    led.on()
    led.off()
If you use led.value(0) and led.value(1) instead of led.off() and led.on(), the resulting output frequency
is a little slower, 64.3KHz, since the code now has to evaluate the parameter passed in.

Since the Pico, with its MicroPython image, doesn't provide any Python program storage,
any power loss or reset causes the program to stop and not restart.

Overall conclusion: I prefer the STM32 MicroPython boards / images since they create a file store for MicroPython programs.
main.py can be modified to run a user's Python program, stored in on-board FLASH memory.