Skip to content

Instantly share code, notes, and snippets.

@Neradoc
Neradoc / picopico_safe_mode_boot.py
Last active July 12, 2023 07:49
boot.py implementing waiting to start into safe mode on Raspberry pico
import board
import time
from digitalio import DigitalInOut,Pull
led = DigitalInOut(board.LED)
led.switch_to_output()
safe = DigitalInOut(board.GP14) # <----- choose your pin with a button on it
safe.switch_to_input(Pull.UP)
@Neradoc
Neradoc / board_pin_mapping.py
Last active July 8, 2023 23:20
List all the pins in the board module, all aliases on the same line, sorted by name
import microcontroller,board
for pin in dir(microcontroller.pin):
if isinstance(getattr(microcontroller.pin, pin), microcontroller.Pin):
pins = ["{:28s} ".format("microcontroller.pin."+pin)]
for alias in dir(board):
if getattr(board, alias) is getattr(microcontroller.pin, pin):
pins.append("board.{}".format(alias))
print(" ".join(pins))
@Neradoc
Neradoc / uos.py
Last active June 20, 2023 14:40
UOS compatibility for mpremote compatibility
import storage
from os import *
def get_mount_for(path):
path = path.rstrip("/")
if path[0] != "/":
path = os.getcwd() + "/" + path
while len(path) > 0:
try:
return storage.getmount(path)
@Neradoc
Neradoc / finderbug-cpy.md
Last active June 14, 2023 23:05
Finder bug when openning files with multiple boards connected

First, random bits from discord conversation:

has anyone encountered a situation on macOS (Catalina) where you double click "code.py" on one circuit python drive but it opens the code.py from another ? I often have multiple devices connected, usually with different drive names (CLUE, QTPY, etc). It happens with different apps, or using the open command line, but it does not happen when using the "open" dialog from within the apps.

let's say I have "BLUEREMOTE" (a feather nrf52) and "CIRCUITBLUE" (a CPB), typing open /Volumes/CIRCUITBLUE/code.py actually opens /Volumes/BLUEREMOTE/code.py

@Neradoc Yes. Lately in Finder, only one CIRCUITPY drive out of many shows up. And so it only opens the files from that drive if I'm opening through finder. I've had to go through command line to find them, or go into /Volumes in Finder.

# SPDX-FileCopyrightText: 2022 Neradoc NeraOnGit@ri1.fr
# SPDX-License-Identifier: MIT
"""
This file was automatically generated using Circuitpython_Keyboard_Layouts
"""
from adafruit_hid.keyboard_layout_base import KeyboardLayoutBase
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
# SPDX-FileCopyrightText: Copyright (c) 2022 brainelectronics and contributors
# SPDX-License-Identifier: MIT
"""
Implementation to interact with Winbond W25Q Flash with software reset.
Credits & kudos to crizeo
Taken from https://forum.micropython.org/viewtopic.php?f=16&t=3899
Converted from https://github.com/brainelectronics/micropython-winbond
"""
@Neradoc
Neradoc / resilient-HID.py
Last active April 22, 2023 13:24
Concept of a resilient HID keyboard. Restarts when USB is lost. Waits for UAB to be back.
"""
Resilient HID:
Test at the start to wait for the USB connection to be available
"""
import microcontroller
import supervisor
import time
# wait for connection
while not supervisor.runtime.usb_connected:
@Neradoc
Neradoc / PMW3901.py
Last active April 22, 2023 13:18
Circuitpython-PMW3901 driver, port from Pimoroni https://github.com/pimoroni/pmw3901-python
import time
import struct
from adafruit_bus_device.spi_device import SPIDevice
__version__ = '0.1.0'
WAIT = -1
BG_CS_FRONT_BCM = 7
BG_CS_BACK_BCM = 8
@Neradoc
Neradoc / code.py
Created April 21, 2023 11:10
Xiao RP2040 pixel fade in CP
import time
import neopixel
import board
import math
import adafruit_rgbled
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
pixel.fill((255, 0, 255))
@Neradoc
Neradoc / board_display_grid_test.py
Created March 14, 2023 17:25
Test a builtin display with a grid to check colstart/rowstart and such
import board
import displayio
import time
import vectorio
display = board.DISPLAY
splash = displayio.Group(x=0, y=0, scale=1)
display.show(splash)
color_palette = displayio.Palette(2)