Sunday, November 28, 2010

Which microcontroller should I get?

There is a huge controversy about which microcontroller is the best, it's almost like a Mac vs PC thing, but just like the Mac vs PC debate I think it is clear which is better (Mac!!!). Before I start let me just make sure you know that when you are getting a microcontroller you usually want to buy a microcontroller on a development or prototyping board. So there are two parts to the decision, the actual microcontroller and the supporting board which provides all the necessary support circuitry.

The major microcontroller contenders I see for beginners are PIC, AVR, MSP430, ARM, and the BASIC Stamp. It is really hard to be able to say which microcontroller you should get because it really depends on your budget and what you are going to use it for. But from my opinion, for a beginner the AVR has a better community, free tools, and the Arduino board.

The Arduino board not only provides you with a great board but also a great programming environment. If you are not a pro at C/C++ but you still want to be able to program in a powerful language then the Arduino is perfect. Truly, it is actually C++ minus a main and plus a easy-to-use library. The Arduino also has an AWESOME community and great documentation! I cannot stress enough how much good documentation and a healthy community helps beginners. The first microcontroller I got was a MSP430 board from Olimex and I have never programmed it in 2 years. This is mainly because I didn't get the right tools to program it but if there was good beginner help I would have gotten the right stuff! The second microcontoller I bought was an Arduino and I had it up and running in minutes.

Now before you go buy your Arduino, you need to understand some things. First, this is a general purpose board, this means will not be able to run DC motors or run a bunch of servos or sensors straight off the board. For you motor people, you will either need a motor shield or a motor driver. The Arduino has a bunch of I/O pins but only one 5v power pin so in order to connect all your servos or and sensors  you will need a breadboard and some jumper wires. Depending on what you want this microcontroller to do you will either need additional circuitry or a shield OR you could buy a specialized microcontroller. I personally like the general purpose Arduino boards but usually the specific microcontroller boards are cheaper than the Arduino + Shield.

Now that I have given my sales pitch for Arduino, lets make a list. When considering which microcontroller to buy:

  • Check out the documentation and the community. If you don't understand the documentation and there is no one to help you, this is probably not a good microcontroller to start off with.
  • Make sure you understand how it's programmed and what you need to program it. Whether it is special programming hardware, expensive software, or free and very complicated software. Arduino's software is free, all you need to program it is a USB A to USB B cable, and if you want you can program it with the AVR tools which are also free.
  • Make sure the board that your microcontroller is on can do what you want. If it can't then you need to buy additional stuff to get that functionality (make sure it's compatible!). The Arduino has many compatible circuits, which they call shields, that attach to the top of the board.
  • Don't be too concerned about features! Don't get overconfident and take on the biggest and baddest board out there for your first project. Start with the basics. If you go buy an Olimex ARM board... You're on your own.
