Archive for August 2006

Example for avr-libc eeprom.h

I must say that I’m really beginning to bond with my Atmega8 microcontroller. It seems that every time I think of a feature I want my microcontroller to have, it turns out it’s already in there. Not bad for a $2 chip.

In this case what I wanted was somewhere I could programmatically write data that would be preserved even when the power goes out. Turns out the Atmega8 actually has some built in EEPROM memory (as well as its RAM and its Flash memory where your program is stored). But I couldn’t find any example code for these EEPROM features, even though they seemed well supported by avr-libc library.

Turns out doing it was pretty obvious…the only wrinkle was that I had to upgrade to version 1.4 of the library to get all the latest goodness. Check out the code in my source control.

This program is just a simple couter app that updates some LEDs everytime you press a button. But the exciting thing it does is remembers the current state of the counter even when it’s powered off.

minor update to ruby_evdev

So Josh looked at my code and suggested that I change my write_event function to use syswrite. Which required a tiny bit of uglyness but seems to work.

I went in and added licensing information too (GPL version 2…inherited from the evdev library itself).

Everything’s in the repository and the tarball. I think it’s time to post this bugger to the wider world.

evdev for ruby (with morse code!)

I built a ruby wrapper for the linux evdev interface. evdev is an interface that lets you work with various linux input devices – touchscreens and mouses and joysticks and keyboards.

So what can you do with this?

  • Well, you can map the interesting (yet unused) buttons on your keyboards and mice to ruby functions. Even those crazy buttons like volume up and down are fair game
  • If you are the sort of person who can never have too many buttons, you could even attach an additional usb keyboard and have 100+ additional ruby programmable keys to play with (this would require just a tiny bit of xorg.conf playing…but ask me an I’ll explain it).
  • You can control your keyboard LEDs and have them flash when interesting events occur (like mail, or when you’re missing a meeting)

I’ve written one sample app. It takes data on STDIN and outputs to your scroll lock LED in morse code. Just like in Cryptonomicon!

fancy documentation
the code itself
a tarball
morse sample documentation

Note that because this has a c extension in it, you’ll have to recompile it on your linux system. It’s super easy. Go to the root and type “ruby extconf.rb”…this will generate a Makefile. Then type “make” and you should be good to go.

Update! If you want to make this comptable with Ruby 2, use this very nice patch file by Scott Johnson

DARCS: on notice

DARCS: on notice

I finally gave up and blew away my old darcs repository. There is a new one now, in the same place, which contains most of the files that the old one did.

Everything was going great right up untill I added a squeak image to my repository. These are bigger files (tens of megabytes) but for some reason forever after I did that every change I made to the repository was slooow. How slow, you ask? Use up all the memory on my system and crawl for 20 minutes so I can’t even use the mouse slow. And especially slow was all the various operations to try and figure out what was going on with the repository.

So screw it. I have a new repository that’s fast again. But I’m officially putting darcs on notice.

flash error at address 0×2

Pop quiz geeklings: see if you can figure out why Buffalo is an idiot in only 30 lines of output:

594% make flash
avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega16 -x assembler-with-cpp -c usbdrv/usbdrvasm.S -o usbdrv/usbdrvasm.o
avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega16 -c usbdrv/oddebug.c -o usbdrv/oddebug.o
avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega16 -c main.c -o main.o
avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega16 -o main.bin usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
rm -f main.hex main.eep.hex
avr-objcopy -j .text -j .data -O ihex main.bin main.hex
./checksize main.bin
ROM: 2100 bytes (data=6)
RAM: 66 bytes
uisp -dprog=stk500 -dserial=/dev/ttyS0 -dpart=atmega16 –erase –upload –verify if=main.hex
Atmel AVR ATmega8 is found.
Uploading: flash
Verifying: flash
flash error at address 0×2: file=0x7b, mem=0×12
flash error at address 0×6: file=0xbc, mem=0×94
flash error at address 0×7: file=0×01, mem=0×00
…about a million more similar errors…

If you said “mike configured his microcontroller as an ATmega16 when he is obviously using an ATmega8″ you are smarter than me.

So yes, at least 1 cause of these errors is specifing the right microcontroller. I edited my Makefile to use atmega8 instead of atmega16 and everything worked like a charm.

Getting clipboard support with ubuntu’s remote desktop

Ubuntu has a handy little feature that lets you log onto a remote system. The bad news: clipboard dosen’t work. Therefore – love to intangible for this howto.

Enabling the internal pull-up resistors on an ATmega8

I was having a problem setting up my atmega8 for user input. My input signal from my button (which was directly connected from my microcontroller to ground) seemed to flucuate after a change. It seems that the problem was that the ATmega8′s internal pull-up resistors weren’t enabled (these resistors cause the input signals to default to 1 when connected to nothing in particular). Figuring out how to enable these pullup resistors took a bit of doing. I found what I needed by looking at this example source code. Turns out you set the pullup resistor to on in avr-gcc by setting the PORTx bits to 1 for your input pins.

Continue reading ‘Enabling the internal pull-up resistors on an ATmega8’ »