I bought:
- Arduino clone (I wish I bought the real thing btw) ATMEL AVR ATMega328p.
- SD card shield. Not SDHC compatible but I can live.
- 2GB SD card (not SDHC).
I bought the stuff locally in Canberra from
Australian Robotics. They are really well priced and I spent over $50 so it only cost $3.50 for express postage. My order was waiting for me at home the next day. They are awesome.
Whats really nice about the Arduino is that it s a really cheap and easy way to get into programming microprocessors. The board comes pre made with easy access to the pins, the clock installed, all resisters and such installed. These boards can be made by hand I think, you can buy kits or what not.
This biggest advantages about this board is the USB port (which you can power the board off) and the Arduino bootloader. You do not need another chip or doodad to program these boards which is awesome.
Back when I started I spent over $200 on microprocessor stuff. Now I can buy all that in the Arduino form for about $20. Awesome.
However, Arduino have made a big effort to make the board really easy to use and make their own software to program it. Their software allows you to program in C++ really easily with a whole bunch of useful examples and code and libraries and everything. Its really nice. Until you realise you need do stuff at 2microseconds...
The reason I got the Arduino is because I want to make a floppy drive replacement device for my Amiga 500. I have a whole bunch of games which instruct you to backup the disk and also requires 1 or 2 disks to save data 2. I don't have any disks and even if I did I can't format them right now because I don't have the Workbench disks (OS disks).
So I have this awesome Arduino but I don't want to use their software. Well you at least need to install their software AND the FTDI drivers to talk to the board over USB.
I also use the Arduino sample code to make sure things on my board are working. Also you can download the Arduino source and look at their libraries like the Serial and SD objects and how they do delays and stuff. Really nice if you get stuck.
If you hold down shift while uploading a sketch to the board it will output a whole bunch of info in the console area of that window. From this info I was able to figure out how to send compiled code to the board.
Note I'm doing this on Mac OS X. However much of this stuff is probably available for windows and Linux. Alternatively you can use the info from the Arduio software to figure it out. On Windows you probably could use AVR Studio to compile the code and use the command from the Arduino software to send the data to the board if AVR Studio can't do it.
Note about the bootloader:
The bootloader seems to handle all the programming to the board which is good. We do not want to ever overwrite this without very good reason. The Arduino bootloader is really awesome since we can program the board over USB really really easily. Also from what I can tell, the bootloader has been protected from being overwritten by default using the fuses. We can pretty much ignore the bootloader and let it do it's magic. Just be aware that it is there, it is awesome and you always want it.
On my Mac I installed the Arduino software and a really nice package of stuff
CrossPack.
I'm not sure if CrossPack has more stuff in it than the Arduino software but it has avr-gcc and avrdude. gcc is the compiler and avrdude is used to send the compiled program to the board. (gcc and avrdude also come with the Arduino software).
I ran the avr-project command which gave me a very basic Xcode project and a separate basic makefile and main.c file.
I don't bother with Xcode, I use vim for all my work so I can't comment on how to get that working.
The great thing about having the Makefile for you is that it is really easy to program C and C++ and get it all compiled and sent to the board. I assume that it is also easy to compile assembler.
Oh also if you want the speed of assembler but you like C, you can program everything in C then compile it and use avr-objdump to print out the assembler which you can fiddle with and recompile if you don't like how the compiler optimises your code. This is really helpful also if you want really simple assembler for something you know how to do easily in C.
Compiling and Flashing
To be able to compile and to get make to work you need to fix the Makefile for your board.
My board has an atmega328p processor. You can get info for boards from the Arduino source (boards.txt file I think).
First I comment out all references to FUSES. I don't know much about them other than they control how the processor works, protect the bootloader and a bunch of other stuff. I don't know about them and so I don't want to touch them, everything seems to work fine without fiddling with them. The default makefile is for an ATMega8 which may not have the same fuse settings as my processor.
Also you need to update the OBJECTS section with the new files you add to your project otherwise they won't be compiled.
The important lines to change are:
DEVICE = atmega328p
CLOCK = 16000000
PROGRAMMER = -D -b57600 -c arduino -P /dev/tty.usbserial-A400fXlf
Not sure what device you have? run avrdude -p ? to list avrdude supported processors.
My board is configured with a 16MHz crystal.
PROGRAMMER was the hard one to figure out:
- -D: Disable auto erase for flash memory... I don't know if thats a good or bad idea.
- -b 57600: The baudrate needed to connect to the board via the USB port. I'm pretty sure this is set as part of the bootloader and FTDI set up on the board.
- -c arduino: The programmer type. Usually you need a programmer to flash your processor. However, the Arduino bootloader is awesome and can program itself.
- -P /dev/tty.usbserial-XXXXX: This is the device handle used to talk to the board. This is also the device to connect to when you want to send/receive stuff over serial.
With all that set up and some code in main.c you should be able to run make to compile and if everything goes well run make flash to program your board.