How to drive 595 shift registers with AVR hardware SPI

A pair of shift registers connected with jumper wires on a breadboard

Driving a shift register using an AVR chip’s built-in hardware is really quite easy. Most of their offerings have an SPI module, or Serial Peripheral Interface. A shift register is exactly that, a peripheral device that communicates via a serial line. All we need to do is hook up our connections and use a few pieces of simple code. Join me after the break to see how that’s done.

Just want to know how shift registers work? Check in on my other post on that topic.

Continue reading

Developing a Larson Scanner

I’ve been hard at working coding my own Larson Scanner. This is the iconic sweeping light seen in the Cylons on Battlestar Gallactica or on the front of KITT, the car from Knight Rider.

As I discussed in my previous post, the thing that makes these look neat is the fading tail that chases the brightest light. Originally that was accomplished with capacitors which caused the light to fade as they discharged. I implemented the same concept, using a microcontroller and pulse-width modulation to manage the fading.

After the break I’ll go through the development process and share the code. I did this using an AVR microcontroller but you can use any chip you want. The gist of my process is this:

  1. Develop software (interrupt) based pulse-width modulation
  2. Write a function to monitor PWM values and automatically subtract from those over time to cause automatic fading.
  3. Use a buffer to track which LED is ‘active’ and do not fade that one. As soon as that buffer is shifted the old ‘active’ diode will start to fade.
Simple, right? Here’s a video overview to convince you:


And of course you’ll want to look at the most recent code.

Continue reading

Larson Scanner project introduction

Okay, it’s time to make a realistic Larson Scanner. You may know it as a Cylon Eye from Battlestar Gallactica or the lights on the front of KITT, the car in Knight Rider. It’s a popular project because it looks cool, but I’ve seen (and built) a ton of lousy imitations. What makes the original so interesting is that the bright tracking light leaves a fading tale behind it. That’s a bit more work to implement, but I’m up for the challenge. Update: check out the complete project.

After the break I embedded a video of the Larson Scanner from Knight Rider. You can pause it to get an idea of what’s going on here. The brightest light is always on the leading edge, the rest fade with time.

So my implementation will happen in a couple of stages:

  • Write some code to drive a PWM signal on the pins of an AVR microcontroller
  • Write some code to automatically fade an LED once the focus has left it
  • Write some code to change where the focus is on a row of LEDs
This is just an introduction so check back soon! Continue reading

AVR Development using Eclipse

I’ve just today set up and started using Eclipse as an IDE for AVR development. I got here in a rather roundabout way. My current project is a tetris-like game played on a 3595 lcd screen. I’m having a bit of trouble with the scalability of the playing area and needed to do some debugging. I installed avarice and avr-gdb and did a bit of debug-wire work with those for the first time, but I wanted a way to tie everything together. It seems that eclipse will allow me to code, build, program, debug code, and hardware debug all in one. First thing is first though, I needed to get eclipse installed and running.

Trial and Error
I use Ubuntu 8.10 Intrepid Ibex and Eclipse is in the repositories, yay!! An hour and a half of downloads later I can’t get the AVR-eclipse plugin to work. Great.

Well, come to find out that Ubuntu has Eclipse version 3.2.2 in the repository and the AVR plugin needs a minimum of 3.3 installed. Fortunately eclipse comes as a java package, requiring no compiling. In fact, I don’t think you even need administrative privileges to install it.

Go download the Eclipse IDE for C/C++ developers here:
http://www.eclipse.org/downloads/

Unpack it, I just put the eclipse folder from the tar package in my home directory. To run it just go into that directory and type:
./eclipse

We will need to AVR plugin for eclipse. To install it go to Help –> Software Updates. Click the available software tab, click add site and put in this url:
http://avr-eclipse.sourceforge.net/updatesite/
In the window to the left expand the tree next to the url you just entered. Check the box next to AVR Eclipse Plugin and click Install to the right.

The plugin will download and install and then you will be prompted to restart eclipse, do so. Once you are back in use the AVR plugin help file to get things going. Find this by going to Help –> Help Contents –> AVR Plugin –> Getting Started.

Following that guide for about 5 minutes I was able to code, build, and program an app that flashed 6 leds in sequence on my development board (Dragon Rider 500) using a mega168 (what I already had sitting in the board. I’m asking my self why I didn’t start using this method much sooner.

There is a pretty good wiki regarding this AVR plugin:
http://avr-eclipse.sourceforge.net/wiki/index.php/The_AVR_Eclipse_Plugin

I’m going to look into on-chip debugging using eclipse along with avarice and avr-gdb. Check back for more on that.