May 21st, 2008

My first AVR code

This is my first AVR project. After going trough the tutorial i was telling you about a couple of days ago and after testing the “Blinky” project i decided to make my own Blinky. So i came up with this idea that the led’s should start lighting from the middle and move to the sides, when they reach the sides blink a couple of times and come back to the center.

I was actually quite easy to do it, i expected to be harder. I used the 8 LED board i designed in the avr butterfly starting guide.

Here is the LED’s in action:

You need to a flashplayer enabled browser to view this YouTube video

Here is a zip archive containing both the source and the compiled hex. The code was written and compiled in AVR studio.

AVR Butterfly is an evaluation tool demonstrating the capabilities of the latest AVR Technology. The tool is shipped with preloaded firmware supporting temperature sensing, light measurement, voltage readings and music playback. The AVR Butterfly is controlled by an ATmega169.

It’s basically the cheapest development board on the market, $21.28 as we’re speaking at Digikey. I choose to start with the AVR Butterfly because it is also featured in all examples in the tutorial I’m reading. The tutorial is easy to follow and i recommend it if you want to start programming AVR’s in C language. You can find it at SmileyMicros.

The tutorial contains all you need to now, but some things are not entirely covered, and other things present incompatibility issues.

When ordering the Butterfly its also a good idea to order some pin headers because they are not included. When you take the Butterfly out of the box it should look like this:


Now it would be nicer if they would of included those pin headers in the package. And here is my Butterfly after i soldered the pin headers.


Another thing that i noticed about this step, is that my Butterfly doesn’t have the LDR, it seems that this version only comes with the NTC soldered on the back, which is also an analog sensor and it should be enough for developing code with analog sensors.

The next important thing that you need to solder is the RS232 cable, because the communication between the computer and the Butterfly is done via RS232.

Hers is a picture of my cable, and how it should be done. (disregard the connector i used, its taken from an old computer case, that’s why its saying turbo sw).


Notice how the RXD and TXD from Butterfly are reversed on the RS232 connector ? That’s because what you transmit here has to be received there. Pay attention on soldering this connector, you will avoid future headaches. But what if you don’t have an RS232 connector on your computer ? the answer is simple you buy a RS232 to USB converter cable, like i did:


I could of done myself the cable using the schematic from this article, but the parts cost more than a commercial cable, not to mention the hours you put in fabricating.

Now about the battery, the onboard CR2450 isn’t gonna last too long with the projects that you’re gonna work with. So its best to build an external power supply. I build mine with 2 x AA-R6 battery holder.

2xaa-battery-external-power-supply-for-avr-butterfly avr-butterfly-with-pin-headers-soldered-and-power avr-butterfly-with-external-power-connected

From this step on, you can approach things two ways, either use a breadboard or fabricate PCB’s. I don’t have a breadboard so i had to make pcb’s. Basically its just a board with 8 LED’s, 8 current limiting resistors and some headers for linking it to the Butterfly.

here is the Eagle schematic and board file.

details on how to fabricate the PCB are covered in my DIY PCB Tutorial.

Here are a couple of pictures with the board after being etched and after being assembled. The 8 LED board is going to be used with the Blinky Project.

boards-after-beeing-etched 8-led-board-after-beeing-assembled

I also did two small PCB’s for driving an RGB LED, one for a CA version and one for CC version.(Common Anode and Common Cathode). I will use this boards later when i will be experimenting with PWM control.

Here are the RGB LED boards assembled.


And to end this article here is a picture with the USB to RS232 cable connected to the AVR. Now all i have to do is read and learn the next 300 pages from the tutorial.


Now i started working on a lab power supply, i could of just buy one but its more fun to build it. Here is a picture where i just started the assembly. The project should be up soon at my personal projects page.

© 2007-2011 YourITronics | Any logo, trademark and project represented here are property of their respective owners | Wordpress | Privacy Policy    RSS