Of course I should give you some links to wet your appetite:
  • Arduino  -  I have used an Arduino Uno and an Arduino Mega and very much enjoy working with them. The good news is that Arduino is Open Hardware and Open Source. This means that every aspect of this board and it's software is open to the public. It also has a large and helpful community and great documentation. The bad news is that it requires a shield to do some tasks and and you have to make sure that sensors and other things you buy for it are compatible. The main Arduino board is currently the Uno and it sells for around $30.
  • LilyPad  Arduino  -  If you want to make wearable computing, the LilyPad is worth a look. It is designed to be sewn onto fabric and connected to other devices via conductive thread. If this is something you are interested in it is only $21.95.
  • Arduino Clones  -  Arduino clones are boards based on the Arduino and support the Arduino enviroment. They may have more features or less features and may be larger or smaller. Some of the more popular ones are the Bare Bones Board, Really Bare Bones Board, Freeduino, Boarduino, Illuminato Board, Orangutan Robot Controllers, Roboduino, Sanguino, and the Seeeduino. I have not used any of these but they may have the features you want. Go ahead and check them out.
  • Axon Microcontroller  -  The Axon was designed by the author of the Society of Robots website so I assume it is a great robot controller. It has a TON of pins and they are arranged in a 3 pin fashion so that you can plug in servos and sensors directly. It is available from the Society of Robots website for $94.
  • PICAXE  -  The PICAXE is based on PIC so that means no free software. It also requires a special programming cable that costs more than the board. I have heard that some people like this controller but I am unsure how healthy the community is. It is fairly cheap, $9.95, if you you don't count the software and the cable.
  • VEX ARM Microcontroller  -  I used this controller on my robot for a recent high school robotics competition. The nice part about this microcontroller is that you know anything you buy from VEX will work with it. The bad part is it costs $249.99 and then you must pay for a crummy programming environment. No thank you! You could get the $149.99 PIC Version but that is still expensive!
  • Mindstorms NXT  -  The NXT Intelligent Brick is a microcontroller meant to bring Lego projects to life. Unfortunately you have to pay for the more powerful programming environments. It has the advantage that you know that whatever you buy from Lego will work with it. Currently it is priced at $144.99.
  • Board of Education  -  I have never used this board. It is based on the Basic Stamp 2 so that means you will be programming in BASIC (booooo!). It has the same nice feature as the VEX, you know anything you buy from Parallax is compatible. The bad is that it is programmed in BASIC and it costs $99.99. You could buy a robot kit version for $159.99 if you are interested in robotics. In fact, their website has lots of cool stuff I think is worth taking a peak at, if you do make sure you check out the Hydra Game Development Kit!
Those are just some of the most popular that I know of. There are more, but most of those are not well suited for beginners. I hope this adequately equips you to go out and purchase the right board. Please leave any comments or questions you have!

Thursday, November 25, 2010

What can a microcontroller do?

Well this is a BIG question. I will start with what I get them to do. First, I use an Arduino Mega to control my robot. It receives input from an ultrasonic sensor and then makes a decision whether or to turn the robot based on the distance to the nearest obstacle. Another thing I am using my microntrollers for is to build a control system for my OWI Edge Robot Arm. The microcontroller receives input from potentiometers on a control system mounted on a user's arm an then mirrors the user's arm position to the robot arm. I also use microcontrollers to drive random LED projects, I can have a cool pattern displaying on an LED matrix or bar graph in no time. 

Microcontrollers have many capabilities and can be used in many applications. There are some simple guidelines you should follow when deciding if a microcontroller is right for the job. You should use a microcontroller if your project:

  • Involves interfacing with the physical world
You should not use a microcontroller if your project:
  • Involves advanced peripherals like USB devices
  • Involves graphics or image processing
  • Requires a lot of memory
  • Requires a lot of CPU speed
If you find you need to interface with the physical word and need all the advanced things then you will need to use a combination of a computer and a microcontroller. This is how a lot of your computer works, instead of your main CPU controlling the rotation of your hard disk, moving the disk head, and reading the data off the disk, it simply sends a request for data to the microcontroller in your hard drive and it sends the data back. You can do this with your projects, you could have your microcontroller recognize commands from your computer and then move a servo. Likewise your computer could recognize data from your microcontroller, you could have your microcontroller send data it processes from a sensor like a accelerometer and the your program running on your computer could react by flipping the screen (iPhone!). 

So to conclude, use a microcontroller to interface the digital world to the physical world! Of course if you need a lot of advanced processing then add a computer! 

Wednesday, November 24, 2010

Getting Started with Microcontrollers

There are several common questions people ask when they begin learning about microcontrollers and I have found that a lot of the answers online to be from very experienced professionals who over think and over complicate the question. So before I become like them I thought i would answer these questions from the point of view of a person who just figured most of this out. So to begin let's list the most common questions I have seen from beginners.
  • What is a microcontroller?
  • What can a microcontroller do?
  • Which microcontroller should I get?
  • Where do I get a microcontroller?
  • How do I program a microcontroller?
  • How do I connect _______ to a microcontroller?
  • How do I take over the world with a microcontroller?
