Friday, October 1, 2010

Simple & Cheap Breadboard Arduino

If you're like me, you want to play with Arduino but you're on a ridiculously tight budget.   Some nice, inexpensive Arduino-compatible kits are available like the Solarbotics Ardweeny or the Boarduino.

Here's how to make a simple, cheap breadboard Arduino. Depending on the chip and bootloader, you can end up with an Arduino Uno or Duemilanove.

Cost
  • Atmel ATmega328P w/ bootloader $5.50 + shipping from Sparkfun
  • Electronics parts $4 + shipping
  • FTDI programmer $14 (which you can reuse) + shipping
  • Breadboard ($5-15 but if you're like me, you have several laying around)
We're talking $15 for the basic parts and shipping. Add some extra money for an Arduino-compatible programmer, wire, and a breadboard, all of which you will no doubt use for many projects. Not bad. Not as cheap as an Ardweeny, which you could substitute onto a breadboard leaving more room for circuits... but what the hey.

Breadboard and Protoboard Arduinos

http://arduinofun.com/blog/2009/10/15/breadboard-arduino/
http://tinkerlog.com/2008/01/07/arduino-on-a-prototype-board/
http://tom.stoopdice.com/blog/?p=670
http://blog.makezine.com/archive/2009/04/breadboard_arduino_from_oomlout.htmlhttp://www.instructables.com/id/How-to-Breadboard-Arduino-Compatible/

Buying Parts

To make it super simple, here are most of the parts at Mouser (just order qty 1 of the whole project). Now just buy the wire, the FTDI programmer for Arduino, ATmega328P with Arduino bootloader (from Sparkfun; they are now using the Uno bootloader) and a breadboard from Radio Shack, etc.

If you want to source parts on your own here's the list. You can use this list as a guide to order from Digikey to get free shipping by mail order.
  • ATmega328P with Arduino Uno bootloader (Sparkfun)
  • 5V FTDI breakout board programmer (Sparkfun)
  • Breadboard (30 row minimum) (Sparkfun, Radio Shack 276-0003)
  • (opt) 2 x 1K resistors
  • 6 pin breakaway header
  • 4 x 0.1uF capacitors (MLCC)
  • (opt) 3 x 1uF electrolytic capacitors
  • 3mm diffused LED (or, really any standard LED)
  • 470 ohm resistor
  • 16.0000 MHz crystal and 2 x 22pF capacitors -or- 16MHz ceramic resonator (try Sparkfun, Electronics Goldmine, etc)
  • Tactile momentary switch (take apart that broken DVD player, VCR, etc)
  • 10K resistor
  • Hookup wire (red, black, and one other color for the reset line)
  • (opt) 7805 voltage regulator (available just about everywhere)
  • (opt) 9V battery connector (Radio Shack)

Assembly Instructions

These instructions are for the type of breadboard with two power rows at top and bottom (like the Radio Shack 276-0003) and it uses a two-pin crystal/resonator, that is, one without capacitors built in.

An older Arduino with Duemilanove bootloader
  • Install the ATmega328P on the board with pin 1 at row E9.
  • Install a 6 pin header at D1-6 for the Sparkfun FTDI programmer
  • Wire up power and ground wires as shown above (the AVR uses VCC, Analog VCC, and Analog REFerence)
  • Install 0.1 (104) capacitors across 9V power at F1-2 and across G15,17
FYI, the 7805 will be installed at I1-3. I got sick of 9V pigtails pulling out of proto boards, so I finally solder a pigtail right onto a 7805. (below) with marine (gluey) heatshrink holding the pigtails to the case.



Now install optional 1uF electrolytic capacitors as above, across 9V power G1-2 and both 5V power rails.


Install the 7805 at I1-3.


Install a reset button at H6,8 with a line from I6 to ground and G8 to pin 1 of the ATmega, D9. I used a reset button I salvaged from a junk CD player.  I chose a right angle as it fit best. I cut off the support part of the case to make it fit. See below.




Install the 1k TX/RX resistors across C5,11 and A4,10 (pins 2 and 3 of the ATmega) The serial ports and the reset port are used by the Arduino bootloader.


Install the 10k pull-up resistor across A3,9, that is, between VCC on the FTDI header and ATmega pin 1.


Now squeeze a 0.1 uF (104) capacitor between C6,9, that is DTR on the FTDI and ATmega pin 1


Might as well put a 0.1uF (104) capacitor across the ATmega Vcc/GND pins C15,A16. Install 27pF capacitors for the crystal: one at D16,17 the other at C16,D17. Install the crystal across ATmega pins 9 and 10. I had to install mine diagonally: A16,C17 as below: Or, use my eeZee Breadboard Crystal.



For the final touch, to make it fully compatible with the Arduino, add the LED circuit: a 470 ohm resistor from G18,23 and an LED at F23,24 (digital pin 13 on the Arduino).

And that's it, you now have an Arduino on a prototyping breadboard. I've built a half dozen of these along the way for various prototyping and experimenting.

They work great, they're easy to do once you've done a few. Even better when your Arduino bootloader enabled ATmega has a decal on top labeling pins. Most do, nowadays.

Friday, September 24, 2010

Core War!

Two programs enter. One leaves. Picture this, tiny assembly language programs battling each other in core memory space* each trying to overwrite the other. Survival of the fittest.

Programs attack!
It's called Corewar. It's a game. A really cool, but kind of old programming game. I haven't looked at it in years but something made me think of it.

The appeal for me is the opportunity to think really creatively about assembly coding. It seems like good mental exercise. Maybe it will jar me into some epiphany about my vision code so I can get more than 3fps frame rate...

The game's assembly language, called Redcode, has 17 instructions and programs run on a virtual computer, the Memory Array Redcode Simulator (MARS) consisting of 8000 memory locations*. You can download various MARS implementations like A.R.E.S. or pMARS.
The goal is to try to get another program to execute a DAT opcode, which will crash it. To do this, your code (warrior) has to drop a DAT into memory right where the other warrior's Program Counter (PC) is pointing to run the next instruction.

Here's sample code from Corewars for Dummies.
;redcode-94
;name Sleepy
;author John Q. Smith
;strategy bombing core

ADD #10, #-1
MOV 2, @-1
JMP -2, 0
DAT #33, #33

end
The instruction ADD #10, #-1 is a self-modifying instruction. It adds the constant 10 (# specifies immediate addressing) to the constant in the second argument. When done the instruction becomes ADD #10, #9

The instruction MOV   2,  @-1 attempts to move the data in the memory cell PC+2 (the line DAT #33, #33) to the location specified in the second argument of the previous instruction... #9, that is. So it attempts to copy DAT #33, #33 to a location in memory 9 cells beyond the current program counter. Or, PC+9.

You can imagine JMP -2, 0 jumps back to the ADD line. That is, it sets PC = PC-2. And the process starts over. Basically the code drops DAT bombs every 10 memory cells.

Here's what battling warriors look like. Dig the cool 8-bit game music.



---
* von Neumann architecture, of course.

Wednesday, September 22, 2010

PryoElectro.com: Mini-Tank Line Follower

All analog, mini-tank, line-following robot
Chris over at PyroElectro.com sent along a link to his write-up for building a mini-tank line follower robot.

I thought I'd pass it along for those itching for a fun DIY robotics project to work on. If you've never built a robot before this could be your first!

It's based on a Tamiya tank kit, gearbox, and basic discrete analog components to follow a line. The write-up includes parts list, circuit diagrams, and very detailed instructions for constructing the robot. Nice!

Also included is a movie of the robot in action. It looks like it works really well. Nicely done, Chris!


This PyroElectro.com site has all kinds of interesting projects from guitar tube amps to turning your oscilloscope into a TV to various robotics projects. Definitely sub'ing to the RSS feed.