Note: code for this project is available here.
For learning microcontrollers, Arduino is a good introduction to the higher level concepts and abilities of a microcontroller. However, directly programming with the microcontroller in C can provide a greater learning opportunity (while also being less portable).
However, an example of needing to use the Arduino setup would be the weather station, as it used an ESP8266 and is not programmable using this method.
This project was tested on an Arduino Nano with an ATmega328P and CH340 USB communications chip.
One of the easier (and cheaper) programmers to use would be the USBasp, as it is open source and as such has a lot of clones with adapters to make flashing on Arduino platforms easier.
The USBasp can also update/flash the bootloader on the Arduino, as the bootloader makes flashing the Arduino possible. In the Arduino IDE, in tools set the programmer to USBASP and then select Burn Bootloader.
However, this setup unlike the Arduino setup uses the D11 to D13 pins (MOSI, MISO, SCK) when programming. The USBasp can always be disconnected after programming if those pins are needed (from the 10 pin to USBasp connection point, or disconnecting the 5V/3.3V power).
For better debugging, serial communication can be used with the same interface as the Arduino programmer (USB) or an I²C HD44780 display if there is audio work with fluctuations from the host USB (code). This display can also be tested using Arduino. An example of this setup is shown to the right.
The easiest way to rapidly program on Linux would to use a makefile, as a make program
is all that is required in order to start programming the microcontroller. The required
programs include make (to setup the compiler), avr-gcc (compiler), and avrdude (programmer).
The included makefile for this project builds the code in a folder and then flashes the microcontroller. It can also get the assembly code if needing to look at the preformance, along with outputs the size when programming the microcontroller.
Available commands include make program
(compile and program), make compile
(compile
only) make size
, make asm
(for assembly code). Both the compile and program also will
warn of errors when compiling.
For Linux based systems, the application
moserial can be used. This allows
serial communication to be send and received, and is quite easy to use. The command make
serialcomm
opens the serial monitor with the first /dev/ttyUSB* port found on the
system.
For Windows, Tera Term, PuTTY, or the Arduino IDE can be used.
abcminiuser - AVRfreaks includes sample code that helped in the development of this code.
Oregon State ECE 473 (archive.org link) is a pretty good resource on ATmega128 in specific along with I²C, SPI, UART, timers, schematics, pushbutton debounce code, interrupts and fuses. This can be used in addition to the manual for an AVR microcontroller. There is also a sample makefile available.