Loading...

在面包板上搭一个 Arduino

概述

这个教程为你展示如何用 Atmel Atmega8/168/328 的AVR单片机和 FTDI FT232 接口板(来自 SparkFun)建造一个 Arduino兼容面包板。或者用 Arduino USB Mini 代替 FT232。

Originally created David A. Mellis
Updated from the ITP version by Carlyn Maw
Updated October 23, 2008 by Rory Nugent

零件

要做这个,你需要:

the supplies
The Supplies

搭建 Arduino 需要的基本元件

  • 一块面包板
  • 22 AWG 连接线
  • 7805 稳压块
  • 2个 LED
  • 2个 220 欧姆电阻
  • 1个 10k 欧姆电阻
  • 2个 10uF 电容
  • 16 MHz 晶振
  • 2个 22pF电容
  • 微动开关,例如 Omron B3F

USB转串口通讯板

你会需要一块 FT232 USB 接口板(来自 SparkFun)。

可以任选以下之一:

  • FT232RL USB to Serial 接口板, SKU BOB-0071
  • Arduino Serial USB Board, SKU DEV-08165

If you plan to use the top option and have not yet soldered headers to the breakout board, now would be a good time.

Bootloading your Atmega Chips

There are several options for bootloading your Atmega chips, a few of which are covered in this tutorial. If you wish to bootload your Atmega chips using your breadboard, an additional part will make your life much easier but is not necessary.

AVR Programming Adapter from Sparkfun, SKU BOB-08508


连接电源电路

如果你用过单片机,那么你很可能已经知道怎么给板子连上供电线路,那么就直接干吧。如果你需要一些提示,下面的一系列图片就是方法之一。(这个版本用的是5V稳压电源)


toppower
顶部电源线

接上稳压块的电源和地的连线。

bottompower
底部电源线

连接底部电源线使面包板两侧排孔连通。

7805
加入 7805 和退耦电容

加入 7805 稳压块和一些连线给面包板供电。稳压块是 TO-220 封装的,面对稳压块的正面,左边是外部电源输入脚,中间脚接地,右边引脚是5V输出。电源输出和地连接到面包板外侧的排孔。

同时,在稳压块的输入与地、输出与地之间各跨接一个 10uF 的电容。电容外壳上白线标示的引脚接负极(地)。


PowerLED
LED

在稳压块的对面板子的左侧接一个 LED 和 220 欧的电阻。连接在电源上的 LED 可以方便的了解供电是否发生故障。

Power Supply Input
电源输入

稳压块左侧的红线和黑线是外部电源接入的地方。红线连接正极,黑线连负极(地)。注意接入的电源电压要在 7-16V 之间。过低的输入电压无法使稳压块输出 5V。过高的电压会损块稳压块。9V的电池、9V 直流电源或 12V 直流电源都是适用的。

BlankCanvas
Blank Canvas

现在基本电源电路已经完成,接下来该插上芯片了!


ATMEGA8/168/328 基础知识

Arduino Pinmap
Arduino 引脚定义

在继续下一步之前,先来看看左图。从这个可以了解 Atmega 芯片每个引脚的功能,这些功能和 Arduino 的功能密切相关。 这能让你明白那些引脚为什么这样连接。详情可以参考datasheet: Atmega 168 (简单版) (详细版). Here's the sheet for the atmega328 (简单版) (详细版)


AddingChipCircuitry
连接外围电路

先给 RESET 引脚连上一个10k欧的上拉电阻(连到+5V),防止芯片在正常操作时被复位。RESET引脚处于低电平时会执行重启芯片的操作。在接下来的步骤中会教你加入一个复位开关来改进它。

  • Pin 7 - Vcc - Digital Supply Voltage
  • Pin 8 - GND
  • Pin 22 - GND
  • Pin 21 - AREF - Analog reference pin for ADC
  • Pin 20 - AVcc - Suppply voltage for the ADC converter. Needs to be connected to power if ADC isn't being used and to power via a low-pass filter if it is (a low pass filter is a circuit that reduces noise from the power source. This example isn't using one)


AddClock
连接晶振和电容

在9和10脚之间接上一个 16 MHz 的晶振,并在这2个引脚和地之间跨接上 2 个 22pF 的电容。


AddReset
连接复位开关

