Skip to content

Instantly share code, notes, and snippets.

@dccourt
dccourt / basic_opencv.py
Created June 6, 2012 23:07
Basic image capture and manipulation with Python and OpenCV
import cv2.cv as cv
import time
cv.NamedWindow('a', 1)
cv.NamedWindow('b', 1)
cv.NamedWindow('c', 1)
cv.NamedWindow('d', 1)
cap = cv.CaptureFromCAM(-1)
cv.SetCaptureProperty(cap, cv.CV_CAP_PROP_FRAME_HEIGHT, 240)
cv.SetCaptureProperty(cap, cv.CV_CAP_PROP_FRAME_WIDTH, 320)
@dccourt
dccourt / gist:2860094
Created June 2, 2012 21:54
dmesg output for Hue HD webcam
usb 1-1.2: new high speed USB device number 4 using dwc_otg
usb 1-1.2: New USB device found, idVendor=0c45, idProduct=62f1
usb 1-1.2: New USB device strings: Mfr=2, Product=1, SerialNumber=0
usb 1-1.2: Product: USB 2.0 Camera
usb 1-1.2: Manufacturer: Sonix Technology Co., Ltd.
Linux media interface: v0.10
Linux video capture interface: v2.00
uvcvideo: Found UVC 1.00 device USB 2.0 Camera (0c45:62f1)
input: USB 2.0 Camera as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.0/input/input0
usbcore: registered new interface driver uvcvideo
@dccourt
dccourt / RFTransmitter.ino
Created March 31, 2012 22:51
Transmit to Maplin radio controlled sockets using Arduino
// See http://www.fanjita.org/serendipity/archives/53-Interfacing-with-radio-controlled-mains-sockets-part-2.html
#define PAYLOAD_SIZE 48
#define DATA_PIN A4
#define VCC_PIN A5
#define GND_PIN A3
#define LED_PIN 13
@dccourt
dccourt / rf-receive.ino
Created March 29, 2012 23:11
Receive from Maplin RF transmitter using Arduino
// See http://www.fanjita.org/serendipity/archives/51-Interfacing-with-radio-controlled-mains-sockets-part-1.html
#define STATE_NOISE 0
#define STATE_COUNT_PRE 1
#define STATE_COUNT_RISE 2
#define STATE_DECODE_MSG_HI 3
#define STATE_DECODE_MSG_LO 4
// payload size in bits
#define PAYLOAD_SIZE 48
@dccourt
dccourt / gist:1775920
Created February 9, 2012 00:38
Simple SPI multiplexed addressing demo
// Digital potentiometer (MSP4131) programming over SPI
// D. Court 8 Feb 2012.
// Pin assignments (arduino digital pin numbering)
#define SRCLK_PIN 4
#define SPICLK_PIN 3
#define DATA_PIN 2
// /CS of each device goes to a (LSB-end) line of the shift reg D-outputs.
// Data line is connected to both SR and device
// SRCLK and RCLK are connected together on shift reg.
@dccourt
dccourt / gist:1714123
Created February 1, 2012 00:14
Power interrupter sketch
// Power interrupter
#define POWER_OUT_PIN 4 // Note : sense is inverted, i.e. ON = LOW.
// Use of pin 4 on ATTiny allows for ISP-reprogramming
void setup()
{
pinMode(POWER_OUT_PIN, OUTPUT);
}
@dccourt
dccourt / gist:1696604
Created January 29, 2012 01:27
Analogue comparator-based frequency counter
// Count zero crossings using analog comparator
// atmega328p:
// Uses pin 7 as the anacomp -ve input (AIN1)
// Uses pin 6 as the anacomp +ve input (AIN0)
// attiny85:
// Uses pin 1 as AIN1
// Uses pin 0 as AIN0
#ifdef __AVR_ATtiny85__
#define AIN1 1
@dccourt
dccourt / gist:1696597
Created January 29, 2012 01:26
Generic timer setup utility
//Setup Timer2.
//Configures the 8-Bit Timer2 to generate an interrupt
//at the specified frequency.
//Returns the timer load value which must be loaded into TCNT2
//inside your ISR routine.
//See the example usage below.
unsigned char SetupTimer2(float timeoutFrequency){
unsigned char result; //The timer load value.
@dccourt
dccourt / gist:1696583
Created January 29, 2012 01:22
Setting up the AVR analogue comparator registers
// Set up the comparator.
pinMode(AIN0, INPUT);
pinMode(AIN1, INPUT);
// ACI : Ana Comp Interrupt flag - writing a 1 clears it, hardware autoclears it when calling ISR
// ACIE : Ana Comp Int Enable
// ACIS1, ACIS0 : Ana Comp Int mode select:
// 0 0 Int on output toggle
// 0 1 Reserved
// 1 0 Int on falling output edge
// 0 1 Int on rising output edge
@dccourt
dccourt / servochuck
Created January 26, 2012 23:38
Simple Nunchuck/Servo mashup
// Controlling a servo position using a Wii Nunchuck.
// by Fanjita <http://www.fanjita.org/>
// Includes code from 'Knob' sample by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Wire.h>
#include <Servo.h>
#include "wiichuck.h"
Servo myservo; // create servo object to control a servo