Skip to content

Instantly share code, notes, and snippets.

View mcbridejc's full-sized avatar

Jeff McBride mcbridejc

View GitHub Profile
@mcbridejc
mcbridejc / program_fuses.py
Created February 13, 2023 05:08
Setting GPNVM bits using PyOCD on Microchip SAM MCUs
"""Program GPNVM bits on a SAM microcontroller using pyocd
You'll need pyocd installed (`pip install pyocd`)
"""
from pyocd.core.helpers import ConnectHelper
import time
session = ConnectHelper.session_with_chosen_probe()
@mcbridejc
mcbridejc / kicad_group_example.py
Created April 10, 2022 18:04
How to group KiCad tracks created in python
"""
When creating a lot of board features (tracks, vias, etc) from a python script,
grouping them allows them to be easily selected together in pcbnew. This can be
useful if, for exampe, you want to move them together after generating, or if
you find yourself iterating and need to delete the old tracks each time before
re-running the script.
Luckily, it's easy to create a group and assign it to elements as they are
created in python; here's a quick example.
"""
@mcbridejc
mcbridejc / generate_track_layout.py
Last active October 26, 2023 23:20
Magnetic Train Track Kicad Plugin
"""KiCad plugin to generate linear stepper track traces in KiCad"""
import pcbnew
import numpy as np
WIDTH=13.2
PITCH=1.0
WIDTH_MARGIN = 1.2
LINE_WIDTH = 0.3
@mcbridejc
mcbridejc / Adding SPI chip selects on Raspberry Pi.md
Last active February 25, 2024 17:20
How to add or change SPI chip select pins on raspberry PI with device tree overlay

The raspberry pi SPI0 by default has 2 CS pins configured. The SPI driver in the kernel uses GPIOS toggled by software, rather than hardware controlled chip selects. This means that any GPIO can be used for a chip select, and any number of them can be supported concurrently. All of these setup for the SPI driver is defined in the device tree, and we can use device tree overlays stored in /boot to dynamically configure the device tree.

The attached example creates a SPI device with 5 CS pins, on GPIO 8, 7, 1, 5, and 6.

To compile it to a binary: dtc -@ -I dts -O dtb -o spi-cs-extend.dtbo spi-cs-extend.dts

Then place spi-cs-extend.dtbo into /boot/overlays and add the following line to your /boot/config.txt: dtoverlay=spi-cs-extend.

@mcbridejc
mcbridejc / cargo.toml
Created February 12, 2020 22:52
Tokio multiple periodic actions with Interval
[package]
name = "multidelaytest"
version = "0.1.0"
authors = ["Jeff McBride"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "0.2", features = ["macros", "time", "sync", "rt-core", "rt-threaded", "rt-util", "stream"] }
@mcbridejc
mcbridejc / cargo.toml
Created December 30, 2019 23:42
Simple rust web socket broadcaster example with ws-rs
[package]
name = "rssocket"
version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "*"
env_logger = "*"
ws = "*"
@mcbridejc
mcbridejc / camera.py
Created December 17, 2019 00:48
MJPEG streaming from raspberry pi camera to browser
import cv2
import numpy as np
import threading
from picamera import PiCamera
class Video(object):
WIDTH = 1024
HEIGHT = 768
@mcbridejc
mcbridejc / start_clock.py
Created August 25, 2019 05:26
Generate a clock from FTDI MPSSE
from pyftdi.ftdi import Ftdi
# Generate a clock output from the D1 pin of an FTDI device that support MPSSE mode (e.g. 232H or 2232H, among others)
# The clock runs continuously, assuming nothing is connected to D4 that will pull it low
# Which device and which port to use for dual port devices (e.g. 2232H)
# See https://eblot.github.io/pyftdi/urlscheme.html
device_url = "ftdi://ftdi:2232h/1"
# Target frequency