Arduino Ecosystem rocks
Arduino is a great way to minimize the amount of variables when getting into microcontrollers. Flashing, cross-compilation, libraries, dongles are much easier(and cheaper!) when standardized.
I bought an expensive arduino nano v3, I got comfortable enough with it to blink an led and do with pwm. Unfortunately arduinos(except lilypad) feature lame 5V voltage regulators which require 6.2V to do anything useful; though atmega chips will supposedly run at as low as 1.8V. End result was that the NanoV3 did not run properly when hooked up to my 5V power supply on the bike.
So in the in the interests of not building a new power supply and not using a board with a whole bunch of pointless components I bought some straight-up ATMEGA328-PUs and a USB flasher.
The rest of this post documents various gotchas.
Pinout on Sparkfun is mirrored!
Red stripe on the cable indicates top. However the pinout is mirrored. One is supposed to look at it with the stripe on top and holes facing away.
ATMEGA328-PU ~= ATMEGA328P-PU
I wondered why seemingly identical chips were selling for a different price. P in 328P stands for picopower and as far as I can tell it allows one to turn off brownout protection. In my case brownout protection is something I want. However, fucking avrdude does not recognize ATMEGA328(without P) and bitches that one should pass -F when specifying -p atmega328p(there is no atmega328). This prevents Arduino IDE from functioning. In order to get a functioning IDE I needed to:
- Modify signature for atmega328p in avrdude.conf:
- signature = 0x1e 0x95 0x0F;
+ signature = 0x1e 0x95 0x14;
(Obviously the proper thing to do here is to add the new chip to avrdude) - Use breadboard.zip from http://arduino.cc/en/Tutorial/ArduinoToBreadboard as an inspiration for the following boards.txt entry:
usbtiny328.name=[usbtinyisp]ATmega328 8mhz
usbtiny328.upload.using=usbtinyisp
usbtiny328.upload.maximum_size=32768
usbtiny328.build.mcu=atmega328p
usbtiny328.build.f_cpu=8000000L
usbtiny328.build.core=arduino:arduino
usbtiny328.bootloader.low_fuses=0xE2
usbtiny328.bootloader.high_fuses=0xDA
usbtiny328.bootloader.extended_fuses=0x05
usbtiny328.bootloader.path=arduino:atmega
usbtiny328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
usbtiny328.bootloader.unlock_bits=0x3F
usbtiny328.bootloader.lock_bits=0x0F
- Burn bootloader with tools->burn bootloader->UsbTinyIsp
- Assemble board as per http://arduino.cc/en/Tutorial/ArduinoToBreadboard. One does not need to hook up GND(pin 22) or AVCC(pin 20). Connect ATMEGA RESET(pin 1), VCC(pin 7), GND(pin 8), MISO, MOSI, SCK(pin 19) to the flasher.
- Check the pin mapping. Note that Arduino software pins do not match physical pins(this cost me a few hours).
- Proceed to use Arduino tools with a convenient $2.82 chip* + $15 programmer rather than an inconvenient/overpriced Arduino board.