Now the last one I am still working on so I will have to get back to you on that one. But as for the rest I believe I have enough knowledge to answer. So in the next couple blogs i will answer these questions. Now, logically I will begin with the first:
  • What is a microcontroller?
A microcontroller in the most fudamental definition is a computer on a chip, it contains a processor, storage, and programmable GPIO. General Purpose Input/Output are I/O pins that can be set as input or output. Of course this is not all, depending on the microcontroller it may have an ADC, a DAC, UART, I2C, SPI, PWM, a watchdog, and various timers. I am assuming you don't know what all that means so I will explain. 

First, an Analog-to-Digital Converter (ADC) is a nice little gizmo that converts an analog signal into an digital signal. What this means is that you can convert a voltage from a sensor like a potentiometer into a numerical value that your program can then operate upon. A Digital-to-Analog Converter (DAC) does the opposite, it converts a digital signal into an analog one. One application of a digital-to-analog converter is in audio, sound is stored as numbers in memory and is then converted to an analog signal using the DAC. 

The Universal Asynchronous Receiver/Transmitter (UART) is one of the ways you can communicate with your microcontroller. It is through this that you can talk to serial LCDs, USB, and RS232(desktop serial). Inter-Integrated Circuit (I2C) or 2-wire interface is intended for communication between ICs on a single board. I2C has addressing so that 112 nodes can communicate on the same bus, you would use I2C to add EEPROM (more storage) or a DAC to your project. Serial Peripheral Interface Bus (SPI) is a synchronous serial communication connection that is full duplex (two-way communication simultaneously). For example you can use SPI to connect a SD card to your microcontroller. 

Pulse-Width Modulation (PWM) is a way of controlling things such as motors so that you can control speed. But instead of actually changing the amount of power supplied PWM just turns on and off really fast to give that illusion. You would use PWM for motor speed control and LED dimming. The watchdog timer is used by the system to reset the system if the main program freezes. It resets the system if it is not regularly updated by the processor. The other timers are used for things like real time applications. When something must happen by a certain time you would use a timer to ensure it happened on time. 

So all this means is that a microcontroller is a system on a chip that has various ways of communicating to the world. By connecting sensors and mechanical devices to your microcontroller you can begin building interesting systems that can react to the environment, communicate with others, and gather data!

Tuesday, November 23, 2010

Breadboard Sanguino

Today I finally got around to setting up the sample ATmega644(P)s I received from Atmel. Using the Sanguino schematics online I built this breadboard Sanguino.

Now unlike the Breadboard Sanguino on the Sanguino website this circuit i complete with decoupling capacitors, status LEDs, a power circuit, a 16 MHz clock, and a FTDI cable pinout so that I can program it via USB. Once I built the breadboard I had the crazy idea to burn a bootloader onto the ATmega644(P)s via my Arduino Uno... so I did just that.

Due to my stupidity I wasted 2 frustrating hours trying to figure out why I could not get the bootloader onto the chip. It turns out I had forgotten to actually connect the ATmega's Vcc and Ground to the breadboard power rails! *facepalm* Once I corrected that I went bootloader crazy and burned a total of 3 ATmegas ( one 644 and two 644P). I have already programmed the blink sketch from the Arduino Environment onto one of the boards and it worked without any problems. I now have three Sanguinos to use in my projects and a breadboard setup figured out for future microcontrollers. Now that i have a total of 5 functional microcontroller boards ( and one MSP430 that i have no programmer for =/ ) I guess it is time to begin creating cool projects with them... What shall I bring from my mind to reality? A demo robot for my robotics team? Or a Uzebox Open Source Video Game Console? Or possibly give my house intelligence? Read my future blogs and subscribe to me on youtube (mrmacthree) to find out!

Sunday, November 21, 2010


Hello people of the internet! I am beginning this blog in order to share my knowledge with the world. I am a self-taught hacker and I look forward to sharing info on topics such as the BeagleBoard, Programming, Arduino, Robotics, iPhone Development, and Electronics!