{"id":19601621,"url":"https://github.com/alankrantas/raspberrypi-pico-micropython-cookbook","last_synced_at":"2025-04-27T17:32:01.568Z","repository":{"id":113012501,"uuid":"334806541","full_name":"alankrantas/raspberrypi-pico-micropython-cookbook","owner":"alankrantas","description":"MicroPython drivers and experiments on Raspberry Pi Pico","archived":false,"fork":false,"pushed_at":"2023-10-11T05:47:20.000Z","size":267,"stargazers_count":8,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2023-10-11T09:58:50.488Z","etag":null,"topics":["micropython","python","raspberrypipico"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alankrantas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-02-01T02:20:33.000Z","updated_at":"2023-07-23T11:14:48.000Z","dependencies_parsed_at":"2023-10-11T07:47:54.520Z","dependency_job_id":null,"html_url":"https://github.com/alankrantas/raspberrypi-pico-micropython-cookbook","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fraspberrypi-pico-micropython-cookbook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fraspberrypi-pico-micropython-cookbook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fraspberrypi-pico-micropython-cookbook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fraspberrypi-pico-micropython-cookbook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alankrantas","download_url":"https://codeload.github.com/alankrantas/raspberrypi-pico-micropython-cookbook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224076432,"owners_count":17251755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["micropython","python","raspberrypipico"],"created_at":"2024-11-11T09:19:11.055Z","updated_at":"2024-11-11T09:19:12.391Z","avatar_url":"https://github.com/alankrantas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raspberrypi Pico MicroPython Cookbook\n\nUpdating...\n\n## Blinky\n\n```python\nfrom machine import Pin\nimport time\n\nled = Pin(25, Pin.OUT)\n\nwhile True:\n    led.toggle()\n    time.sleep(0.5)\n```\n\nor\n\n```python\nfrom machine import Pin, Timer\n\nled = Pin(25, Pin.OUT)\nblink = lambda _: led.toggle()\n    \nTimer().init(mode=Timer.PERIODIC, period=500, callback=blink)\n```\n\nor\n\n```python\nfrom machine import Pin\nimport uasyncio\n\nasync def blink(led):\n    while True:\n        led.toggle()\n        await uasyncio.sleep_ms(500)\n\nuasyncio.run(blink(Pin(25, Pin.OUT)))\n```\n\nor\n\n```python\nfrom machine import Pin\nimport rp2\n\n@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)\ndef blink():\n    set(pins, 1)\n    set(x, 31)                  [6]\n    label('delay_high')\n    nop()                       [29]\n    jmp(x_dec, 'delay_high')\n\n    set(pins, 0)\n    set(x, 31)                  [6]\n    label('delay_low')\n    nop()                       [29]\n    jmp(x_dec, 'delay_low')\n    \nsm = rp2.StateMachine(0, blink, freq=2000, set_base=Pin(25))\nsm.active(1)\n```\n\n## Overclocking\n\nThe 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):\n\n```python\nfrom machine import freq\n\nfreq(270000000)\n```\n\nRemember to reset the frequency back to 125000000. (Note: firmware v1.18 seems fixed this problem.)\n\n## NeoPIxel (WS2812) PIO Driver\n\nThe [NeoPixel driver](https://github.com/alankrantas/raspberrypi-pico-micropython-cookbook/tree/main/neopixel) is based on the official PIO example, repackaged into a class similar to CircuitPython's NeoPixel driver.\n\n## DHT11/DHT22 PIO Driver\n\nThe [DHT driver](https://github.com/alankrantas/raspberrypi-pico-micropython-cookbook/tree/main/dht) is based on [Harry Fairhead \u0026 Mike James' DHT22 PIO code](https://www.i-programmer.info/programming/hardware/14572-the-pico-in-micropython-a-pio-driver-for-the-dht22.html?start=2), repackaged into a class similar to MicroPython's dht module on ESP boards.\n\n## Multicore and Game of Life\n\n[threads.py](https://github.com/alankrantas/raspberrypi-pico-micropython-cookbook/blob/main/threads.py) is a simple example of how to run two tasks simultaneously on both of RP2040's cores.\n\nThere's also two versions of [Conway's Game of Life](https://github.com/alankrantas/raspberrypi-pico-micropython-cookbook/tree/main/game-of-life) with OLED display, with or without utilizing dual cores.\n\n## Links\n\n* [Raspberry Pi Pico - Getting Start with MicroPython](https://www.raspberrypi.org/documentation/pico/getting-started/#getting-started-with-micropython)\n* [Raspberry Pi Pico Datasheet](https://datasheets.raspberrypi.org/pico/pico-datasheet.pdf)\n* [Raspberry Pi Pico Python SDK](https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf)\n* [Raspberry Pi Pico Python SDK Examples](https://github.com/raspberrypi/pico-micropython-examples)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Fraspberrypi-pico-micropython-cookbook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falankrantas%2Fraspberrypi-pico-micropython-cookbook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Fraspberrypi-pico-micropython-cookbook/lists"}