Skip to content

Instantly share code, notes, and snippets.

@Neradoc
Neradoc / code_openlcd_temp.py
Last active March 3, 2021 16:25
Display temperature on a Sparkfun SerLCD with a minimal driver
import time
import board
DISPLAY_ADDRESS1 = 0x72
i2c = board.I2C()
# from sparkfun_serlcd import Sparkfun_SerLCD_I2C
# lcd = Sparkfun_SerLCD_I2C(i2c,DISPLAY_ADDRESS1)
import openlcd_mini
@Neradoc
Neradoc / oled_temperature.py
Created March 3, 2021 16:15
Display a temperature sensor on an I2C OLED REPL with the QT PY Haxpress
import time
import board
print("I2C")
i2c = board.I2C()
while not i2c.try_lock():
i2c.unlock()
#i2c.unlock()
try:
scan = i2c.scan()
@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)
"""
NOTE: requires the usual secrets.py file
The test
- connects to the server
- sends headers to switch to websockets mode
- reads the headers that the server sends back
Note: the code doesn't do anything else with the connection,
it will hang or disconnect, but it should receive the headers first.
import wifi
import socketpool
import ssl
import secrets
import sys
SSL = False
try:
from secrets import secrets
@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))
import wifi
import ssl
import socketpool
import adafruit_requests
from secrets import secrets
print("WIFI: Connecting")
#wifi.radio.start_scanning_networks()
wifi.radio.connect(secrets['ssid'],secrets['password'])
#wifi.radio.stop_scanning_networks()
@Neradoc
Neradoc / mcc_pin_mapping_sorted.py
Last active September 13, 2021 17:09
List all the pins in the board and microcontroller modules, all aliases on the same line, microcontroller pin first
import board
import microcontroller
allpins = []
for pin in dir(microcontroller.pin):
if isinstance(getattr(microcontroller.pin, pin), microcontroller.Pin):
pins = []
for alias in dir(board):
if getattr(board, alias) is getattr(microcontroller.pin, pin):
pins.append("board.{}".format(alias))
pins.sort()
@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.

@Neradoc
Neradoc / arduinoInstall.py
Last active January 10, 2021 09:59
Arduino sketch installer from the command line (mac version)
#!/usr/bin/env python3
import argparse, os, re, subprocess, glob, datetime, sys, shutil
import usb
import serial.tools.list_ports
tmpFiles= "/tmp/arduinotmp"
logFile = "/Users/spyro/Developement/ArduinoLib/ArduinoInstall.log"
arduinoCommand = ['arduino-cli',"compile"]
RED = '\033[91m'