Skip to content

Instantly share code, notes, and snippets.

View pingswept's full-sized avatar

Brandon Stafford pingswept

  • Tufts University
  • Somerville, Massachusetts, USA
View GitHub Profile
@pingswept
pingswept / dmx_test.ino
Created November 15, 2012 22:34
First cut at DMX receiving code for Leonardo / Saikoduino
#define RX_STATUS_PIN 13
#define RX_ENABLE_PIN 2
#define TX_ENABLE_PIN 3
volatile uint8_t DmxRxField[8]; //array of DMX vals (raw)
volatile uint16_t DmxAddress; //start address
enum {IDLE, BREAK, STARTB, STARTADR}; //DMX states
@pingswept
pingswept / servo-test.py
Created December 15, 2012 00:10
Servo test code in Python for Pololu Micro Maestro servo controller
@public.route('/speed/<channel>/<pulse_in_ms>')
def set_motor_speed(channel, pulse_in_ms):
pytronics.serialWrite(chr(0xAA), speed=9600)
if (channel == 'right'):
side = chr(0x01)
else:
side = chr(0x02)
rough_speed = (int(pulse_in_ms) >> 7) & 0x7F # grab bits 7-13
fine_speed = int(pulse_in_ms) & 0x7F # wipe out all but bits 0-6
pytronics.serialWrite(chr(0x84) + side + chr(fine_speed) + chr(rough_speed), speed=9600)
@pingswept
pingswept / read-ftdi.c
Created December 15, 2012 00:22
C shim to read serial data via FTDI driver. Compile on Rascal with: gcc -lftdi -oread-ftdi read-ftdi.c
/* simple.c
Simple libftdi usage example
This program is distributed under the GPL, version 2
*/
#include <ftdi.h>
#include <stdio.h>
#include <string.h>
@pingswept
pingswept / datalogger.py
Created December 19, 2012 16:00
Hacked first version of weather station code. Bloated, but works.
import sqlite3
import datetime
sql_live = """SELECT
strftime('%Y-%m-%d %H:%M GMT', logdate) AS logdate,
avg({0}) AS {0}
FROM log
WHERE logdate >= datetime('now', '-180 minutes')
GROUP BY strftime('%Y-%m-%d %H:%M', logdate)
ORDER BY 1;"""
@pingswept
pingswept / weather_usb.cpp
Created December 21, 2012 19:27
C++ program to talk to the open source libftdi driver (http://www.intra2net.com/en/developer/libftdi/) to read data from Sparkfun's USB Weather Board. Ships by default on the Rascal, http://rascalmicro.com
/* weather_usb.cpp
Weather station client using libftdi
compile: g++ -l ftdi -o weather_usb weather_usb.cpp
This program is distributed under the BSD license
*/
#include <ftdi.h>
@pingswept
pingswept / server.py
Last active May 5, 2023 22:45
Code for Color Commons project on Greenway Light Blades in Boston. The real code starts around line 808; the rest is mostly boilerplate and data.
from flask import Flask, render_template, request
from uwsgidecorators import *
import pytronics
import os, time
public = Flask(__name__)
public.config['PROPAGATE_EXCEPTIONS'] = True
# Include "no-cache" header in all POST responses
@public.after_request
@pingswept
pingswept / color-commons.py
Created February 4, 2013 22:18
A snippet of code from the Color Commons interactive light sculpture in Boston, USA http://newamericanpublicart.com/colorcommons/index.html
try:
program = int(d[color[0:25].lower()])
except KeyError:
print 'color {0} not found'.format(color)
program = int(d['red'])
command = 'X04%(number)2.2X' % {"number": program}
print 'Translated {0} to {1}'.format(color, command)
if (command in allowed_commands):
pytronics.serialWrite(command, speed=9600)
else:
@pingswept
pingswept / README.md
Last active December 14, 2015 00:29
Color Commons
@pingswept
pingswept / fdsystems.py
Last active December 14, 2015 07:49
(Unfinished skeleton of a) Python library to control http://4DSystems.com LCD over a serial port from the Rascal.
import pytronics, webcolors
from math import pi, radians, sin
def clear_lcd(): # also moves cursor to 0,0
pytronics.serialWrite(chr(0xFF) + chr(0xCD), 9600)
def put_string(data):
pytronics.serialWrite(chr(0x00) + chr(0x18) + data + chr(0x00), 9600)
def draw_filled_rectangle(x1, y1, x2, y2, color):
@pingswept
pingswept / precision_voltage_shield.ino
Last active June 28, 2018 10:52
Code for reading voltages with the Precision Voltage Shield, an Arduino shield for reading very precisely. 8 channels; 14-bit, 16-bit, and 18-bit versions. More details at http://rascalmicro.com/blog/2013/03/21/bringing-an-analog-voltage-arduino-shield-to-life/
// Copyright 2014, Brandon Stafford, brandon@rascalmicro.com
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the