Serial Communication

Serial Communication

I know I was supposed to talk about the power supply schematic, and I promise I will get to that. Right now I plan to talk about serial communications between two microcontrollers and the outside world. Since I decided to go with 2 microcontrollers for my new mini sumo board, I realized they needed to communicate. There were several choices that could be used. You have the USART, SPI, and I2C/TWI ports on the AVR. Each serial comm port has its uses and issues.

USART

USART stands for universal synchronous/asynchronous receiver/transmitter. The USART (or UART) was a serial communications port that used to come with your computer, though that has mostly been replaced with USB. The USART is some times called RS-232. Really RS-232 is an electrical specification that also specifies a connector. The USART was either an external chip or hardware built into the microcontroller. I could go through the entire history of the USART and RS-232, but I won’t. That is information you can look up on your own if you want it. These days you will use a USB to Serial port  converter or bridge IC. One end will plug into your computer, while the other will connect to your micro. This is the interface I’ll use for my board to talk to my PC. As I start working on the software development, I will revisit this interface.

SPI

SPI or the serial peripheral interface was designed to allow microcontrollers with limited numbers of pins to control external peripherals like I/O ports and serial EEPROM. Where the USART was normally used for computers to talk back and forth, the SPI bus was mainly used in a master and slave configuration. The microcontroller was the master and the peripheral was the slave. This allowed the designer a way to save pins on their microcontroller, which can be a limited resource. Since the microcontroller typically has all the required hardware, you can make the chip either a master or a slave depending on the needs of the design.

I2C/TWI

I2C/TWI is a serial communications interface originally designed by Philips (now NXP Semiconductor). I2C stands for Inter-Integrated Circuit bus. Where as the name I2C is copy written, TWI (two wire interface) is not, so many semiconductor companies use TWI to mean I2C because of licensing issues. None of that is really important here. Just remember that when I write I2C, I also mean TWI.

The I2C interface was designed from the beginning to be a multi-master bus. This meant several masters and slaves could share the simple two wire communications bus. This bus also has electrical specifications you need to be aware of. Most importantly is that the data and clock lines need pull up resistors. The value of these resistors is dependant on how strong of a pull up you need and capacitive loading on the signal lines.

OK, so…

Wireless radio module

XBee Pro Radio Module

Why am I going over all of this, so you can understand why I designed the circuits the way I did. I am planning to use the USART for communication back to a PC. Wireless communication could also be used. One of the most popular is the XBee radios. This would give you a way to send data back and forth between your computer and microcontroller without wires. The software overhead of communicating with the USART is minimal, around 100 bytes. Software is not the issue, just the fact I am using this interface to talk with a computer means I will have to use one of my other options. So how about using the SPI bus to talk between the micros? Again the amount of software over head is small. The issue is that the SPI port is also the in circuit programming interface. This complicates programming the devices individually, requiring some extra hardware. I will have to explore this a little more. That leaves the I2C port. The hardware requirements are not an issue, so this looks like a good idea. The only issue is the software, it requires a greater amount of code to handle the internal hardware. That could be an issue for flash limited devices.

So as I look at the problem in front of me, what I really need to do is write some code to test the 3 serial busses between a mega328 and a tiny24 micro. This way I can figure out which interface to use. This is also going to need some reading of the data sheet of the tiny24 as it has USI (universal serial interface) which is all 3 interfaces combined into one module in the micro. So much for things being easy.

So I am off to do some coding to test the serial busses. Then I can work on finishing the schematic and finally present the power supply and the rest of the electronics. Until then I hope this has been informative.

Brain Design

Microcontroller

Atmel microcontroller atmega328

An Atmel ATmega328 microcontroller

Last time I said I was going to use 2 microcontrollers – a mega328 and a tiny24. If I feel like I am going to run out of code space on the tiny24, I can quickly swap it out for tiny44 or 84. The surface mount vs. through hole debate has morphed into “why not both”. The schematic will be the same for both, just the PCB layout will be different.

Serial Port

Having a USB port would be nice, but it is not a main requirement. Neither is having an RS-232 level serial port. I can get by with a TTL level serial port. I have USB to serial port adapters that provide RS-232 and TTL voltage levels. I will think about these some more.

Driving Motors

motor driver circuit board for an Arduino

Sparkfun Motor Shield

One of the big decisions to make is about a motor driver. The design of my first robot brain had headers to plug-in a motor driver daughter board. Sparkfun makes a motor shield for the Arduino that plugs in as a daughter board. The issue that comes up is how much prototyping space do I want. If I leave off the motor driver circuit, then I leave myself a larger area for prototyping. Then again I could include the motor driver and make a prototype expansion board. Pololu makes the 3pi robot and they offer an expansion board that mounts on top to give you a good-sized prototyping area. The 3pi has a cool look to it when the expansion board is mounted. It is a good idea to give yourself some area to experiment with. I like to add a few LEDs for debugging purposes or other circuitry for more functions.

