This all started last year, when I was playing with an ATmega168 microcontroller and did something silly. I programmed the RSTDISBL fuse bit, which effectively makes it impossible to reflash the chip using an ordinary (serial) programmer.
Instead of giving up and throwing out the “dead” chip, I decided to try to revive it using an obscure high voltage parallel programming mode that isn’t supported by most AVR programmers. Armed with my Arduino and the ATmega168 datasheet, I quickly designed and constructed a programmer using parts I already had on my workbench.
A few hours later, I tested my new programmer and it worked! I revived my “dead” AVR by using spare parts and a few lines of Arduino code. That week I published the schematics and Arduino sketch to the site and called it my Arduino-based AVR High Voltage Programmer.
The response was overwhelming. Since I first posted the design, many people have built their own and used it to fix their “dead” AVR microcontrollers by restoring the fuse bits to sane values. I even received several requests for a PCB and/or kit based on the design, which got me thinking…
Today I’m proud to introduce:
The AVR HV Rescue Shield
The AVR HV Rescue Shield is a high voltage parallel mode fuse programmer for Atmel AVR microcontrollers.
It currently supports the ATmega48/88/168/328 series and the ATtiny2313. The Rescue Shield does everything my original AVR High Voltage Programmer does, and a lot more. I think the new features make this a really useful tool for anyone working with AVR microcontrollers.
New features include:
Custom 2-layer PCB with silkscreen and soldermask. No more hacking and modifying perfboards to fit Arduino’s nonstandard pin spacing!
Onboard 12V DC-DC boost converter eliminates the need for an external 12V power supply
Support for two of the most common families of AVR microcontrollers, the ATmega48/88/168 and ATtiny2313
Support for programming the extended fuse (EFUSE) byte.
A new interactive mode, where desired fuses can be entered using the Arduino’s serial port.
Separate Ready and Burn indicators
Protection resistors on every single data, control, and supply line to the target AVR, meaning that your Arduino and AVR should survive any mishaps during programming, including inserting the AVR backwards or off by 1 pin.
I spent considerable time testing each new feature and documenting the Arduino sketch. I hope that you’ll find that the finished product was worth the wait!
Big news – the AVR HV Rescue Shield PCBs arrived yesterday! I’m currently testing them and will post information about kits for sale as soon as I verify that everything is working properly.
This is actually the second spin of the PCB but the first to bear the ‘Rescue Shield’ name. The first spin was a one-off prototype to check a couple things out, mostly related to the 5V to 12V step up converter. That design allowed me to fix a couple bugs before doing a production run with the improved design, show below.
So far all I can say is that the step up converter works perfectly. (Yipee!)
When I started blogging in July of last year I wasn’t sure what I would post about or where all of this would go. Eight months later, the blog has exceeded my expectations in many (and many unexpected) ways. The major driving force behind this blog has always been my desire to share my projects and my passion for electronics with the world, in addition to (hopefully) inspiring some other people to do cool things with electronics as well.
My favorite post? Definitely the Arduino-based AVR High Voltage Programmer. I never expected such a simple circuit to help so many people. There has been so much ongoing interest in this project that I am putting together an Arduino shield kit based on the original design. The kit features a slick double-sided PCB and an integrated 5 to 12V step up converter so you don’t need an external 12V supply to use the programmer. More details very soon!
Tony’s Wifi Radio Sketchup Model
Tony created this awesome Google Sketchup model of an enclosure for my Wifi Radio project. After I made a very crude first draft, Tony took my design and turned it into something that is sort of modern, sort of retro. Perfect!
In other news, there is a Dorkbot SF meeting tonight at Parisoma at 7:30PM. Arrive early to get a seat! Details at dorkbot-sf.
Hal created a neat project by taking parts of my Wifi Radio project and repurposing them to do something completely different. His Standalone Weather Station changes the color of an LED based on the weather forecast for tomorrow. If temperatures are trending warmer, the color changes towards red. Colder – blue.
His project is very well documented and includes code for both the ATmega168-based circuit that drives the LED using PWM and the shell script on the router that communicates with Weather Underground to get the forecast.
This is the eighth part of an ongoing series about building a low cost, open source streaming internet radio based on the ASUS WL-520gU Wireless Router. If you haven’t already, check out the previous parts (see the links at the end of this article) for some background about the project.
In part seven, we added an LCD status display for the radio that shows the stream name as well as the artist and title of the current track. In this part, we’ll add a tuning knob that lets us change stations without using a computer.
It turns out that this is mostly a software exercise, made simple by taking advantage of the analog to digital converter function of the Atmel ATmega168 AVR that is controlling the LCD display. The addition of the tuner control turns the display circuit into a very simple user interface. Turn the knob and the station changes. The position of the knob determines what station the radio is “tuned” to, and when combined with a calibrated scale it will make it easy to change to any one of the several streaming radio stations stored as presets (favorites?) in the router.
To give you an idea of how this works, here is a demo of the tuner control changing between ten preset stations I have set on the router. The tuner control is in the upper right hand corner of the breadboard. As I adjust the control, the music changes and LCD display updates to show the name of each new station.
Is that cool or what?
If you are interested in adding this functionality to the radio, keep reading and I’ll show you how.
Changes to the hardware:
You will need:
The completed AVR-based LCD display from part seven
A 1k-10k trimmer or potentiometer, linear taper
Some hookup wire
Here is an updated schematic of the AVR circuit showing the potentiometer connected to ADC4 (pin 27).
The AVR firmware has been significantly expanded, slightly reworked and cleaned up in some areas.
The most important changes are:
The addition of a serial transmit function so the AVR can talk to the router (based on the uart_putchar function)
New code supporting the analog to digital converter (ADC) which reads the value of a potentiometer connected to ADC4.
A new Timer1 overflow interrupt has been added, which occurs roughly every 0.5 seconds. The interrupt service routine (ISR) checks the position of the tuner control, and if it has changed, sends the value to the router. The ISR is towards the top of the file, see the SIGNAL (TIMER1_OVF_vect) section.
The ADC range of the ATmega is 0 – 1024 for an input voltage from 0 to 5V. The AVR sends serial data in the format “Tuner: Value” back to the router when the tuner position changes by more than ADC_SENS counts (default is 5). The AVR waits for an “AVR Start!” command from the router before sending any data, this avoids filling up the serial receive buffer on the router before it’s ready to start processing data. An important consequence of this is that the AVR must be reset before running the control script on the router.
You can download the source code and compiled .hex file here. Flash it to the AVR using any compatible ISP programmer and you should be good to go. The source is commented fairly well so if you’re interested in learning how the interface works, take a look. You will need a copy of the ATmega168 datasheet to understand the register names and other architecture-specific parts of the code. Feel free to post in the comments with any questions.
Modifying the circuit:
This part is pretty simple – just wire the potentiometer as shown in the schematic. Most potentiometers have three terminals. The left terminal goes to ground, the right one to +5V, and the middle terminal to ADC4 on the AVR (pin 27).
Tweaks to the OpenWrt configuration:
To make bidirectional communication with the AVR work, we have to change a couple config files on the router and disable some services that would otherwise get in the way.
The first change is to modify the /etc/config/network file so that we can always telnet or ssh into the router on a LAN port using the IP 192.168.1.1. The ability to access the router via ethernet is helpful in case we screw something up and lose the wireless connection or the router loses it’s IP address, etc.
Modify the LAN section of /etc/config/network to look like this (changes in bold):
#### LAN configuration
config interface lan
#option type bridge
option ifname "eth0.0"
option proto static
option ipaddr 192.168.1.1
option netmask 255.255.255.0
Save changes, restart the router, and connect an ethernet crossover cable (straight cable might work on some computers) to the router. Configure your desktop/laptop computer with a static IP, like 192.168.1.185. Try to open a telnet connection (or ssh if you have set a password on the router) and see if you can log in. If not, don’t continue with the next steps until you can get this working.
We previously used the router’s serial port to get a login shell. Now that we’re trying to receive data from the AVR on the same serial port, we need to disable the login shell or it will capture the data before we can get to it.
Edit /etc/inittab to look like this (changes in bold):
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K stop
Sysrq is a fascinating and very low level debugging feature of the Linux kernel. It can be used to perform troubleshooting operations and reboot the system. Usually it is invoked with a magic key combination on a desktop computer, but in this case I found that it is easy to accidentally trip over the serial port when using an AVR. (The “break” RS-232 code triggers Sysrq, this probably has something to do with it.)
Fortunately, it’s easy to disable by editing the /etc/sysctl.conf file and adding these lines:
# Disables the magic SysRq key
kernel.sysrq = 0
Reboot the router to apply the changes. Now we can get on with the good stuff!
Shell scripting magic:
The real action happens on the router, where a shell script waits for input from the router and changes the station accordingly.
This script is called interface.sh and can be downloaded to the router using wget as shown:
Once both scripts are downloaded, executable and located in /root you can launch interface.sh as follows:
volume: 60% repeat: on random: off
volume: 60% repeat: on random: off
… more stations here …
Tuner Position: 0
[playing] #1/10 0:00/0:00 (100%)
volume: 60% repeat: on random: off
The interface script adds ten presets to the router, shows the playlist, and then waits for valid tuner data from the AVR. Once it receives a “Tuner: value” line (which should occur shortly after the AVR receives a go signal from the script), the script prints the received tuner positon and changes to the requested station. It will then wait for new tuner data from the AVR and change the station when necessary.
As you can see in the video, this works very well. Over a fast Wi-Fi connection, the time to change stations is almost instantaneous – very satisfying!
That’s it for part eight. In part nine, I’ll add some finishing touches to the router configuration and start talking about enclosures. Stay tuned!
Update: There is a new Wifi Radio Discussion Forum, hop over there to ask questions about the project or see what other people are working on! (4/12/09)