Recipe for an Arduino: one Atmel 328P (foreground) along with one 16 MHz crystal and a couple of 22 pF caps (background) |
Following Instructions: My goal is to build an Arduino Uno on a breadboard. Furthermore, I want to be able to program it from the Arduino IDE, just like a real Arduino. Not surprisingly, the Arduino folks have a pretty good page on how to make a breadboard Arduino. These are the instructions that I followed, though I'm bad at following directions, so you may see some differences here.
Buying Stuff: You don't need many parts. I already had basic stuff like a solderless breadboard, resistors, and jumper wires. I did have to buy the Arduino processor (an Atmel AVR ATMega328P), a 16 MHz crystal, and a couple of 22 pF caps. Easy.
Wiring Together my Breadboard Arduino: Once I got the parts, I started wiring it up. As shown in the picture below on the left, I started with the power (+5V) and ground connections, along with the 10K pull resistor for the reset line. Then, as shown in the picture on the right, I added the crystal and its supporting caps. That's it. It's done. [Note that some folks like to add a push button to make it easier to reset the chip. It's not necessary and I never felt the desire to use it. You don't need it.]
Is it now an Arduino? No. My breadboard circuit still is not quite an "Arduino" because it can't yet be programmed from the Arduino IDE. The missing piece is that the processor has not been programmed with the Arduino "bootloader". This is the software that tells the chip what to do upon startup, including how to listen to the Arduino IDE after being reset. So, to turn my breadboard circuit into a breadboard Arduino, I have to put the bootloader on it.
Burning the Arduino Bootloader: Following the Arduino page on this topic, I put the bootloader on my breadboard Arduino using a real Arduino Uno. I connected the Uno to my PC and (via the Arduino IDE) uploaded the "ArduinoISP" sketch. Note that this is programming the real Arduino, not my breadboard one. Once the Uno was programmed, I continued to follow the instructions and hooked up the Uno's SPI pins to my breadboard Arduino's SPI pins (see photo below). Finally, in the IDE, I set "Programmer" to "Arduino as ISP" and then selected "Burn Bootloader". I took just a second or two and it was done!
Using a real Arduino Uno (left) as a programmer for my breadboard circuit. Here, I'm burning the Arduino bootloader onto my Atmel 328P so that it can be programmed as an Arduino. |
Programming my Arduino: Theoretically, my breadboard Arduino (it's an Uno, specifically) can now be programmed with regular Arduino programs straight from the Arduino IDE. It has no USB jack, however, so how do I actually get the program onto the breadboard Arduino? The Arduino instructions say that, if you've got the right kind of real Arduino, you can use your real Arduino to act as a USB-to-Serial converter. Great! Let's try!
From One Arduino to Another: The key to doing this transfer is that you need the right kind of Arduino. The "right" kind of real Ardiuno is one where the main chip is a big DIP, which will need to be pulled out for this trick. Most of my Arduinos happen to be the SMT version, which won't work. In my bin of spare electronics, I did find one Arduino that is DIP version (yay!). So, following the Arduino page's instructions, I popped out the big DIP chip and then connected the board's TX and RX and Reset lines to my breadboard Arduino (see below). Once connected, I told the Arduino IDE software to upload the "Blink" sketch and VOILA! The light blinks! It works!
Using an empty Arduino Uno to program my breadboard Arduino with the basic "Blink" sketch. My breadboard Arduino lives! |
Programming via FTDI: After this exciting initial success, I found that this setup wasn't ideal. It turns out that my DIP Arduino would sometimes fail to program my breadboard Arduino. I then remembered that this unreliability was why this Arduino had sunk to the bottom of my box of electronics...I had seen problems with it previously. Very annoying. So, to avoid more annoyance, I purchased a stand-alone USB-to-serial converter. There are a variety of these devices available. I bought an "FTDI Friend" from Adafruit because they usually make good stuff.
Connecting the FTDI Friend: While the Adafruit documentation is good on how get started with the FTDI Friend, it does not explicitly show how to connect it to a breadboard Arduino to transfer a program. Instead, I found this thread on the Arduino forum, which was very helpful. The picture above shows the connections that worked for me. On the left are the names of the wires as labeled on the FTDI friend itself. On the right are the names of where it should connect to a breadboard Arduino.
Don't Forget the Capacitor! One key detail (as stated in the thread above) is that you have to use a capacitor between the RTS pin on the FTDI Friend and the Reset pin on the AVR chip. The cap needs to be 0.1 uF or bigger. If you don't have the cap in series, it doesn't work! Once i did this, I could reprogram my breadboard Arduino from the Arduino IDE reliably and with ease. It is very satisfying.
Can my Arduino Drive my Digipot? The whole purpose of this experiment is to figure out how to build an Arduino to the digipot that's at the heart of my Overdrive Mod for my Polysix. So, before I declare victory with my breadboard Arduino, I want to make sure that it worked like a real Arduino to drive my AD5260 digipot.
My breadboard Arduino controlling an AD5260 digipot. It works! |
Testing with the Digipot: I wired up the digipot the same way as in my previous post, though I did need to reference the Arduino pin map to find which pins on my naked AVR chip corresponded to the SPI bus (answer: pins 19, 17, and 16). Once I got it all connected (see picture above), I loaded my test code for the digipot, which steps through a few resistance values. As you can see in the picture below, it works just fine...here I'm getting a resistance of 8.3 kOhm. It was very satisfying to confirm that my breadboard Arduino was able to drive my digipot.
Measuring the resistance values produced by my Arduino-controlled digipot. |
Adjusting CPU Speed: Now that it all works, I'm thinking ahead to the PCB that I'll design to fit these elements within the Polysix. I'm a bit concerned that the addition of this microcontroller, plus the others that I've already added, might be stressing the power supply of my old synth. My old synth already gets pretty warm. So, if possible, I'd like to minimize the power consumption of my added elements. One easy way to reduce power is to slow down the clock speed of the processor on my breadboard Arduino. Looking at this thread, you can change the CPU speed on an Arduino simply by adding a little code to your sketch. That's easy!
Measured Current Draw: Following the example code in the link above, I tested each speed from 16 MHz down to 1 MHz and recorded the current draw for each case. My results are shown below. In all cases, I confirmed that the digipot still works, which is great. So, it appears that I can cut my power draw almost in half by running at 1 MHz. Great!
Current Draw When Running the "Blink" Program. The clock speed is changed by changing the clock divider setting. No is LED connected. |
Lessons Learned: The purpose of this whole experiment has been to learn what needs to be learned so that I can build my own Arduino-based modification for my Polysix. Let's summarized the important lessons:
- I am able to build my own Arduino from a raw Atmel AVR chip. That is fantastic.
- To put the Arduino bootloader on the raw AVR chip, I need access to the chip's SPI pins. So, on my custom PCB, I need to make those pins available.
- To program the AVR chip from the Arduino IDE, I need access to the chip's TX, RX, and Reset pins. So, I need to break those pins out, too.
- To upload my programs to the AVR chip, I need a USB-to-serial converter. My Adafruit FTDI Friend works great as long as I've got that in-line capacitor on the RTS line.
- To save power, I can run my Arduino at 1 MHz instead of 16 MHz. I confirmed that the digipot still works fine at the slower speed.
Follow-Up: I designed a custom PCB, including a home-brew Arduino! You can check out the story here.
Fantastic work on this, PCB design is easy enough, just keep the high speed clock lines short and observe any recommended layout from the application notes. If you go SMT, you might want to stick with larger smt or possibly stick to through-hole as it will be much easier to solder vs. the spec of sand sized passives - otherwise, that could be a challenge in itself.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete