Skip to content

Instantly share code, notes, and snippets.

@projectgus
projectgus / VAN_Monitor_Interrupts sketch
Created February 17, 2010 21:51
Arduino sketch to monitor a 125 kbps VAN automotive bus (similar to CAN bus)
#include <avr/interrupt.h>
const int pin_rx = 3; // Pin hooked to the output of the CAN transceiver
enum message_state { vacant, loading, ready };
const int ticksPerTs = 132; // 16Mhz clock / 125Kbps / 8 = 128 ticks/bit
const int timerLoadValue = 257 - ticksPerTs;
const int oneHalfTimerLoadValue = 257 - (ticksPerTs * 1.25); // Add an extra 1/4TS when we know we're at start of a bit
@projectgus
projectgus / tls_memory_test.py
Created November 21, 2023 23:31
Simple MicroPython TLS socket memory test
import esp
import esp32
import micropython
import network
import gc
import socket
import ssl
import time
SSID = 'DebugAP'
from machine import SPI, Pin
from lora import SX1262
def get_modem():
return SX1262(
spi=SPI(1, baudrate=2000_000, polarity=0, phase=0,
miso=Pin(12), mosi=Pin(11), sck=Pin(10)),
cs=Pin(3),
busy=Pin(2),
dio1=Pin(20),
@projectgus
projectgus / 99-usb-serial-by-vid-pid.rules
Created April 28, 2023 05:42
udev rule to create symlinks /dev/serial/usb/VID:PID for usb serial devices
# Create a /dev/serial/usb/VID:PID symlink for each usb serial device
#
# - Kernel will manage multiple devices with the same VID:PID so the symlink points to the latest attached (I think).
# - Doesn't handle devices with >1 port, looks like it links the first one(?). /dev/serial/by-id probably better for that.
SUBSYSTEMS=="tty", ENV{ID_BUS}=="usb", SYMLINK+="serial/usb/$env{ID_USB_VENDOR_ID}:$env{ID_USB_MODEL_ID}"
@projectgus
projectgus / context.md
Last active November 10, 2022 07:43
Basic examples of MicroPython LoRa modem driver use
@projectgus
projectgus / rp2-semihosting-when-cdc-closed.patch
Created October 26, 2022 06:26
MicroPython patch to output stdout to semihosting whenever USB-CDC is closed
diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt
index 8c8119e06..98c3de93d 100644
--- a/ports/rp2/CMakeLists.txt
+++ b/ports/rp2/CMakeLists.txt
@@ -92,6 +92,7 @@ set(MICROPY_SOURCE_LIB
${MICROPY_DIR}/shared/runtime/interrupt_char.c
${MICROPY_DIR}/shared/runtime/mpirq.c
${MICROPY_DIR}/shared/runtime/pyexec.c
+ ${MICROPY_DIR}/shared/runtime/semihosting.c
${MICROPY_DIR}/shared/runtime/stdout_helpers.c
@projectgus
projectgus / logger.py
Created October 10, 2022 00:29
Quick and dirty register logger for HL100100 DC motor controller
#!/usr/bin/env python
# Place in same directory as https://github.com/burpen/hl200200-controller-uart-utility code
from controller import *
import serial
import struct
import time
s = serial.Serial('/dev/ttyUSB0', 19200)
def readReg(reg, mask=0xFFF):
@projectgus
projectgus / hid_device.py
Last active October 4, 2022 05:48
MicroPython report-only HID debug Proof Of Concept
import machine
from micropython import const
_CONTROL_STAGE_IDLE = const(0)
_CONTROL_STAGE_SETUP = const(1)
_CONTROL_STAGE_DATA = const(2)
_CONTROL_STAGE_ACK = const(3)
_PACKET_SIZE = const(64)
@projectgus
projectgus / link.md
Last active July 6, 2022 20:05
some python code used to explore Mitsubishi Outlander diagnostic interface
@projectgus
projectgus / gist:6757491
Created September 29, 2013 23:29
Arduino sketch to calculate CRC32 of a given file from the SD card
/*
* SD card CRC32 calculator by Angus Gratton for Freetronics
*
* CRC32 implementation based on the implementation in the C SNIPPETS archive
* http://web.archive.org/web/20080303102524/http://c.snippets.org/snip_lister.php?fname=crc_32.c
*
* Original Copyright (C) 1986 Gary S. Brown. You may use this program, or
* code or tables extracted from it, as desired without restriction.
*
* This version is released with the same lack of restrictions, use however you please.