This is an old revision of the document!


Paspberry Pi Pico

Pinout


On ADC 04 is a temperature sensor.
The on board LED is on GP 25.
To reset short the RUN pin low.


Micro Python

Raspberry Pi Pico Python SDK

Plug in the RP Pico with pressed BOOTESL button Download Micro Python for the RP Pico:

wget "https://www.raspberrypi.org/documentation/rp2040/getting-started/static/f70cc2e37832cde5a107f6f2af06b4bc/rp2-pico-20210205-unstable-v1.14-8-g1f800cac3.uf2"

Copy it to the RP Pico

MicroPython on Command Line

start minicom

 $ minicom -o -D /dev/ttyACM0

press Enter

 >>> from machine import Pin
 >>> led = Pin(25,Pin.OUT)
 >>> led.high()
 >>> led.low()

To leave minicom: Ctrl+A, Z, x

MicroPython in Thonny

Install Thonny:

 yaourt -S thonny

Select Micro Python (Raspberry Pi Pico) on the bottom of the IDE or in Tools/Options/Interpreter.
Run blink:

import machine
import utime
led_onboard = machine.Pin(25, machine.Pin.OUT)
while True:
    led_onboard.value(1)
    utime.sleep(5)
    led_onboard.value(0)
    utime.sleep(5)

And the first audio code, if one connects a wire to ADC 0 one get the simple Theremin:

import machine
import utime

led_onboard = machine.Pin(25, machine.Pin.OUT)
led_onboard.value(1)

sensor_poti=machine.ADC(0)
sound_pin=machine.Pin(15, machine.Pin.OUT)
while True:
    reading=sensor_poti.read_u16()
    # values from 304 to 65535
    # print(reading)
    pitch=reading / 655350
    sound_pin.value(1)
    utime.sleep(pitch)
    sound_pin.value(0)
    utime.sleep(pitch)
Save it on the Pico
  • for testing press F5 or the Run button
  • Shift+Ctrl+F2 or the Stop button to stop again
  • save the program as 'main.py' on the Raspberry Pi Pico

More sound with PicoBuzz by benevpi.


PWM

pwm=PWM(Pin(25))
pwm.freq(1000)

one can change the duty cycle, 0 to 65535

pwm.duty_u16(duty)

Interrupt

from machine import Pin

mypin=Pin(2,Pin.IN,Pin.PULL_UP)
mypin.irq(lambdapin:print("IRQ with flags:",pin.irq().flags()),Pin.IRQ_FALLING)

or

 mypin.irq(trigger=machine.Pin.IRQ_RISING, handler=myTask)

Multicore

 import _thread
 
 _thread.start_new_thread(Blink, ())

Synchronize two threads with allocate_lock()

 baton = _thread.allocate_lock()

in the threads

 baton.acquire()
 ...
 baton.release()

taken from Andreas Spiess on youtube


Programmable I/O

WS2812