There’s trunk and then there’s whatever-ax-was-using

July 6th, 2010

feurig: ax have you gotten anything to work with deans post feburary lufa?
[1:29pm] ax: post feb. hmm, i’d have to look into my project files to remember which version i was usting
[1:29pm] ax: just a sec
[1:29pm] feurig: I was pulling my hair out with the may release and then I went back to the standard “what ever ax was using” and things started working
[1:30pm] feurig: you used the feb19 release on the midimonster stuff
[1:30pm] feurig: where is that (explicitive deleted) tourist????
[1:34pm] ax: yeah, /lufa_100219/
[1:35pm] ax: i like this ‘whatever ax was using’ standard
[1:35pm] ax:
[1:48pm] bzztbomb: That should be a source control tag

Why I hate DarwinPorts/MacPorts.

July 6th, 2010

Because they aren’t bsd ports.

  • They force you to carry redundant dependencies.
  • They do not allow you to fetch and compile the source files in a transparent way.
  • They do not give you clean access to the patches they use to make things work.
  • They haven’t had a current version of avr-gcc in over 4 years.
  • They just dont get it.

Today, I am working on a cross platform USB device which I hope to interface with ruby, python, and perl using libusb. The ruby bindings for libusb are for 1.0.xx which actually almost works on OSX nowadays. A quick sampling of using ruby-usb on osx, like most things embedded in apple land, is a trip more or less to hell. (see: http://www.jedi.be/blog/2009/11/11/ruby-usb-libusb/ http://www.ruby-forum.com/topic/192042) . Since most of my ruby is gem installed I just need a working version of libusb so I go to the darwin ports recommended above. Looking at the “raw” port file I see that there are really only two patches and so I go find them. They aren’t exposed for reasons that seem pretty stupid to me,  but I did find them at. http://libusb.darwinports.com/dports/devel/libusb/files/patch-libusb__io.c and  http://libusb.darwinports.com/dports/devel/libusb/files/patch-libusb__os__darwin_usb.c

When I downloaded the source file and went to wget the patches it got even more screwey.

wget http://libusb.darwinports.com/dports/devel/libusb/files/patch-libusb__io.c
--2010-07-06 00:28:13--  http://libusb.darwinports.com/dports/devel/libusb/files/patch-libusb__io.c
Resolving libusb.darwinports.com... 208.185.168.32
Connecting to libusb.darwinports.com|208.185.168.32|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2010-07-06 00:28:13 ERROR 403: Forbidden.

I didn’t want to deal with it so I just saved the links in my browser and patched the source files manually. After that a

./configure; make && make install && make clean

let me do the normal ruby thing.

gem install ruby-usb

Just like on all the other operating systems.

Avr C programming references (linux-osx biased)

June 3rd, 2010

Focused workshop: Artbots 30 May 10 — PNCA ($35)

May 22nd, 2010


In this workshop we will be taking our dorkboards and using them to create a simple machine that draws. The focus will be on hands on problem solving.

What you will get.

  • A servo and a geared motor with paper feed.
  • A motor driver board.
  • Misc parts.

What to bring:

  • A dorkboard, teensy or other arduino capable board.
  • A soldering iron.
  • Some basic tools (esp wire cutters, x-acto knife)
  • superglue
  • A hot glue gun.
  • foamcore or cardboard.
  • $35 or a copy of your rsvp / paypal reciept.

Where:

PNCA — 1432 NW Johnson St, Room 205

When:
Sunday May 30nd from 1 to 5pm

How do I rsvp?

Making Pigs Fly — Object Space, Spokane 07-11 June 2010 ($105)

May 16th, 2010

An introduction to physical computing for artists and musicians.

What:

This workshop is an opportunity for 15 to 25 people to spend a week working on the fundamentals of integrating micro-controllers into the arts. At the end of the week participants should be able to build and program their own Arduino compatible micro-controller system and use it to interact with the physical world using motors servos lights relays and switches.

The workshop will be structured with a hands on approach. The theory being that we learn best by doing. The first two days will be devoted to building and programming the base platform and using it to control various devices. The remaining 3 days will be a lab devoted to incorporating the new tools into actual pieces. The cost of the course is $105 and includes the materials listed below as well as 5 days of hands on instruction.

What you will get.

  • A Benito usb to serial programmer
  • A Dorkboard! (an Arduino clone) Kit
  • An introduction to the Arduino and microcontrollers in an artists setting
  • A servo and a geared motor with paper feed.
  • A motor driver board.
  • Misc parts.
  • Help when you need it
  • To know that what you built worked at least once
  • Ideas

What to bring:

  • A laptop (there will be some (not many) loaner systems available)
  • A soldering iron (20-30W Pencil type)
  • A standard usb cable (A->B)
  • Some basic tools (esp wire cutters, x-acto knife)
  • superglue
  • A hot glue gun.
  • foamcore or cardboard.
  • A copy of your rsvp / paypal reciept.
  • Ideas.

When:

June 7th through June 11th from 1-5pm.

Where:

Object Space Gallery:

1818 1/2 E Sprague, Spokane WA

How do I rsvp?

Windward Notes.

April 30th, 2010

Mantras,

  • Modularization.
  • Simplicity.
  • Stepwise refinement.

Tools

DS1306

Best code example is at .http://www.nearfuturelaboratory.com/2006/12/14/arduino-and-ds1306-real-time-clock/

only problem with sample code is that it only works in the full sp mode and the diagram on the page shows the other mode. (need a32khz crystal)

To Do:

Exchange for Tuesday

Give walt

  • 32khz crystals
  • proto boards
  • Bare lcd (maybe a temp/lcd controller board)
  • Laptop and EPC (load with ubuntu 9.10).
  • 4 dorkboards.

To develope.

  • Software modules for timer and lcd.
  • Better lcd/button controller
  • led meter boards.

Running Paul Stoffregons’s teensy_serial arduino core on DFU based chips.

April 20th, 2010
das blinkin

das blinkin

With a lot of my projects I have done my prototyping with Paul Stoffregon’s Teensy series of boards before moving them onto their own codebases. On those occasions where the “prototype was all I needed” I would compile the code using the teensyduino and then manually load the .hex file onto the target. As I am looking at using the arduino for more projects I decided to take a look at how paul interacts with the Arduino IDE and see if I could load code directly onto my chips.

boards.txt

The arduino allows for different chips and configurations through the boards.txt and the programmers.txt files. Each configuration usually will also have a “core” which maps the pins and handles the particulars of that chip. When you run paul’s teensyduino installer it adds several entrys to the boards.txt file including the entry below.

teensy_ser.name=Teensy 1.0 (USB Serial)
teensy_ser.upload.protocol=halfkay
teensy_ser.upload.maximum_size=15872
teensy_ser.upload.speed=38400
teensy_ser.upload.disable_flushing=true
teensy_ser.upload.avrdude_wrapper=teensy_reboot
teensy_ser.build.mcu=at90usb162
teensy_ser.build.f_cpu=16000000L
teensy_ser.build.core=teensy_serial
teensy_ser.build.post_compile_script=teensy_post_compile
teensy_ser.name=Teensy 1.0 (USB Serial) teensy_ser.upload.protocol=halfkay teensy_ser.upload.maximum_size=15872 teensy_ser.upload.speed=38400 teensy_ser.upload.disable_flushing=true teensy_ser.upload.avrdude_wrapper=teensy_reboot teensy_ser.build.mcu=at90usb162 teensy_ser.build.f_cpu=16000000L teensy_ser.build.core=teensy_serial ...
Looking at pauls additions to the boards.txt I see that he is using the teensy_serial core  that he has written to create a simple usb to serial interface and to map the usb avr pins and other peripherals to the arduino conventions. He is also adds an entry to the arduino uploader class which lets him use a wrapper for avrdude which lets him use his proprietary bootloader. This wrapper is installed by the Paul’s installer and  lives in the Arduino’s bin directory. After looking to see if this wrapper was a script I replaced the entry in the boards.txt and put a script into the bin directory called “dfume”, after seeing that my replacement wrapper worked I added two new entries for each class of avr that I wanted to use the atmega32u2 and the atmega32u4
#############################################################
fouryou.name = atMega32U4
fouryou.upload.protocol=atmega32u4
fouryou.upload.maximum_size=32256
fouryou.upload.speed=38400
fouryou.upload.disable_flushing=true
fouryou.upload.avrdude_wrapper=dfume
fouryou.build.mcu=atmega32u4
fouryou.build.f_cpu=16000000L
fouryou.build.core=teensy_serial
#############################################################
tooyou.name = atMega32u2
tooyou.upload.protocol=atmega32u2
tooyou.upload.maximum_size=32256
tooyou.upload.speed=38400
tooyou.upload.disable_flushing=true
tooyou.upload.avrdude_wrapper=dfume
tooyou.build.mcu=at90usb162
tooyou.build.f_cpu=16000000L
tooyou.build.core=teensy_serial
############################################################# fouryou.name = atMega32U4 fouryou.upload.protocol=atmega32u4 fouryou.upload.maximum_size=32256 fouryou.upload.speed=38400 fouryou.upload.disable_flushing=true fouryou.upload.avrdude_wrapper=dfume fouryou.build.mcu=atmega32u4 fouryou.build.f_cpu=16000000L fouryou.build.core=teensy_serial ############################################################# tooyou.name = atMega32u2 tooyou.upload.protocol=atmega32u2 tooyou.upload.maximum_size=32256 tooyou.upload.speed=38400 tooyou.upload.disable_flushing=true tooyou.upload.avrdude_wrapper=dfume tooyou.build.mcu=at90usb162 tooyou.build.f_cpu=16000000L tooyou.build.core=teensy_serial

I started with a blank script that just printed the arguments passed to the wrapper and then called it by restarting my Arduino (to reload the boards.txt) And then selecting one of the new boards and “Uploading” my code. This gave me a window to interactively work through my script. Since the avrdude_wrapper code just pretends to be an avrdude most of the script is munging the arguments passed to avrdude to get the commands to pass to dfu-programmer.

#!/usr/bin/perl
use Getopt::Std;
print @ARGV;
my %args;
my $hexfile;
my $dfu = "/usr/local/bin/dfu-programmer";
my $cpu;
my $hexfile;

getopt('pUc',\%args);
$hexfile=$args{U};
$hexfile =~ s/flash:w://;
$hexfile =~ s/:i//;
$cpu=$args{c};

print "\n[" . $hexfile . "]";
print "\n[" . $cpu . "]\n";
print "$dfu $cpu erase\n";
system "$dfu $cpu erase";
print "$dfu $cpu flash $hexfile\n";
system"$dfu $cpu flash $hexfile";
print "$dfu $cpu start\n";
system "$dfu $cpu start 1>&2";
print "\n";

There is one tricky bit. The current avr-gcc doesnt support the atmega32u2 correctly but the code for the at90usb162 is binary compatible so the build.mcu is set to the at90usb162. But then dfu-programmer supports the correct chip and wont find the device so we use the fact that the upload.protocol argument is passed directlyalong using the -c argument and everything works fine.

So now we just use the hwb and reset buttons to get the system into dfu mode and upload our code directly from the arduino. Its not as slick as the teensy in “auto” mode but it works.

TestBox

March 14th, 2010

The testbox is an LCD/Dorkboard based arduino clone with two buttons and a pair of potentiometers. The switches, power and 4 io pins are made avaliable via screw terminals on the ouside of the testbox.


#include
/*--------------------------------------------------------------
pulse generator for test box

Depending on the setting of left dial send send pulses out on digital ouput pin 2
at between 1 and 122 hz when left button is pressed.
the lcd should show the hz and the number of pulses sent.

*/

//defines for analog "dial" pins.
#define D1PIN 0
#define D2PIN 1
//defines for switches
#define S1PIN 17
#define S2PIN 16
// other pins avaliable for testbox 2, 3, 4, 13
#define PULSEPIN 2

// defines for smooting (nsamples) and debounce (milliseconds)
#define SMOOTHING 16
#define DEBOUNCE 50

//defines to map pins to lcd
#define D4 7
#define D5 8
#define D6 9
#define D7 10
#define RW 11
#define E 6
#define RS 12
#define BL 5

LiquidCrystal lcd(RS, RW, E, D4, D5, D6, D7);

int d1 = 0, d2 = 0, s1=0, s2=0;

/* variables for debouncing switches and knobs */
int s1reading = 0 , s1previous = 0;
long int d1sum = 0, d2sum = 0, s1time=0;
int samples = 0;

volatile int overflowcount;
volatile int pulsecount;
volatile int pinstate=HIGH;

ISR(TIMER2_OVF_vect) {
if (s1) {
if (++overflowcount > d1) {
overflowcount=0;
pinstate=!pinstate;
digitalWrite(PULSEPIN,pinstate);
if ( pinstate ) {
pulsecount++;
}
}
}
}

void setup()
{ overflowcount = 0;
pulsecount = 0;

delay(1000);

lcd.begin(2,16); // Print a message to the LCD.
pinMode(S1PIN, INPUT);
digitalWrite(S1PIN, HIGH);
pinMode(S2PIN, INPUT);
digitalWrite(S2PIN, HIGH);
lcd.setCursor(0,0);
lcd.print(" ");

TCCR2A = 0; //freerunning timer 2
TCCR2B = (CS21|CS22); //divide clock by 256
TIMSK2 = TOIE1; //enable timer2 terrupt

}

void loop()
{

s2 = !digitalRead(S2PIN); //read s2 for grins or DEBOUNCE as below.

//DEBOUNCE s1
s1reading = digitalRead(S1PIN);

// If the switch changed, due to bounce or pressing...
if (s1reading != s1previous) {
// reset the debouncing timer
s1time = millis();
}

if ((millis() - s1time) > DEBOUNCE) {
if (s1 == s1reading) { // if DEBOUNCEd reading is a change
s1=!s1reading;
if (s1) {
pulsecount=0;
}
}
}
s1previous = s1reading;

d1sum += analogRead(D1PIN);
d2sum += analogRead(D2PIN);
if (++samples > SMOOTHING) { //when i have SMOOTHING samples then average them.
d1sum /= SMOOTHING;
d2sum /= SMOOTHING;

d1=map(d1sum,0,1023,0,122); //map dial to what you want values to be
d2=map(d2sum,0,1023,0,300);

samples=0;
d1sum = 0;
d2sum = 0;
}

lcd.setCursor(0,0);
lcd.print("Rate: ");
lcd.setCursor(6,0);
lcd.print(122-d1);
lcd.print("Hz ");

lcd.setCursor(0,1);
if (s1) {
lcd.print("ON ");
} else {
lcd.print("OFF");
}
lcd.setCursor(6,1);
lcd.print("# ");
lcd.setCursor(8,1);
lcd.print(pulsecount);
}

Reprogramming your avr-usb device using atmel’s built in bootloader

March 5th, 2010

Getting code onto the MidiMonster or Benito device.

Midi Monster Button Locations.

Midi Monster Button Locations.

Benito 7g Switch Positions.

Benito 7g Switch Positions.

Benito 2010 Switch Locations

Benito 2010 Switch Locations

Benito Without Buttons.

Benito Without Buttons.

All of the code on the Benito and MidiMonster devices is open source and references an open source library called the Lightweight Usb For Avr (lufa). Getting the code compiled and onto the device requires a few other open source tools.

AVR-GCC

The most current and stable release of the toochain for the AVR has untill recently been maintained by Eric Wedddington and released as WinAvr (http://sourceforge.net/projects/winavr/) Winaver integrates nicely into atmels avr studio http://www.atmel.com/dyn/Products/tools_card.asp?tool_id=2725 and I reccomend that you get both if you are running windows. Each Winavr Release is closely followed by objective developments CrossPack for avr http://www.obdev.at/products/crosspack/index.html and a script for building the current toolchain on linux which is hosted by AvrFreaks at present there is also a debian package that was put out last month http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=90172

HWB? DFU?

Most Atmel “atmega” devices have a pin dedicated to determining weather or not the device goes into the bootloader depending on the devices flag settings. This pin is labled HWB (for hardware boot) on most of  the datasheets. The usb avr family has this mode set up by default. When you hold the hwb pin low and reset the device it goes into the bootloader. On these devices the built in bootloader uses a usb device class called the Device Firmware Uploader (DFU). Atmel provides a tool called flip for programming DFU devices on  windows and linux. There is an open source programmer called dfu-programmer http://dfu-programmer.sourceforge.net/

That other guys stuff.

Those of you who have worked with the teensy boards from paul stoffregon will notice some subtle differences. Paul wrote his own (closed source) bootloader rather than use the bootloader tha comes installed on the chips. Then he uses a hardware trick similar to the auto reset hack to make a single button manipulate both the reset and the hwb pins to put his boards into the bootloader. I didnt feel that either the two button arrangement or the builtin bootloaders were broken so I like most people working with these chips dont fix them.

Using the dfu-programmer

All of the programs in Dean Cameras Lightweight Usb for Avr have a “dfu” target. Once you have the target into the DFU mode you can simply

$make dfu

This will cause the dfu-programmer to erase the flash reprogramm it with a new hex file and restart the chip. You can also do this manually with the following commands

$dfu-programmer atmega32u2 erase
$dfu-programmer atmega32u2 flash mycode.hex
$dfu-programmer atmega32u2 start

This will cause the dfu-programmer to erase the flash reprogramm it with a new hex file and restart the chip.

Focused Workshop: Programming the Midi Monster (28FEB10 PNCA).

February 23rd, 2010

What: Focused workshop: programming Midi devices using the Lightweight Usb For AVR library (Lufa) and the MidiMonster.

When: Sunday 28 Feb 2010 1-5 pm.

Where: PNCA (NW 12th and Johnson) #205

Cost: $35 (includes Midi Monster)
(If you have a MidiMonster from the PD Workshop and wish to use it please bring $10)

Materials: you Should Bring, a laptop and a mini usb cable. Please install Arduino >16 as well.

In this workshop we will be going through the firmware built by Alex Norman as an example of how to develop midi devices using the avr microcontoller. Topics covered will include:

  • The Midi Specification
  • The USB Midi Specification
  • The Lightweight Usb for AVR  library.
  • Programming the avr using avr-gcc

To reserve a place in the class please rsvp at http://tempusdictum.com/tdproducts.html