MicroPython on Raspberry Pico 2040

MicroPython

  1. Download the MicroPython UF2 file.
  2. Push and hold the BOOTSEL button and plug your Pico into the USB port of your Raspberry Pi or other computer. Release the BOOTSEL button after your Pico is connected.
  3. It will mount as a Mass Storage Device called RPI-RP2.
  4. Drag and drop the MicroPython UF2 file onto the RPI-RP2 volume. Your Pico will reboot. You are now running MicroPython.
ls /dev/*usb*
# returns /dev/cu.usbmodem14201 /dev/tty.usbmodem14201

Prepare Virtual Env

$ mkdir pico-tests
$ cd pico-tests
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install rshell$ rshell -p /dev/tty.usbmodem14201 --buffer-size 512
$ repl

..

print("Hello, Pico!")from machine import Pin
led = Pin(25, Pin.OUT)
led.on()
from machine import ADC
temp_sensor = ADC(4)
temperature = temp_sensor.read_u16()

Running a micropython script:

nano main.py

Copy paste this test script LED PWM in main.py

# Example using PWM to fade an LED.import time
from machine import Pin, PWM
# Construct PWM object, with LED on Pin(25).
pwm = PWM(Pin(25))
# Set the PWM frequency.
pwm.freq(1000)
# Fade the LED in and out a few times.
duty = 0
direction = 1
for _ in range(8 * 256):
duty += direction
if duty > 255:
duty = 255
direction = -1
elif duty < 0:
duty = 0
direction = 1
pwm.duty_u16(duty * duty)
time.sleep(0.001)

Transfer this to pico using

cp pwm_led.py /pyboard/main.py

References

--

--

--

Engineer | Engineering

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Here is something cool you can do while programming!

Our experience at the AWS Berlin Summit 2019

Docker crash course (1)

Intergrating GraphQL with GoLang: The Right Way

How To Install Django and Python on Windows

CentOS 8 SSH Server Hardening & Create Users

CS 373 Fall 2021: Victoria Hall

Introducing Button Swap

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maruti Muthu

Maruti Muthu

Engineer | Engineering

More from Medium

Groot in Linux

What is a dynamic library compared to a static library?

Setting up Emacs for Clojure Programming Within Seconds

The Arduino Chronicles 3: Arduino Mega Basics/Resistors and LEDs