Friday, October 17, 2008

Picture of the day


This is a screenshot of a "Robot Lawnmower Simulation" that I assigned as a project in a CS2 course I'm teaching.

Here's the link:
http://faculty.ycp.edu/~dhovemey/fall2008/cs201/assign/assign4.html

Sunday, October 5, 2008

max7219 is working

This past week I was able to get the AVR to talk to a max7219 multiplexed LED driver. One thing that took a while to figure out is that to bring the max7219 out of shutdown mode, you write a 1 to the shutdown register, not a 0. Fortunately, putting the chip in test mode (all LEDs lit) works even in shutdown mode, so I was at least able to verify that the chip worked and it was receiving data. After getting it out of shutdown mode, progress was rapid. (In the process of debugging, I also discovered that the max7219 works best when its ground pins are connected to ground :-)

One nice feature of the max7219 is that it supports undecoded output, meaning that you're not limited to decimal, hex, or code-B when using 7-segment displays. Some weird people out there have come up with 7 segment text fonts, which (surprisingly) aren't totally unreadable.

Aside from adding some buttons for user input, pretty much all of the technical details of my top-secret AVR project have been ironed out. (I still have to finish writing the code, but that should be the easy part.)

One interesting wrinkle is that the max7219 doesn't precisely support SPI, but a protocol very much like it. So, I actually have two SPI busses, one for the ds1305, and one for the max7219. (I should have ordered the max7221, which is fully SPI-compatible.) No big deal, since the atmega48/88/168 chips have a lot of I/O pins. (I'm currently using the '48, since it's cheapest.)

Thursday, September 25, 2008

SPI success!

I've had no luck getting the atmega168 to talk to a DS1307 RTC chip over i2c. My colleague Greg suggested using an RTC which uses SPI. After getting my hands on a couple DS1305s, I wired it up, and wrote some code to bit-bang SPI using several pins on port C. (I didn't use the hardware SPI support because those pins are used for in-system programming.) I tried it out, and---nothing. Every register read would return 0, which seemed a bit odd.

Eventually, I replaced the DS1305 with some LEDs, and wired the atmega168 pin I was using for input from the DS1305 to +5V, and noticed that even though the LEDs were blinking correctly (I slowed the SPI protocol way down), I was still getting 0 when I did the read.

Long story short, AVRs have different registers for reading and writing ports. For example, PORTC means "write to port C", while PINC means "read from port C". I, of course, was trying to read from the output register. Fixed the code, and presto, my test program worked. All it does is repeatedly writes an incrementing counter to one of the DS1305 RAM addresses, and reads it back.

The obligatory picture:


The DS1305 is the chip just to the right of the atmega168.

Next step: use a MAX7219 to drive the 7-segment displays.

Thoughts on the bailout of the financial industry

Spending $700 billion to bail out the financial industry is about $2300 per US citizen.

So, the US government wants to spend $2300 of my money (probably more) to clean up the financial mess left by greedy and stupid people. We're letting the people who knowingly arranged and sold bad mortgages off the hook. We're also (presumably) letting the people who knowingly walked into mortgages they couldn't afford off the hook.

I now feel really stupid for working an honest job and living within my means. Our government seems to be largely in the business of making sure that the unscrupulous prosper.

Friday, September 12, 2008

ATMega168, i2c/twi

I changed by AVR circuit to use an atmega168 rather than the attiny2313. The primary reason is that I'm trying to use the i2c code from the Procyon AVRLib in order to talk to a DS1307 real time clock, and avr-libc doesn't seem to have the required register definitions for the attiny2313. I don't know why - the attiny2313 is supposed to support hardware TWI (really i2c).

Here's a snapshot of the new circuit, taken again with the world's worst digital camera:


My program successfully loads and runs on the atmega168. Next step: actually try to talk to the DS1307.

Tuesday, September 9, 2008

Powered by Ubuntu sticker

When I got my new Thinkpad X61 tablet, I (naturally) removed the "Designed for Vista" sticker and threw it away. That got me wondering whether anyone has made a "Designed for Linux" sticker. And of course, the answer is yes, and they're free:
http://system76.com/article_info.php?articles_id=9
Double w00t!

The sticker actually says "Powered by Ubuntu", but that's good enough for me.

Getting Eclipse to work on 64-bit Linux

Back at the beginning of the summer, I was experiencing strange Eclipse crashes after an upgrade to 64-bit Ubuntu. My solution at the time was to switch over to Netbeans, which worked out very nicely.

Since students here at YCP are using Eclipse for Java development, I thought I'd take another stab at getting things working.

As it turns out, there is an easy solution: use the IBM JDK. Instructions are in a comment in the following blog post:
http://dmartin.org/weblog/eclipse-on-ubuntu-linux-for-amd64
Basically, you grab the RPM for the IBM JDK, use alien to install it, then use the -vm Eclipse switch to launch it using the IBM JVM.

W00t!

Since the problem seems to be in the Sun JVM, and not Eclipse, I have to wonder why Sun has let this bug linger for such a long time.