Tuesday, April 26, 2011

Learning Shift Registers (Latches)

If you need to minimize the use of the pins of your IC, you need to use additional controllers that help out in specific situations.
The 74HC595N is a Shift Register, also known as latch, and it can provide 8 different outputs needing only 3 input pins (it is also possible to daisy chain several Shift Registers to increase the number of outputs). This is done by converting serial inputs for parallel outputs.

Basically you need to fill up a buffer to release all the outputs at the same time.

This CodeProject article is very straightforward in teaching how to use it and you'll be able to do it in minutes.

Here's the final result running 'Example 2 - Single Shift Register - LED Sweep':

This is a basic usage of the 74HC595N Shift Register, and there are a number of possible situations that this could come in handy.

P.S. Only later have I realized that I forgot to connect the Vcc and GND pins of the Shift Register to the Arduino. Even still some dim lights emanate from the LEDs :P

Monday, April 25, 2011

Arduino Standalone

After setting a Arduino on a Breadboard I also needed to be able to make work without a computer or an Arduino Board to provide power.

The ATMega needs a 5V power source, and I want to be able to power it on any regular wall wart. How can this be done?

Small electronics need some kind of rectifier to take the Alternate Current (AC) you get in your house outlets (220V in most of europe) to something as small as 5-12V of Direct current (DC) (if you want to know more about AC and DC you can read the 'War of Currents' article on Wikipedia).

To be able to ensure a smooth 5V DC to the circuit, I used a 7805 rectifier. In order to use it correctly you need a diode and two capacitors. Here's the schematic I used.

This rectifier has an input limit of 40V DC (but it is recommended to use from 7 to 12V), so we still need an AC-DC adapter capable of providing the recommended input to the 7805.

To test it all, I connected a LED to the Arduino running a Blink example:

Sunday, April 17, 2011


In order to use the Arduino IC on a real board, we need to learn how to use it.
There's a common type of Arduino configuration for this called Breaduino (derived for Arduino on a Breadboard).

What I want to use is the minimal configuration, in order to avoid buying an external crystal oscillator, knowing that it is possible to use the IC's internal oscillator.

These oscillators are what sets the pace for a circuit. The faster the oscillator can go, the faster can the IC make calculations.

My Arduino is a Duemilanove an has an ATMega328p IC. In the datasheet it is stated that we can use an external oscillator up to 20 MHz (for Arduino we should use one at 16 MHz). The internal oscillator runs at 8 Mhz, but these frequencies can be divided by 8 using configuration (I'll write more about it in the end).

Once again the Arduino site has very good references and tutorials:
- Arduino To Breadboard
- Standalone
- Disabling Auto Reset (You'll need this one, even not being mentioned on the above tutorials)

If you look for the 'Minimal Circuit (Eliminating the External Clock)' sections you'll find an illustrated guide on how to configure the Arduino IDE and to connect the IC to the breadboard for both burning the bootloader and programming the IC.

After reading all of these and much more, I still couldn't burn a bootloader for using the internal oscillator on the ATMega328. Because of that I read and learned about understanding the configurations of the IDE, programming the ATMega by command line using AVRdude, and setting the fuses (configuration of the IC) in order to configure its behavior.

So why couldn't I burn the bootloader using the Minimal Circuit?
All my ATMega came preloaded with the regular Arduino Bootloader for use with the Arduino Board. That way they are configured to work with an external 16 MHz crystal.
So, because of that, the ATMega that I was trying to burn a bootloader into wasn't working. It needed the external crystal as configured for me to be able to burn a different bootloader.

Some of the errors I've seen because of this (both on Arduino IDE and running avrdude by command line):
- avrdude: Yikes! Invalid device signature;
- avrdude: Device signature = 0x00000000;
- avrdude: Expected signature for ATMEGA328P is 1E 95 0F;
- avrdude: stk500_getsync(): not in sync: resp=0x00;
- avrdude: stk500_getsync(): not in sync: resp=0x15;

Well, I had to buy a 16 MHz crystal after all.

To sum it up, what I had to do was:
1) In the \hardware\arduino\boards.txt add the breadboard settings below

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)



Note that these settings are not the same as downloaded with breadboard.zip from the Arduino site;

2) On Arduino IDE, load the ArduinoISP sketch of the Examples tab to the Arduino Board;

3) Set the hardware as in the images on the ArduinoToBreadboard tutorial (with the external crystal). Also you will need to disable the Auto-Reset feature if your board has it (and Duemilanove does have it);

4) (Optional) I read the comments on the ArduinoISP sketch and it talks about some pins you can use to light up some status LEDs. I used them to help me understand what was happening;

5) Upload the ArduinoISP sketch (confirm that you have the correct board configured in the IDE - in my case 'Arduino Duemilanove or Nano w/ ATMega328');

6) Make sure once again that all hardware is well connected.

7) Select the ATMega328 on a breadboard (8MHz internal clock) and burn the bootloader 'w/ Arduino as ISP'. It will take a while.

8) Now that the bootloader is set, you can upload a sketch. Don't forget to remove the ATMega from the Arduino Board, so that the ATMega on the breadboard is the one used. Also, don't forget to connect only the VCC, GND, RX and TX pins (one of my mistakes was to leave the crystal connected and because of that I couldn't upload sketches);

A tip about setting extended_fuses (efuse):
This fuse controls the brown out detector and it can influence the correct working of the controller if you use less than 5V to power it.
There are only 4 possible values for this fuse so the controller  might only read those 2 bits in the full 2 bytes reserved for the fuse.
If you can't burn a bootloader because the efuse doesn't match the expected efuse (like 0xFF != 0x07) it means that that kind of controller expects that bits 2 to 7 are the opposite of what you set (remember that they won't be really needed), so you might need to adjust the value for the fuse accordingly.

So here are the values you need with bits 2 to 7 ON and OFF:
OFF(1)       ON(0)       Meaning
0xFF   <->   0x07    =   Brown-out detection disabled
0xFE   <->   0x06    =   Brown-out detection at VCC=1.8V
0xFD   <->   0x05    =   Brown-out detection at VCC=2.7V (Arduino 5V default)
0xFC   <->   0x04    =   Brown-out detection at VCC=4.3V

Thursday, April 14, 2011

How a LCD monitor works!

Here is a fantastic video of how a LCD Monitor works:
LCD Monitor

Saturday, April 2, 2011

New Project. BIG!

I have a new ambitious project in hands.
It involves much more that what I know now, but I'm confident that I'll be able to accomplish it!

I will use shift registers, RGB LEDs, Arduino on breadboard, 7 segment displays, etc.
And of course, all I learn will be posted here.

First step is to learn how to use the ATMega328 (Arduino IC) on a breadboard, so that I can use it on a board for the final 'product'.