Giter VIP home page Giter VIP logo

raspberrypi-pico-micropython-cookbook's Introduction

Raspberrypi Pico MicroPython Cookbook

Updating...

Blinky

from machine import Pin
import time

led = Pin(25, Pin.OUT)

while True:
    led.toggle()
    time.sleep(0.5)

or

from machine import Pin, Timer

led = Pin(25, Pin.OUT)
blink = lambda _: led.toggle()
    
Timer().init(mode=Timer.PERIODIC, period=500, callback=blink)

or

from machine import Pin
import uasyncio

async def blink(led):
    while True:
        led.toggle()
        await uasyncio.sleep_ms(500)

uasyncio.run(blink(Pin(25, Pin.OUT)))

or

from machine import Pin
import rp2

@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def blink():
    set(pins, 1)
    set(x, 31)                  [6]
    label('delay_high')
    nop()                       [29]
    jmp(x_dec, 'delay_high')

    set(pins, 0)
    set(x, 31)                  [6]
    label('delay_low')
    nop()                       [29]
    jmp(x_dec, 'delay_low')
    
sm = rp2.StateMachine(0, blink, freq=2000, set_base=Pin(25))
sm.active(1)

Overclocking

The Pico has default frequency of 125 MHz but can be overclocked as high as 270 MHz (which uses higher CPU voltage and might be less stable):

from machine import freq

freq(270000000)

Remember to reset the frequency back to 125000000. (Note: firmware v1.18 seems fixed this problem.)

NeoPIxel (WS2812) PIO Driver

The NeoPixel driver is based on the official PIO example, repackaged into a class similar to CircuitPython's NeoPixel driver.

DHT11/DHT22 PIO Driver

The DHT driver is based on Harry Fairhead & Mike James' DHT22 PIO code, repackaged into a class similar to MicroPython's dht module on ESP boards.

Multicore and Game of Life

threads.py is a simple example of how to run two tasks simultaneously on both of RP2040's cores.

There's also two versions of Conway's Game of Life with OLED display, with or without utilizing dual cores.

Links

raspberrypi-pico-micropython-cookbook's People

Contributors

alankrantas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.