Arduino Uno on a Breadboard (With USB Support)
1743 Views, 3 Favorites, 0 Comments
Arduino Uno on a Breadboard (With USB Support)
In this tutorial, we will build an Arduino Uno on a breadboard with USB support. Other people have done this before, but they used FTDI boards or other USB-to-UART boards, and a small part of me feels like this is cheating. This tutorial will use none of these boards, only IC chips, a handful of components, and a USB breakout. To do this, we will use the MCP2221A IC from microchip. This chip will act as a USB to UART bridge, enabling us to program the ATMEGA328P chip. Another bonus of using this chip is that most modern operating systems already have drivers installed for this chip, eliminating the need to struggle over installing drivers.
Supplies
For the barebones version (USB power only), you will need:
- 1 - ATMEGA328P-PU chip
- 1 - MCP2221A chip
- 1 - 16 MHZ Crystal
- 1 - USB breakout board (and a cable to go with it)
- 5 - LEDs (various colors; I used 2 red ones, 1 green, 1 yellow, and 1 blue.)
- 2 - 22pf ceramic capacitors
- 2 - 0.1 - 1 uf ceramic capacitors (I used 0.1 uf)
- 1 - 10k resistor
- 5 - 2k resistor (these are for the LEDs, so they can be anywhere between 220 and 2k, but I like the LEDs dim)
- 1 - Small pushbutton
- Jumper wires
- 1 - Arduino Uno (to program the bootloader onto the ATMEGA328 chip)
If you want to include a 2.1mm power jack for portability, you will also need:
- 1 - 7805 Linear voltage regulator
- 2 - 10 uf capacitors (These should be between 25 and 50 volts)
- 1 - Breadboard friendly 2.1mm power jack
Prepare the Breadboard
In this step, we will prepare the breadboard.
- Connect the two power rails
- Place the ATMEGA328 chip onto the breadboard (about in the middle)
- If the power rails on your breadboard are split, connect them
Burn the Bootloader
Most ATMEGA328 chips available today do not have the Arduino bootloader on them. (Pre-burned chips are available, but are often rather expensive.) We will need to burn a bootloader onto the chips, using an Arduino Uno. To do this, we will use a sketch from Adafruit. This sketch makes the Arduino do the programming, instead of using the Arduino to act as an intermediator between computer and chip. It is recommended that you read through the github page before continuing.
Hardware Connections:
Connect these pins on the Arduino to the pins on the chip (you can use this image for reference, as the pinout is the same)
- 5V on Arduino to (+) power rail
- GND on Arduino to (-) power rail
- Pin 13 on Arduino to pin 19 on chip
- Pin 12 on Arduino to pin 18 on chip
- Pin 11 on Arduino to pin 17 on chip
- Pin 10 on Arduino to pin 1 on chip
- Pin 9 on Arduino to pin 9 on chip
For connections on the breadboard, connect:
- 5V power rail to pin 7 on chip
- GND power rail to pin 8 on chip
- 5V power rail to pins 20 and 21 on chip
- GND power rail to pin 22 on chip
It is also a good idea to add a visual cue for when the programming is complete, so add an LED from analog pin 0 to a 1k resistor going to ground.
Programming the Bootloader:
- Download the sketch file
- Extract the compressed folder, if necessary
- Navigate through the folders until you find the sketch (it will end in ".ino")
- Right-click on the sketch and choose "Open with Arduino IDE"
- The other necessary files should load in the sketch under different tabs
- Upload the sketch to the Arduino
- At this point, the Arduino should be programming the chip. Wait until the LED shows that the programming is complete (this can take a while).
That's it! You can remove any jumper cables from the Arduino to the breadboard. We are done using the Arduino Uno.
Connections for the ATMEGA328
In the previous step, we made these connections:
- 5V power rail to pins 7, 20, and 21 on the chip
- GND power rail to pins 8 and 22 on the chip
Next, add the 16 mhz crystal and the reset button:
- Connect the two legs of the crystal to pins 9 and 10 on the chip
- Add two 22 pf ceramic capacitors
- One going from GND to pin 9, the other from GND to pin 10
- Place the pushbutton onto the breadboard, to the left of the ATMEGA328 chip
- Place a jumper wire between pin 1 on the chip to the bottom-right pin on the pushbutton
- Connect the 10k resistor to pin 1 on the chip to the 5V power rail (This will be a pull-up resistor to prevent the chip spontaneously resetting)
- Place a jumper wire between the top-right pin on the pushbutton to the GND power rail
The last thing to do is to connect the integrated LED (On an Arduino Uno, this is tied to digital pin 13)
- Connect a 2k resistor from pin 19 on the chip to a free row on the breadboard
- Connect the LED between the 2k resistor and the GND power rail
Connections for the MCP2221A
Now we need to add connections for the MCP2221A USB-to-UART bridge and the USB-breakout board.
- Place the MCP2221A chip to the left of the reset pushbutton
- Connect the 5V power rail to pin 1 on the MCP2221A chip
- Connect the GND power rail to pin 14 on the chip
- Connect the 0.1 uf ceramic capacitor
- One end should go to pin 11 on the chip, the other should go to the GND power rail
- Place the USB breakout board to the left of the MCP2221A chip
- Connect the 5V and GND on the breakout to their respective power rails
- Connect the D- on the breakout to pin 12 on the chip
- Connect the D+ on the breakout to pin 13 on the chip
- If there is an "ID" pin, do not connect anything to it and leave it floating
Those are the basic connections, now let's add some LEDs!
- First add the green LED. Connect the cathode (short end) to pin 8 on the chip, and a 2k resistor from the anode (long end) to the 5V power rail
- Repeat above step using red LEDs and connecting to pins 2 and 3 on the chip
- Add a basic power LED by connecting the cathode to GND, and the anode to a 2k resistor going to 5V
The only thing left now is to connect Tx and Rx for serial UART communication.
- Connect a 1k resistor between pin 5 on the MCP2221A to pin 3 on the ATMEGA328
- Connect a 1k resistor between pin 6 on the MCP2221A to pin 2 on the ATMEGA328
Add 2.1mm Barrel Jack and Power Regulation
Barrel jacks and plugs can vary, as well as the pinouts of linear regulators. For this reason, check any datasheets to find the pinout and configuration of your parts.
- Plug the 2.1mm barrel jack and 7805 linear regulator into the breadboard
- Connect the GND on the barrel jack to the GND rail
- Connect the GND of the linear regulator to the GND rail
- Connect the (+) of the barrel jack to the input of the linear regulator
- Connect the output of the linear regulator to the 5V power rail
Almost done! The only thing left is to add some capacitors
- Add a 10 uf capacitor between the unregulated current to ground (this is easiest to do right next to the linear regulator)
- Add a 10 uf capacitor between the 5V and GND rails (+ on the capacitor goes to 5V)
- Add a 0.1 uf capacitor between the 5V and GND rails
Review Connections and Connect to Computer
First, review all of your connections. Next, connect the device to your computer, using a USB cable and the breakout board. After a couple of seconds, the green LED (connected to pin 7 on the MCP2221A) will turn on. This means that it is connected as a USB device, and that your computer can 'see' it.
Upload a Program
- Open the Arduino IDE
- Open the "Blink" example sketch, or write your own:
void setup() { //Configure pin 13 as an output, and start the serial communication pinMode(13, OUTPUT); Serial.begin(19200); } void loop() { //Turn the LED on Serial.println("ON"); digitalWrite(13, HIGH); delay(2000); //Turn the LED off Serial.println("OFF"); digitalWrite(13, LOW); delay(2000); }
- Under the "Tools" tab, make sure that the Arduino Uno is selected as the board
- Upload the sketch
- Just as it starts uploading, mash the reset button on the breadboard
- This takes some practice to get used to, and will take a couple of tries to get
- It should upload with no issues
- If you get an error: "not in sync", do not worry. You just mistimed your button press! Just try again.
- This sketch is an adaptation of the basic Blink program. I used it to make sure that the Arduino could communicate with the serial monitor in the Arduino IDE.
Troubleshooting
My computer cannot find the USB device
- Make sure that the cable you are using is a "data" cable, some USB cables are "charge-only"
- If your breakout board has an "ID" pin, make sure this is not connected to anything
- Make sure the D+ and D- cables are pretty similar in length
- If none of these work, you may need to install a driver for your OS. This is extremely unlikely, as Windows, Mac, and Linux all have drivers for CDC devices
I can't upload sketches
- Be sure to press the reset button before you start uploading. Not when the sketch is compiling, but before it uploads.
- It can take some practice to get the timing right. Don't accept defeat until you have tried uploading at least a dozen times.
- Make sure that the UART communication resistors are pretty similar in length.
- Make sure that you have the right board and port selected under the "Tools" tab in the Arduino IDE
Every time I plug the board into my computer, my computer crashes
- This means you have a short on your board. Inspect all of your connections. For me, I had the 2.1mm power jack wired up wrong. Luckily, I was only using a Raspberry Pi 3, so no harm done.
What Next?
- I moved the connections between power rails to the other side of my board, so that I had a larger prototyping area
- You could get a chip to step down the 5V to 3.3V so you have all the options found on an Arduino Uno.