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
// Big block of macros to access EEPROM data
#include <avr/eeprom.h>
#define eeprom_read_to(dst_p, eeprom_field, dst_size) eeprom_read_block(dst_p, (void *)offsetof(__eeprom_data, eeprom_field), MIN(dst_size, sizeof((__eeprom_data*)0)->eeprom_field))
#define eeprom_read(dst, eeprom_field) eeprom_read_to(&dst, eeprom_field, sizeof(dst))
#define eeprom_write_from(src_p, eeprom_field, src_size) eeprom_write_block(src_p, (void *)offsetof(__eeprom_data, eeprom_field), MIN(src_size, sizeof((__eeprom_data*)0)->eeprom_field))
#define eeprom_write(src, eeprom_field) { typeof(src) x = src; eeprom_write_from(&x, eeprom_field, sizeof(x)); }
#define MIN(x,y) ( x > y ? y : x )
#define KEYPAD_SIZE 5
@projectgus
projectgus / gist:1807319
Created February 12, 2012 08:31
openwrt-zipit 3.2 libertas problem
scripted as;
sleep 15
ifconfig wlan0 up &
sleep 10
dmesg > after.log
/sbin/poweroff
ie 'ifconfig wlan0 up' is run @ 82
@projectgus
projectgus / serial_mux.py
Created September 4, 2012 02:28
Quick serial port to tcp socket muxer
#!/usr/bin/env python
import argparse, serial, socket, select
parser = argparse.ArgumentParser(description='Connect to a serial port and allow multiple TCP clients to talk to it (simultaneous output shared between all TCP clients, any client can write to port.)')
parser.add_argument('--baud', help="Baud rate", default=115200, type=int)
parser.add_argument('port', help="Port to listen on.", type=int)
parser.add_argument('serial', help="Serial port to share.")
def main():
args = parser.parse_args()
@projectgus
projectgus / 1_pv_leak.py
Created November 8, 2012 22:04
Demonstration of pv reference leak
import epics,gc
name1 = "c1v0:UPTIME"
name2 = "c2v0:UPTIME"
name3 = "c3v0:UPTIME"
def report_usage():
epics.ca.show_cache()
# use the gc's debugging features to look for leaked PV objects
gc.collect()
@projectgus
projectgus / zombie_pv.py
Created November 8, 2012 22:13
Demonstration of callbacks coming from otherwise stale PV object
import epics, time
pvname = "c1v0:UPTIME"
def my_callback(value, **kw):
print value
def setup_callback():
pv = epics.PV(pvname)
pv.add_callback(my_callback)
@projectgus
projectgus / gist:6016251
Created July 16, 2013 23:37
Simple mashup of the Arduino Ethernet WebServer example and the SD DumpFile example
/*
Web Server
A simple web server that sends the contents of "hello.txt" on the SD card
to any web client that connects.
Modified from the "Ethernet -> WebServer" & "SD -> DumpFile" Arduino examples
by Angus Gratton <[email protected]>
*/
@projectgus
projectgus / digikey_ordersplit.py
Last active December 20, 2015 07:29
At CCHS hackerspace we make a lot of group parts orders to save shipping costs. This script can split up a a DigiKey order's total by participant (assuming each person's name is listed in the Customer Reference field for the order.)
#!/usr/bin/env python3
"""
Digikey order splitter script for group buys. For Python 3.x. Public Domain.
Supports cases where people are paying in a different currency to the Digikey currency,
and also pro rata splitting of shipping costs.
If you use this then please sanity check the results before sending them
Usage:
@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.