加上一个微动开关,这样你就可以随时给 Arduino 复位和准备给芯片上传新的程序。短按一下开关就能使芯片复位。在紧贴 Atmega 芯片的上方插上微动开关,使芯片跨在面包版中间凹槽的两侧。然后用导线连接微动开关的左下脚和 Atmega 芯片的 RESET 引脚,再用一条导线把开关的左上角和地相连。


LEDWires
LED 连接到 Arduino 的 13 号引脚

这个板子上的芯片是已经写入了 Arduino 软件中的 blink_led 程序。如果你已经有了一块可以运行的 Arduino 模块,不妨用那片已知可以正常运行的芯片来测试这个面包板版本。把芯片从 Arduino 模块上拔出来插在面包板上试试。blink_led 程序会使引脚13上的LED闪烁。注意 Arduino 的引脚13不是 AVR ATMEGA8-16PU/ATMEGA168-16PU 的引脚 13。它实际上是Atmega芯片的19脚。

参考前面的 引脚定义,确定你正确地插好了芯片。


LED
Arduino 13 号引脚上的 LED

最后,插上 LED。Finally, add the LED. The long leg or the cathode connects to the red wire and the short leg or the anode connects to the 220 ohm resistor going to ground.


Arduino-Ready!
Arduino-Ready!

At this point if you had already programmed your chip somewhere else and didn't need this breadboard circuit to reprogram the chip, you could stop here. But part of the fun is in-circuit programming so keep going to really make a full USB-Arduino-circuit on a breadboard!


Arduino-Ready

Add USB
Add FT232 USB to Serial Board

Now we'll be adding the USB to Serial breakout board to our Arduino breadboard circuit. If you haven't added male headers to your breakout board, you will need to do it now.

Connect the VCCIO of the breakout board to power and the GND to ground.


USBBack
The pinouts of the Sparkfun FT232 breakout

Curious what all the pin outs are for the SparkFun FT232 breakout board, just simply flip it over! In this situation we'll be using VCC (to supply 5V from the USB port to your board), GND, TXD, and RXD.


TXRX
Connecting the TX and RX

Now, it's time to get the USB to serial breakout board talking with your new Arduino setup. Connect the RX (pin 2) of your Atmega chip to the TX of the USB to serial board, and connect the TX (pin 3) of your Atmega chip to the RX of the USB to serial board.


And there you have it... ready to be plugged in, powered up and programmed!

But wait, there's another step right? If you pulled your Atmega chip out of your Arduino, it has most likely been programed several times by yourself and so it definitely has been bootloaded, so you won't need to move any further in this tutorial.

However, if you purchased some extra Atmega8 or Atmega168 chips from an online store they will have NOT been bootloaded with the Arduino bootloader (with the exception of Adafruit Industries). What does this mean? You won't be able to program your chips using the USB to serial breakout board and the Arduino software. So, in order to make your new chips useful for Arduino you MUST bootload them and MUST check out step 4.


Other Breadboard Options

The uDuino Setup by Tymn Twillman
This configuration is similar to the one above but the trick is that the Atmega chip is bootloaded with the Arduino Lilypad bootloader. The Lilypad runs using the internal clock instead of an external clock and so removes the need for much of the supporting circuitry.

Boarduino by Ladyada
The Boarduino is a kit you purchase and assemble to create a nice, small breadboard compatible Arduino set up. All the common components are included on a small PCB so that the Boarduino can easily be added to a breadboard and even removed, in a snap.


Bootloading your chips OPTIONAL

Bootloading Options

There are two options for bootloading your chips. The first being quite easy and the other being a little more tricky. We will cover both.

  • Bootloading your Atmega chip using a Arduino board and an AVR programmer
  • Bootloading your Atmega chip in your newly prepared breadboard with an AVR programmer

There are also many different kinds of AVR programmers but two are most commonly used:

AVRISP mkII
AVRISP mkII

USBtinyISp
USBtinyISP


