Valentines Day Card 2010
16 Feb 2010
Every year, I make Sheena a Valentines card. A few years ago I didn't have a
chance to go to the local card shop, and made one from art supplies I had on
hand. Now I'm doomed -- I can't go back to buying cards.
This year I decided to raise my game a little, or at least incorporate another
hobby. As I mentioned earlier, this is a
blinky sign. It has an 8x8 LED matrix and an Atmel ATmega48 on board, as well
as a CR2032 watch battery. The ATmega uses its internal oscillator, so there
is very little supporting circuitry. It doesn't sound exciting on it's own,
but context is everything.
The local art store had cards and
envelopes in different sizes. I picked a much larger envelope as the assembled
card is rather thick. The hearts are cut from red craft foam, and hot glued on
to the card and envelope.
The circuit board is bolted to an acrylic backplate. The card and a black piece of craft foam are sandwiched in place. This will hopefully prevent the circuit board from tearing through the card.
The software has about 25 different messages, and it steps through them each time the button is pressed. Then it puts itself into power down mode until the next button press. Updating the matrix is handled by an interrupt routine that reads from a circular buffer. There's also a putchar routine that feeds into the buffer, so I can use it with I/O streams. This lets me use
The circuit board is bolted to an acrylic backplate. The card and a black piece of craft foam are sandwiched in place. This will hopefully prevent the circuit board from tearing through the card.
The software has about 25 different messages, and it steps through them each time the button is pressed. Then it puts itself into power down mode until the next button press. Updating the matrix is handled by an interrupt routine that reads from a circular buffer. There's also a putchar routine that feeds into the buffer, so I can use it with I/O streams. This lets me use printf to write to the matrix.
And the font: The only 8-bit font with a heart character I know of is the Commodore 64 system font. I created ROM dumps from a C-64 quite some time ago, including the character generator. The C-64 was a strange machine by modern standards. Not only did the internal character representation differ from ASCII -- the Commodore version was called PETSCII -- but the font in the character generation and the stored screen state both used yet another representation known as screen code. I've modified the font into something more like ASCII, with the heart character as 0x7f. Please don't hurt me, Commodore!
The final code, with the font in program memory, comes to 4004 bytes, just fitting inside the 4096 bytes available. The font takes up 768 bytes of flash, and the avr-libc printf implementation takes up another 1.5k or so.
There are more pictures in this flickr gallery.
The code is posted on GitHub.
Lessons Learned
- AVR microcontrollers have some mad power management capabilities. While running, this card consumes around 20 millamps. While sleeping, it consumes ~1 microamp.
- When wiring up an LED matrix, think about which end should be the most significant bit. I wired up this project to be little-endian (MSB at the right), while the font I used was big-endian (MSB at the left). This was easy enough to fix in software.
- Additionally, I'm reaching the point where point-to-point prototyping may no longer be feasible. I guess I have to break down and learn some real circuit layout software.
- I should probably plan ahead more -- It'll be tough to top this next year.
Little Robots -- Firmware
11 Feb 2010
This is part two of a series. Part one covered the hardware build. Part three will cover the python based host software.
Without any further ado:
Firmware
This entire project was based around Objective Development's V-USB product -- an open source software USB implementation. Among the AVR community, it seems to be reasonably well used, and has a nice selection of reference projects. From the outset, I knew one robot -- the one for my desk -- would be talking to a linux or macintosh computer. However, my fiancé's robot would have be happy in windows. Unfortunately, windows devices require kernel device drivers, with a very few exceptions; the most abused being the Human Interface Device profile. So why buck a trend? HID it is. With that in mind, two existing projects seem most useful.- 1-Key Keyboard -- the original hardware base for the little robots -- is naturally firmware compatible. In fact the belly switch of each robot does indeed work as a keyboard switch. This is a full bidirectional HID device.
- The HID-Data example included in the V-USB distribution. This is a much simpler application -- it allows a host application to set and read the EEPROM storage in an AVR. It is unidirectional -- all interaction is initiated by the host controller.
Servo Control
Servos are controlled via pulse width modulation. Many microcontrollers do have hardware PWM support, and the ATtiny85 is no exception. However, all of its timers have an 8-bit resolution. For my purposes, this is acceptable, but provides only about 25 steps from one end of the servo's range to the other. This works out to be about seven degrees a step. Better resolution would require a software timer. I find with the small servos I have handy, the low end of the servo's sweep comes in at around 11, and the high end anywhere from 35 to 40.
void pwm_set( int x ) {
OCR0B = x;
}
void pwm_init( void ) {
// Set non-inverting output mode on pin OC0B.
TCCR0A = ( 1 << COM0B1 ) | ( 0 << COM0B0 );
// Set fast pwm mode.
TCCR0A |= ( 1 << WGM01 ) | ( 1 << WGM00 );
TCCR0B = ( 0 << WGM02 );
// Use /1024 Prescaler.
// This sets a PWM frequency of ~48Hz,
// which is just about perfect for a servo.
TCCR0B |= ( 1 << CS02 ) | ( 0 << CS01 ) | ( 1 << CS00 );
}
Lessons Learned
- Include a programming header on a development board. For every firmware revision I had to pop the AVR out, reprogram it, and reinstall it. As simple as the process is, it gets old real quick.
- Chip self-protection features are your friend. For example, under-voltage detection and hardware watchdog timers are very useful. When a computer -- especially a laptop -- reboots, it may brown out devices on the USB bus. A microcontroller may come back up in an undefined state. One of the robots burnt out a servo when it flaked out on a reboot.
- Embedded software is actually fun to write! It's simple, clean and very scope limited. Perfect for a satisfying hobby project.
This Weekend's Project.
08 Feb 2010
I was inspired last night, so I made this little gizmo. It's a blinky sign, about the size of a 3x5 index card. It's destined for a specific purpose, so check back in a couple weeks for the reveal.
DemoCamp Guelph Success!
04 Feb 2010
Last week I presented my little robots at DemoCamp Guelph. And to my surprise, I took home the much coveted Crowie award for best presentation.
There's a USB stick on the back with the names of previous winners. I added myself to the list, then I held the Crowie aloft and said:
There's a USB stick on the back with the names of previous winners. I added myself to the list, then I held the Crowie aloft and said:
By the power of Greyskull!And nothing happened. So it must be broken. Here's what's inside: I clearly need to add more magic. I've got a few ideas in mind -- I'll post more as they come to fruition. In other news, I upgraded the firmware on the little robots. They're now safely back on our respective desks, and keep my fiancé and I in touch all day.