Pololu 3pi robot with expansion board mounted on top

A Pololu 3pi with expansion board mounted

So if I put the driver circuit on the main board, which motor driver should I use? I can use the old standby chips like the L293D/SN754410, the L298, a pair of LMD18200Ts, or a FAN8200 if I could find them. These are bipolar transistor parts that have a voltage drop and a bit of current draw while conducting. Looking into MOSFET drivers appeals to me for the lower voltage drop and less current wasted while driving motors. I could use something like a TC4427 or more exotic parts from Allegro and Freescale. They make motor driver chips with extra features. I just have to decide which components I want to use. Either way I have decided that like the Pololu 3pi robot, I will have a separate expansion board for prototyping. This way I can plug it in only when I need to and the robot’s main circuit board does not have to change.

So I still have a few more things to think about. Next time I will go through the pros and cons of having the motor driver circuit on the main controller board. I will also post a few more pictures and details on my current mini sumo robots. At some point talking about the software tools will come up. Schematics, PCB layout, and parts lists are going to be required at some point. Check back for the next exciting article, or at the very least better than average.

AVR Overview – Hardware

Hardware

This time I am going to discuss hardware platforms, mainly where you can get them. There are many vendors where you can get board with an AVR micro on it. I am just going to mention a few that I have dealt with before. I am going to move quick, so I hope you can keep up.

Atmel

I am going to start with Atmel. Through Digikey, Atmel sells the AVR Butterfly. The Butterfly has a mega169V micro, a LCD, joystick, and tons of I/O. The board runs about $20 from Digikey. If you read the magazine Nuts & Volts, you might have seen the articles “Smiley’s Workshop”. He uses the Butterfly to teach C programming for the AVR. I recommend you check out the articles.

Pololu

Pololu is another vendor, and a great place to get robotic parts. They carry a line of sensors, motor drivers, motor controllers, and AVR microcontroller boards. Their Orangutan series of boards range from small 24 pin DIP modules to large multi-micro/multi-board designs. So take a look around Pololu’s web site, you won’t be disappointed.

Sparkfun

All I can say about Sparkfun is WOW! They have more electronic offerings than I can mention. They have a long list of AVR development boards along with other microcontrollers. You will just have to check out there site to see everything.

Wright Hobbies

Wright Hobbies is a smaller supplier of electronics. They have 2 different boards for sale. The first is the M32 DevBoard. It uses the mega32 micro. All of the pins are brought out to headers. The second board is the Chibots Controller board. This board was developed by the owner Eddy Wright for Chibots – the Chicago Area Robotics Group. The Chibot Controller carries a mega48 and a motor driver. The board was designed for some of the simpler robotic games held by Chibots. We will hear more about Wright Hobbies in later articles.

Megabitty

The Megabitty is a very small 1″ square microcontroller board with dual 500mA motor drivers. The chip is a mega8, but could be replaced with a mega48/88/168/328 as they all use the same pin out. You will have to check the Megabitty web site to see where to buy the kit.

Arduino/Freeduino

Un Arduino Diecimila

Image via Wikipedia

I decided to lump these together because they are similar boards. In fact there are many copies of the Arduino platform that you could buy, one of them being the Freeduino. First place to look up information on Arduino is the web site. The Arduino is supported by a very large community committed to the platform. Arduino is a board and a programming environment. The resources are too numerous to list here, so I just suggest doing a search in your favorite search engine, for Arduino.

Next Time…

There are many more options out there, but since I plan to build my own. I will leave the rest of the searching up to you. Next time I am going to talk about programmers and debuggers.

Project Ideas

So some of the electronic project ideas I have had are:

  1. New brain and motor driver board for my Mini Sumo robot
  2. SD card interface to an AVR microcontroller
  3. A DDS Function Generator that can go up to 10MHz
  4. A vision system based off of an Analog Devices Blackfin 531/32/33 DSP
  5. A robot brain for a Hexapod robot
  6. Finally, a CPLD/FPGA experimenter board

I know some of my ideas are robotics related, but as you notice not all of them are. The function generator is just a piece of test equipment I want to build, where as the CPLD/FPGA experimenter’s board is just so I can play around with those devices.

The first thing I am going to be working on is my new brain for my mini sumo ‘bot. The current plan is to use an Atmel mega328 (compatible with Arduino) as the main controller, and maybe add a second controller that only handles the IR object detectors and reports back to the ‘328. Then I need to pick a motor driver chip, and decide if I want to use surface mount or through hole parts. If I go surface mount and other people like my design, they might not be able to build it. If I use all through hole, anyone could build it. I could even go as far as to make it a kit. Then again a surface mount board just looks high-tech and has that “Cool!” or “Wow!” factor. This is something I will have to think about.

Well I just want this to be a quick post, so I am ending it here.