by Brian Conley, PE
One thing that is both useful to know and fun is how to design with microcontrollers. You could spend hundreds of dollars on things like In Circuit Debuggers (ICDs) and compilers. Or you could try something from the open source environment called Arduino. For less than a hundred dollars, and maybe even less than fifty you can start learning about microcontrollers and make things that blink and beep.
The Arduino (www.arduino.cc) is a family of circuit board assemblies. The brain is an Atmel microcontroller, most often an ATmega328. This provides the programming platform the whole reason for the board. In addition to the microcontroller there is a USB chip and connector to connect to a computer as an application or to connect to the Development Tool, which can be downloaded free from the Arduino website. Every Arduino board are the I/O connectors, either male (in the Arduino Nano) or female (in the Arduino Duemilanove and Arduino Mega). The final part of any Arduino board is the power regulator and connection to the AC-DC converter or “wall wart.”
The Arduino software environment is also easy to learn and use. The Development Tool comes with a compiler and a serial interface through a USB connector. Included with the download are simple examples of setting a digital pin as an output, reading a digital pin as an input, reading an analog pin via the ADC inside the microcontroller, and reading from and writing to the Arduino via the USB line. The on-line help is decent, although rather simplistic.
The registers of the ATmega chip are hidden from view, which is nice for the beginner but might frustrate a more advanced user. This is not really a problem once you find out about the online Forum, where many questions are asked and answered and you can find out how to do the advanced things. There is also a local group called DorkBot PDX that meets biweekly where you can see what others have done.
The programming language is similar to C. It is tightly coupled to the Arduino board, meaning that you have to declare a variable as one of the pin numbers instead of setting a bit in a particular port. For example, here are three lines to write a bit out:
First you declare the name to pin connection: (This example connects variable ONESA to pin 22.)
define ONESA 22
Then set the mode of the pin: (as an output)
pinMode(ONESA,OUTPUT);
The last step in this procedure is to write to the pin, making it high.
digitalWrite(ONESA, HIGH);
For an analog pin the code is even simplier, you have to declare a variable but the code is:
P5VSENS = analogRead(1);
For more advanced applications you can look for answers in the Forum.
So, how do you get started? The Arduino boards are available from many vendors.
Local to the Pacific Northwest is Fun Gizmos in Woodland, Washington. There are also vendors in California and across the country. The cheapest starting point is to buy an Arduino Nano, a solderless breadboard, some other circuit elements, and then just start playing. As you advance or want to make a larger investment there are prototyping shields available.
Most vendors also have lots of little sensor add-on circuits that could be easily interfaced. These may look too simple to be worthwhile; I thought that too at first. But one of my clients has built an eight-cylinder engine controller around an Arduino Mega. I had to get into Arduinos because I built a board around one for a client, then had to make it work. Now I have a new skill that I can offer my clients, and a new way to have fun to boot.


Posted
11.09.2010 in










Leave a Comment