The AVRISP mkII can be purchased from Digikey (Part # ATAVRISP2-ND) while the USBtinyISP must be assembled and can be found at Adafruit Industries.

Using an Arduino board

ArduinoBootload
Bootloading on an Arduino board

Place your Atmega chip into the Arduino board with the divot of the chip facing outward. Set the jumper to an external power supply and connect a 12V power brick (your board needs to be externally powered when using the AVR ISP mkII but is not needed with the AVRtinyISP) . Then, attach the 6-pin female plug of your AVR programmer to the 6 male header ICSP pins with the plastic nub of the ribbon cable head facing inward.

NOTE: The AVR ISP mkII turns its LED green when they've been hooked up correctly and are ready for programming. The LED turns red if it is hooked up wrong.


Using your breadboard

AVRAdapter
AVR Programming Adapter

When bootloading an Atmega chip on a breadboard, the AVR programming adapter (SKU BOB-08508) from Sparkfun is incredibly handy. This adapter breaks out the 6 pins from the programmer to 6 inline pins for easy attachment to the breadboard. All the pins are also labeled making it very easy to connect it up to your chip.


6pinAVRprogcable
6-pin AVR Programmer Cable

Don't worry, if you don't have an AVR programming adapter you can still bootload without it. It will however be more of a headache to set up. The two images to the left are great references when hooking up a programmer to an Atmega chip without an adapter board. The images will tell you what all the holes in the 6-pin AVR plug are and you will simply need to stick wires in the end and run them to your Atmega chip.


6pinAVRproghead
6-pin AVR Programmer Cable Head

This image is a view from the bottom and labels each of the holes. Take note of the square as to what orientation your cable is in.


AVRpwrgnd
Add power and ground

Let's begin!

With the breadboard you prepared above, add two wires for power and ground for your AVR programmer.


AVRplug
Plug in the AVR adapter

Now plug the AVR programming adapter into the breadboard with the GND pin matching up with the ground wire you just ran and the 5V pin matching up with the power wire you just ran.


AVRwires
Add the MISO, SCK, RESET, and MOSI wires

In this step you will need to add the last four wires needed by the AVR programmer for proper bootloading.

Be sure to refer to the Arduino pin mapping for help wiring this up.

  • The MISO pin of your adapter will go to pin 18 or Arduino digital pin 12 of your Atmega chip.
  • The SCK pin of your adapter will go to pin 19 or Arduino digital pin 13 of your Atmega chip.
  • The RESET pin of your adapter will go to pin 1 of your Atmega chip.
  • The MOSI pin of your adapter will go to pin 17 or Arduino digital pin 11 of your Atmega chip.


Plugin
Plug in the USB cable and AVR programming cable

Almost there! Just plug in a USB cable to your USB breakout board and plug the 6-pin plug of your AVR programmer to your AVR programming adapter. The black nub of the 6-pin head must be facing upwards towards the Atmega chip.

In the next step, we'll show you have to use the Arduino software to burn your bootloader!


Time to burn!

ArduinoPickBoard
Pick your board type

Fire up Arduino and then go to 'Tools' and 'Board'. Choosing the type of board you'd like to use will effect which bootloader you will be put on your chip. Most commonly you will be using the Diecimilia or the most recent version of Arduino for an Atmega PDIP, however if you'd like to bootload an Arduino Lilypad, Arduino Mini, Arduino Nano, or any of the older Arduino versions, choose the appropriate board.


ArduinoBurn
Choose your programmer. Burn!

Then, go to 'Tools' and 'Burn Bootloader' and choose the programmer you will be using.


ArduinoBurning
Burning

Once you chose your programmer, the AVR programmer will begin bootloading your Atmega chip and a message will appear in the status bar which reads "Burning bootloader to I/O Board (this may take a minute)..." Lights will flicker on your programmer.


BurnDone
Burn Complete!

When done bootloading, the status bar will be updated with the message "Done burning bootloader." Your chip is now ready to be programmer using the Arduino software! Congrats! Power cycle your Arduino and your new Atmega chip will be running a simple LED blink program with pin 13 (if this is not the case, try programming it with one). If this is working, it was most definitely a success.

NOTE: On occasion, the process of bootloading an Atmega chip with the AVR ISP mkII will take an extraordinarily long period of time. Usually it should only take a couple minutes and in fact, the AVRtinyISP finishes much quicker. However, there are times where after 5-10 minutes it still appears to be bootloading. I found this to be an odd hiccup (perhaps it is triple checking the data flow) and after giving it ample time, 10 minutes or so, I usually unplug the programmer only to find the burning process to be a success and has ended long ago. I by no means endorse this method and you take all responsibility in whatever may happen to your chip, but in my experience it has been fairly harmless though you should proceed with caution. It is very possible that you may damage your chip in the process.


HomePage