MicroPython on Raspberry Pi Pico: Difference between revisions

From Embedded Workshop
Jump to navigation Jump to search
(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....")
 
No edit summary
 
Line 39: Line 39:
  is a little slower, 64.3KHz, since the code now has to evaluate the parameter passed in.
  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,<br>
Using the Thonny application to interface with the Raspberry Pi Pico, running MicroPython, provides<br>
any power loss or reset causes the program to stop and not restart.<br><br>
the ability to store files onto the Pico board. If you store a Python program as main.py, it will auto-start<br>
 
when power is applied.
'''Overall conclusion:'''
I prefer the STM32 MicroPython boards / images since they create a file store for MicroPython programs.<br>
main.py can be modified to run a user's Python program, stored in on-board FLASH memory.

Latest revision as of 16:26, 18 May 2021

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.

Using the Thonny application to interface with the Raspberry Pi Pico, running MicroPython, provides
the ability to store files onto the Pico board. If you store a Python program as main.py, it will auto-start
when power is applied.