Arduino On a Beadboard - Uploading Your Sketches

Wednesday, February 22, 2012

A few days ago I posted some intructions on how to use a standalone Atmega328 (or Atmega168) on a breadboard. This approach offer a good cost reduction for Arduino-based hobby projects by reusing the USB-to-TTL circuit between the projects. The cost saving can be close to $20, but there is a small tradeoff in convenience. Instead of the customary "plug in the USB cable and click 'Upload' ", we will need to hook-up a few wires; nothing too bad, though. Let's look at two different approaches: using FTDI adapter and an existing Arduino board.

There is no inherent benefit to either. If you already have an Arduino board with a removable chip (Arduino UNO, Duemilanove etc.), it makes sense to use it. Otherwise, $17 + shipping from Sparkfun ins't a bad deal.

Unless you already own a USB to serial adapter, I'd encourage you to stick with Sparkfun's FTDI cable or FTDI Basic board (either one works fine, so this is just a matter of preference). First of all, they are designed for Arduino Pro header pinout, so programming those (if you decide to get one in future) is as simple as plug-and-go. Additionally, they have auto-reset capability via DTR cable (most cheap USB-to-Serial adapters I've seen don't have this capability)

Using Arduino as USB-to-TTL Adapter

Arduino uno used to upload code
to Atmega328

To start with, you need to remove the Atmega chip from Arduino's socket and create the basic Arduino circuit, as described in the last post. The proper way to do so it to use an IC puller, but with care you can do as good of a job with a flat screwdriver or tweezers. The key is to pull the chip straight out, without beding the leads. Once the chip is out of the socket, try to stabilize the board on or near your breadboard (I use a small piece of "gray" 3M double-sided tape to attach it to the breadboard). This prevents the board from flopping around (and releasing the magic smoke as a result of an accidental short).

There are four or five connections you will need to make:

  • Arduino Pin 0 (Rx) to IC pin #2 
  • Arduino Pint 1 (Tx) to IC pin #3
  • Arduino Reset to IC pin #1
  • Arduino Ground to breadboards ground rail
  • Arduino 5V (Vcc) to breadboard Vcc rail (if you want to power the breadboard from the Arduino board)
To upload the sketch, you simply plug in the board into the USB port, select the correct target from the "Board" menu and watch the magic happen. Keep in mind that you choose the target based on the bootloader burned into the chip, not the board you are using to upload the code.

Using FTDI Adapter

FTDI Basic (from Sparkfun) connected to Atmega328
This example uses the same breadboard circuit as previous one with one minor difference: the "reset" line is connected to the reset pin of the chip through a 0.1uF ceramic capacitor. I missed this detail the first time I tried the FTDI Basic board and spent 2 hours pulling my hair out. Other than that, the drill is the same. First you make the following connections:
  • FTDI Tx to IC pin #2 (Tx to Rx)
  • FTDI Rx to IC pin #3 (Rx to Tx)
  • FTDI DTR to IC pin 1 (via .1 uF cap)
  • FTDI Gnd to breadboard ground rail
  • FTDI 5V to breadboard Vcc rail (if you choose to temporary power the board)

The upload procedure is the same as with Arduino. The only caveat I'd add he is that shorting out 5V on the FTDI board can fry your USB port (most computers allegedly have protection, thoug)

6 comments :

  1. Yuriy, Thanks for this posting. I missed that cap between DTR and IC pin 1 as well but had no idea I needed it. Cheers great post and site.

    ReplyDelete
  2. I am following the described method for using FTDI Basic 5V to upload Arduino sketches onto a broken-out ATmega328P (see http://i44.tinypic.com/qyu91e.jpg for setup). I have been able to upload the bootloader (Uno) and sketches using a SparkFun RedBoard (essentially Arduino board) and following instructions at http://arduino.cc/en/Tutorial/ArduinoISP. The main difference I see between what I have been successful with and the process described above is using the TXD/RXD pins rather than MOSI/MISO/SCK pins. When trying to "Upload Using Programmer" through FTDI Basic, the Arduino IDE returns the following error "avrdude: stk500_getsync(): not in sync: resp=0x00". Any help is appreciated. Thanks.

    ReplyDelete
    Replies
    1. I don't think you can do "Upload Using Programmer" through FTDI Basic. That option is meant for a programmer.

      Delete
  3. Looking at 2 things that I would like to know in the breadboard photo.
    I see a capacitor between the power input to the IC (PIN 7-8).
    Also see the 2 yellow jumpers to ground,one for LED obviously and one to the left that appears to go nowhere?I have setup this exact same way using identical method and it does not work for me.

    ReplyDelete
  4. I know this is old, but I've been looking around to find a post that works for uploading sketches to a breadboard Arduino with an ftdi adapter - and this one worked! So, thanks!

    ReplyDelete