Wednesday, March 24, 2010

Flashing OpenLog Firmware in Ubuntu Linux

I recently hit a bug in the Sparkfun OpenLog v1.1 firmware that left the device useless. I found out the hard way that version 1.1 only supports up to 255 log files. Once it hits this limit the firmware doesn't know what to do with itself and loops endlessly. This even prevents you from entering command mode where you could otherwise reset the log number. Nate Seidle at SparkFun quickly released an update, v1.2, to correct this problem I was having. But now I had to figure out how to flash the firmware on my OpenLog. It turns out the process is extremely easy in Ubuntu, but the GitHub documentation targets mostly Windows, so I decided to document the process for Ubuntu users from start to finish here.

I expect that you have the Arduino IDE installed and running properly. This means the avrdude and avr-gcc libraries necessary to flash OpenLog will already be installed. Next step is to pull the firmware source code from the GitHub repository. If you don't have git installed, run the following command:

[code gutter="0"]$ sudo apt-get install git-core[/code]

Now you can run the git command to pull the source code over the read-only HTTP path. This is generally the easiest path to use to avoid issues with proxies or closed/blocked ports on your network.

[code gutter="0"]$ git clone http://github.com/nseidle/OpenLog.git[/code]

Once the command has completed, you'll have an OpenLog directory in your currently active directory. Time to compile the source code to make the required hex file that we'll write to OpenLog.

[code gutter="0"]$ cd OpenLog/Code/[/code]

[code gutter="0"]$ make[/code]

You should see several notices about compiling various .c files, linking main.elf, and most importantly loading main.hex. Now we need to get that hex file onto OpenLog. Grab your trusty FTDI breakout board (you should never leave home without it) and wire it to OpenLog as shown below.



Before connecting the FTDI to your computer, we want to make sure we have the correct device path for the next step. Look at the list of all tty-capable USB devices. It's okay if none show up right now.




[code gutter="0"]$ ls /dev/ttyUSB*[/code]

Now connect the FTDI board and run the command again. The new ttyUSB# device listed is your FTDI board. I'll use ttyUSB0 in the command below, so you will need to change the zero if your # is different.


I hope you have an extra wire at hand. The Linux build of avrdude unfortunately doesn't have the "DTR wiggle" necessary to automatically reset OpenLog's ATMega328p, so we have to do it ourselves. Grab a wire and connect one end to ground. If necessary, the microSD socket's case can be used as a ground if you don't have OpenLog on a breadboard. You'll need to tap the other end of the wire onto the GPIO pin 6 on OpenLog. This is the square pin pad near the "O" in "OpenLog" on the silkscreen (the bottom-left most pin in the image featured above). Timing here is of the essence; run the command below, hit enter on your keyboard, then immediately tap the other end of your grounded wire to pin 6. Don't leave the wire sitting on pin 6, it's just a quick tap to momentarily ground it and force a reset.




[code gutter="0"]$ avrdude -p atmega328p -P /dev/ttyUSB0 -c stk500v1 -b 57600 -U flash:w:main.hex[/code]


Don't forget to change the ttyUSB# number if necessary. If your timing was good enough, you should see avrdude show a progress bar as it flashes the hex firmware onto OpenLog. If not, you'll likely see errors like "programmer not responding" or "out of sync". Try try again. Tapping enter and grounding pin 6 should be almost instantaneous, with the enter key coming ever so slightly first.

After a few seconds, the updated firmware will now be on your OpenLog chip and you'll be on your merry way. I hope this helps someone out there.

9 comments:

  1. Hi, saw your post, may I ask if you know if it's possible to reflash the unit via serial connection only? tnx.

    ReplyDelete
  2. If by serial connection, you mean via an RS232 port on a computer, I can't really say for sure. I do know the FTDI breakout board mentioned in my post creates a virtual serial device on your computer, so the software end should be no different than if you were to use a USB line. RS232 is not the same as UART, however, which is how OpenLog talks (different signal voltage levels) so I'm not sure if a direct RS232OpenLog connection would work. I would either ask on the SparkFun forums, message Nate (the creator) on GitHub, or post in the comments section on SparkFun's OpenLog product page.

    ReplyDelete
  3. I needed to write you the very small observation in order to give thanks yet again for all the lovely tactics you've shown in this case. It was quite incredibly open-handed with you giving unreservedly all that some people would have marketed for an ebook to help make some cash for their own end, certainly seeing that you might well have done it in case you decided. The secrets also served as the easy way to realize that someone else have the identical dream just like mine to grasp much more in respect of this matter. I am certain there are a lot more fun occasions up front for people who looked at your site.

    ReplyDelete
  4. [url=http://www.pradaoutletts.com]Prada Shoes 2012[/url]
    [url=http://www.pradaoutletts.com]Prada[/url]
    [url=http://www.pradaoutletts.com]Prada Shoes[/url]

    new@#7891hello
    Prada Outle|Prada Sunglasses|Prada Bags

    ReplyDelete
  5. I just want to say I am just very new to blogging and site-building and really enjoyed you're blog. Probably I’m want to bookmark your site . You amazingly have awesome articles. Thanks a lot for sharing your web page.

    ReplyDelete
  6. I simply want to mention I am very new to weblog and certainly loved this web site. Likely I’m likely to bookmark your site . You surely come with amazing article content. Cheers for sharing your webpage.

    ReplyDelete
  7. I just want to tell you that I am all new to blogs and really enjoyed you're web site. Very likely I’m going to bookmark your site . You actually come with fantastic stories. Thank you for sharing with us your blog site.

    ReplyDelete
  8. I saw a lot of website but I think this one contains something special in it in it 330032

    ReplyDelete
  9. I simply want to tell you that I am beginner to weblog and honestly loved this web site. Probably I’m likely to bookmark your blog . You actually have awesome posts. Regards for revealing your website page.

    ReplyDelete