LCDBootDrive: Selectable Files!

New toy (o-o-o)

After I showed the BootDrive on the Adafruit Show and Tell, I watched their weekly “Ask an Engineer” show where they showcased a new product, an LCD shield with an RGB backlight. The really cool thing is that the LCD AND 5 buttons only need 2 IO pins on the Arduino, because the shield is designed with an I2C expander. I ordered it the next day (close to 5pm) selected UPS ground shipping and it was at my house the next day!

Here’s a quick video before I go through the blow-by-blow:

[youtube]http://www.youtube.com/watch?v=w5jPm3thkWo[/youtube]

I soldered the micro-sd breakout onto an Adafruit Proto Shield, and a 6 pin right angle header to connect an FTDI cable. Adafruit also had a pre-made 6pin-6pin female cable that was perfect for this project!

I wired it with fine wire-wrap wire on the bottom

The wiring is almost identical to the original BootDrive, except I changed the reset pin assignment:

Digital Pin5  –> FTDI Pin 6 (CTS)
GND                –> FTDI Pin 1 (GND)
Digital Pin1 (RX) –>FTDI Pin 4 (TX)
Digital Pin2 (TX)–>FTDI Pin 5 (RX)

SD Card Interface:
Digital Pin 10 –> SD-breakout CS
Digital Pin 11  –>  SD breakout DI
Digital Pin 12  –> SD breakout DO
Digital Pin 13  –> SD breakout CLK
GND                    –> SD breakout GND
5V                       –> SD breakout 5V

Debugging

I incorporated the directory listing code from the SD library examples, and instead of listing all the files, I did an openNextFile() each time the “down” button was pressed. It would be nice to be able to scroll up and down, but I’m pretty tight on memory as it is, so I didn’t want to cache the directory, or do some kludgy re-reading the whole directory to get to the file we are on.

The first problem I ran into was it worked fine until you scrolled through what turned out to be 25 names (actually the same 3 names 8+ times) and then it started repeating the same name over and over. When I realized it was always 25, I knew it wasn’t some overflow, and I finally figured out the example code had a bug in it! They list the directory by opening each file (with openNextFile() to get the name, but they never close it! If you try the listfiles example with more than 25 files on the card, you’ll see only the first 25. Easy enough to fix, as I’m scrolling I close the file after I get it’s name. I reopen it if you press the “select” or program button.

The next problem was a bit harder. The hex programs seemed to work on some boards but not others, even though there were apparently no errors. I created new test programs and suddenly they didn’t work either. Since the writing to flash seemed to be working, I figured that there must be some corruption of data. I read back the programmed AVR code from the target arduino (with avrdude  <programmer parameters….> -U f:r:readfile.hex:i) and compared it with the file I was sending to be programmed. It turns out I was advancing to the next “line” of 16 bytes even when I read less. Files that ended in shorter lines were getting placed ahead of where they needed to be and so the program was corrupt. Probably on some, the data that was already there was harmless, or the program didn’t actually execute that part of it’s memory, but in some cases it clearly was. Fixed, putback to github!

Have fun and let me know if you try it!

https://github.com/osbock/Baldwisdom/tree/master/LCDBootDrive