--> ap/xxxxx


AVR-HID: (2008.03.26:1)

Low budget USB sensor input into Pure Data/Supercollider and other free softwares based around the ATmega8 microcontroller. This allows for very fast, multiple sensor input at high resolutions on a range of platforms (GNU/Linux, MAC OS X, Windows).

Six analogue inputs (0-5v) provide ten bit resolution. Sensors are attached to the P7 connector with Pin 1 as GND, Pin 2 as +5v, and all sensor six inputs following. P8 jumper is for four digital or pushbutton inputs (Pins 6,4,5,3 on the jumper).

Based on workshops with Derek Holzer (forthcoming 26 April 2008) and:


This project makes use of Objective Development's USB driver: http://www.obdev.at/avrusb/

The AVR/HID can be purchased as a kit or pre-built and tested from: http://pickledfeet.com/electronic%20kits.php

For SMD version and further developments please refer to: avrhid_dev



Parts list:

C1         100nF [optional]
C2         22 PF [all ceramic]            
C3         22PF        
C4         100nF       

CP1        CP10uF [optional]
CP2        CP10uF [electrolytic 16v]           

I1         ATMEGA8-16PI with socket

P1         CONN_5 [2.54 pitch connectors]      
P5         CONN_2      
P6         CONN_2      
P7         CONN_8      
P8         CONN_6 
R1         10K [resistors 1/4w 10%]       
R2         100R         [or increase to 330 ohms on some laptops]
R3         100R         [or increase to 330 ohms on some laptops]
R4         4.7K        
R5         2.2K        

U2         7805 voltage regulator [optional]       

X1         12 MHz CRYSTAL     
X2         USB-MB-H - USB BW socket (bent leads)    


Viewed from above. Single-sided copper (with jumper wires on top in red).

For generic etching instructions please see notes at: pcb


http://1010.co.uk/xxxxx-hid.tar.gz or: http://1010.co.uk/xxxxx-hid.zip

In this case the microcontroller was programmed under GNU/Linux using avrdude and an STK500 compatible programmer (avrusb500 below) with programming cable connections in this order:


Notes on other programmers:

See the short AVR/ATmega programming tutorial: avrprog


a) Very simple parallel port: http://www.bsdhome.com/avrdude/

works on some desktops/laptops.

b) AVR-HID can be adapted as a usbasp programmer below.

cd AVR-HID-6-10/firmware

make clean

make [one line in Makefile changed: COMPILE = avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega8 ]

make flash

[change line in Makefile also for:  avrdude -p m8 -c avrusb500 -e -U flash:w:~/main.hex ]

//with fuse bits set as follows:

avrdude -p m8 -u -c avrusb500 -t

w lf 0 0xff

w hf 0 0xdf

And using the programmer featured at:


Software usage:

The AVR-HID board does not require additional drivers. It's a class-compliant USB [HID] joystick.

For PD [Pure Data] on GNU/Linux and MAC OS X makes use of the [HID] object: http://at.or.at/hans/pd/hid.html

Windows: [pd_joystick]: http://crca.ucsd.edu/~jsarlo/pd/

HID example patch:

Example PD output [print]:

Device 0: 'AT Translated Set 2 keyboard' on '/dev/input/event0'
Device 1: 'TPPS/2 IBM TrackPoint' on '/dev/input/event1'
Device 2: 'PC Speaker' on '/dev/input/event2'
Device 3: 'Power Button (FF)' on '/dev/input/event3'
Device 4: 'Lid Switch' on '/dev/input/event4'
Device 5: 'Sleep Button (CM)' on '/dev/input/event5'
Device 6: '/usr/sbin/thinkpad-keys' on '/dev/input/event6'
Device 7: 'MUMT AVR-HID' on '/dev/input/event7'

Supported events:

  key   btn_0   Keys/Buttons (btn_trigger)
  key   btn_1   Keys/Buttons (btn_thumb)
  key   btn_2   Keys/Buttons (btn_thumb2)
  key   btn_3   Keys/Buttons (btn_top)

  abs   abs_x   Absolute Axis
  abs   abs_y   Absolute Axis
  abs   abs_z   Absolute Axis
  abs   abs_rx  Absolute Axis
  abs   abs_ry  Absolute Axis
  abs   abs_rz  Absolute Axis

  4 Key/Button types
  6 Absolute Axis types
And then [open]...

other HID softwares:

1] aseqjoy is a Joystick to ALSA MIDI Sequencer Converter:


2] Supercollider:

    HIDDeviceService.buildDeviceList(0, 0);
//replace 0 with your device number
//or just be sure to plug your device in last. 

        HIDDeviceService.action_({arg productID, vendorID, 
           locID, cookie, val;
            ( "Element Number: "++cookie++" Value: "++val ).postln;

with thanks to: www.randomfunction.com

See also GeneralHID helpfile:

[Quick start (GNU/Linux with GNU Emacs: M-x sclang-start


C-c C-h searches for a help file

C-M-h switches to the Help browser

E copies the buffer, puts it in text mode and sclang-minor-mode, to
enable you to edit the code parts to try out variations of the
provided code in the help file. With C-M-h you can then return to the
Help browser and browse further from the Help file.

C-c C-e allows you to edit the source of the HTML file, for example if
you want to improve it and commit it to the repository.
From: http://swiki.hfbk-hamburg.de:8888/:/579

3] Ixi's HID OSC server:

SDL based python standalone application that sends out via OSC any HID device (gamepad, joystick) event generated data:


4] Our own commandline client (including OSC):


Usage: ./hidtool read 5

[first rmmod usbhid to detach driver]

reads analogue 10 bit values form channel 5 to STDOUT.

Also included eegtool and hidtoolosc [channel] [IP] [port] for HID to OSC message forwarding.

(also note for pd-extended Debian testing/Lenny install: http://www.mail-archive.com/pd-list@iem.at/msg21782.html )

Hardware/sensor examples:

With BPW40 phototransistor:

[Parts: BPW40, 10K resistor]

With KTY81-120 temperature sensor:

[Parts: KTY81-120, 1K resistor, 2x 3.3K resistor, 2x 100K trimmer/potentiometer, LM358 dual op-amp]


See also PDplug workshop wiki

1] The board doubles as a standalone ATmega8 breakout and programming boards - the parts around the 7805 voltage regulator [capacitors C1, CP1, connector P6, and 7805] need NOT be assembled.

2] AVR-HID is also open to Arduino users who can consult the following reference:


3] Using code from: http://www.fischl.de/usbasp/ and a few jumpers the AVR-HID board can also be used to program AVR microcontroller using free software such as avrdude: http://www.bsdhome.com/avrdude/

A new design reflects these minor changes:


Also see the short AVR/ATmega programming tutorial: avrprog