Getting started

Even if you are experienced with designing circuit boards, I would suggest you buy a development board to start off with. You might be able to save a few bucks building one yourself, but its not worth the hassle - trust me, I've been there done that. 

After playing around with several microcontrollers, the best platform to start off with in my opinion is an ATmega. It has free and open-source toolchains, supported by some great libraries (such as Pascal Stang's AVRLib), many helpful communities (such as AVR Freaks), and importantly easy to understand datasheets.

The ATmega is an 8-bit microntroller which is fairly easy to use. On the other hand, 32-bit micros such as the PIC32 and the STM32 are powerful but a lot more difficult to use - they are not for beginners!

Several development boards exist for ATmegas, but I would suggest you buy an Arduino Uno. It conveniently brings out the microcontroller pins into a semi-friendly breadboard layout, has an onboard programmer (a huge benefit), and a selection of other useful things. Many semi-specialised shops sell Aruduinos, but you can also buy them cheaply off ebay.

Another benefit of starting off with an Arduino board is that it comes with a nice integrated development environment (IDE). The Arduino environment provides a user-friendly programming language, Wiring. This language is sort of like C, but builds in Arduino libraries that make setting up PWM, and communicating with RC servosI2C and other peripherals quick and easy. 

Note that you are not limited to programming in Wiring when you use an Arduino. I've got an Arduino, and I haven't even used Wiring on it! Instead, I like to use plain old C and a Makefile, with the avr-gcc toolchain, along with the AVRlib and my own custom libraries.

Windows

Download and install WinAVR. Install it where you want, but I recommend add directories to path and installing Programmers Notepad (PN). I also like to setup hotkeys with my PN. In PN, go Tools->Options. Click on Tools on the left pane, and under the "Scheme" dropbox, select "(None - Global Tools)". I assign F9 to "Make Clean", F10 to "Make All", and F11 to "Program", but thats entirely up to you!

Linux

It is just as easy to get gcc-avr going on Linux. For me, I use Ubuntu 10.04 and setup my computer by firing up a terminal and running: 

sudo apt-get install gcc-avr avr-libc binutils-avr avrdude

Like most of my work under Linux, I prefer to use a plain old text editor (in this case, gedit) and a terminal. It's somewhat old school, but it works well for me. I'm sure you could setup hotkeys as well, but I just type in "make clean", "make", or "make program" in the terminal.

Resources

Here are a few Arduino+gcc-avr projects to get you started, starting off with the easiest ones first. I am a fan of learning by doing, so instead of writing up a page for each I'm simply going to provide you with the source files. You will need to change the Makefile depending on which COM port your computer assigns your Arduino (these examples are setup to use COM3). Note that the COM port is used for both programming the Arduino, and also provides a virtual com port (VCP).

  1. Toggle an LED, read an ADC port and read a switch: atmega_simple_blocking.zip
  2. Toggle an LED, read an ADC port and read a switch (without blocking delays): atmega_simple_non_blocking.zip
  3. Use the UART port to print out debug messages: atmega_uart_test.zip
  4. Read a quadrature encoder: atmega_encoder_test.zip
  5. Read a HC-SR04 ultrasonic rangefinder: atmega_hc_sr04_test.zip
  6. Create a simple I2C slave interface: atmega_i2c_slave.zip
  7. Drive a pair of MC33886 5A h-bridge motor drivers: atmega_mc3886_motor_driver.zip
  8. Read a MPU-6050 inertial sensor (using its DMP): atmega_mpu6050_test.zip
More advanced examples
  1. Create a battery monitoring circuit with an I2C slave interface.
  2. Make an ultrasonic rangefinder with an I2C slave interface. This project also show how to interface a serial port to MATLAB via RealTerm.
  3. Interface to a DS18B20 1-wire digital temperature sensor and create a simple 1-wire slave device (my temperature sensor hack).

Share |