pc serial





This tutorial describes how to interface the AX-12 bus to a PC, over a serial connection running at 115,200.

There is a connections list at the bottom, and a comprehensive parts list, with suppliers and links to each part, as well as the costs.

Software

On the software side, you will need a piece of code that will run on the ATmega128, providing a pipeline between one UART (connected to the PC) and the other UART (connected to the AX-12 bus). My brother Dave Hylands has written this piece of code, and you can find the source here, and the binary hex file here. In order to build this interface, you don't need to worry about the source code unless you want to make changes to it. The binary provided works as is.

Hardware

ATmega128

As well as the microcontroller, you'll need some way to talk to it from your PC. If you're like me and you don't have a serial port, or if you just prefer using USB, you can get a USB -> TTL board, from any number of providers. I got mine from HVWTech, because they are Canadian and I know the owner, but Sparkfun is another good place to get them on the US side if that's where you live. I've listed the Sparkfun link in the Parts list at the bottom of this page.

Here's some reference material if you're unsure of what you need, or you want to experiment with something else:

Serial Adapters
Serial Voltages

Whatever you choose, it has to run at 115,200 baud.

You will need some kind of circuit board you can attach both the ATmega128 board to, and the USB -> TTL board. You'll need some kind of power supply - I used a 9.6 volt AA NiMh? pack for R/C cars, with a standard R/C connector. You can get the other side of the R/C plug from most hobby stores that sell R/C cars. Bring your charger with you when you go - you're looking for a plug that is identical to the one on the charger.

Finally, you'll need some way to attach the ATmega128 board to the prototyping board - I used some SIP sockets I had left over from earlier projects. Note that the pins on the ATmega128 board are square molex-header type pins, and thus they won't fit into most SIP sockets. Digikey doesn't seem to have any more in stock, but Mouser carries them (see parts list below for link). They are expensive, but great for this sort of thing. You'll need one 64-pin row for the ATmega128 board, and another for the other pieces.

I went to Radio Shack and picked up a 4.5" x 6" prototyping board to use as the development PCB. I like those boards because (a) they are cheap, and (b) its easy to solder wires in place on the bottom in the place of traces.

I soldered the SIP sockets on the board in the shape of the ATmega128 board pins, including the two special pins inside the square, which you can use to provide unregulated power to the board. Since I'm running this board off a 9.6 volt battery pack, I decided to go ahead and use the on-board regulator on the ATmega128 board. I also soldered a 9-pin SIP socket for the USB -> TTL converter, as well as a couple two-pin SIPs for support. For the Sparkfun board, you would only need a 4-pin SIP for the main connector, plus the two support headers. I also soldered on a two-pin terminal block (which you can get from Radio Shack) to plug the battery into. It doesn't really matter where on the board you solder these things, but I like to have at least 3-4 holes clearance between items when I am prototyping.



Depending on whether you use the USB adapter from HVWTech or Sparkfun, you hook them up differently.

On the HVWTech USB adapter, the Rx & Tx pins are labeled to match the microcontroller, so you would solder a connection wire between the Rx pin of the USB adapter to the Rx pin of UART-0 on the ATmega128 board (pin 2). You would also solder a connection wire between the Tx pin of the USB adapter and the Tx pin of UART-0 on the ATmega128 board (pin 3). Since you're soldering "trace" wires, you actually solder them on the bottom of the board, between the pins from the SIP sockets.

If you're using the Sparkfun USB adapter, the Rx and Tx pins are labeled to match their function, so you would solder a connection wire between the Rx pin of the USB adapter to the Tx pin of UART-0 on the ATmega128 board (pin 3). You would also solder a connection wire between the Tx pin of the USB adapter and the Rx pin of UART-0 on the ATmega128 board (pin 2).

You need to hook the battery power up to the ATmega128 power plug, which is a 2-pin header beside pins 1 and 2 on the inside of the square of pins. You will need to solder a black wire between the pin marked (-) and the negative side of the terminal block (pick one, it doesn't matter which side). Take a black magic marker, and put a mark on that side of the terminal block. That is the side of the terminal block you will plug the black battery cable into. Solder a red wire between the other side of the terminal block and the ATmega128 pin marked (+). Once again, you're soldering on the bottom of the board, to the corresponding pins on the SIP sockets.



Make sure the jumper on top of the ATmega128 board is in place. I've circled it in red in the following image.



Next up, you can solder the bus header in place. The bus header is the 3-pin white connector with pins sticking up inside a shroud. The AX-12 servo wire should be able to plug directly into that header. Position-wise, it should be reasonably close to the battery terminal. When you position it on the board, solder it from the bottom to the pads.



Now solder a black wire from the negative terminal of the battery to the pin on the bus header marked as Ground in the image above. Note the orientation of the header - the small triangles inside can be used to orient the header. The center pin of the header should have a red wire soldered between it and the positive side of the battery plug. The image below shows the battery terminal on the left, and the bus plug on the right, from the bottom.



Next, solder the two-pin header so the pins are lined up with pins 27 and 28, but three or so holes away from the SIP socket. See the labeled image farther up the page, where it is marked as the "UART-1 Jumper". Solder a white wire between each of the two pins on the header and the corresponding UART-1 pin (27 or 28). Then run another white wire from either of those pins (27 or 28) to the empty pin on the Bus header you installed just previous to this. Make sure you slide the jumper onto those two pins from the top, so the Rx and Tx pins become electrically connected or shorted together.







Finally, you need to install the three LEDs. They are connected to pins 35, 36, and 37 of the ATmega128 board. If you look at each LED, you'll see it has a two "legs", which are pins sticking out of the bottom. One of the legs is slightly shorter than the other - this shorter leg is the "negative" side, and its the one we will solder to the microcontroller pin.

Note: If you buy the specific part number I have indicated in the list below, they are "integrated resistor LEDs" and they don't require a current limiting resistor. If you hook up regular LEDs like this, you will probably damage your micro-controller.

So, take the three LEDs, and feed them down through 6 of the holes next to pins 35, 36, and 37, with the short side of the LED closest to the pins.



You can put the three LEDs and cluster them like this, since they are too big to put side by side...



Instead of soldering wires to the LED leads, you can simply bend the LED leads over, with the short side overlapping the pins of the SIP socket, and the long side going out away from there. In this render, I've cut the long leads short, since they are all going to be soldered to a single wire.



Solder the "short" leads to the corresponding pin of the SIP socket, and then lay down a red wire that crosses the "long" side, and then loops around to pin 52. It doesn't hurt to solder the LED pins to the board where they come through from the top, to help hold the LEDs in place securely.



That that, you should be done the soldering portion of this tutorial.

The LEDs are hooked up so that the yellow LED flashes about twice per second (once the ATmega128 is programmed) - that is your heartbeat LED, to let you know that the system has power, and the microcontroller is working. The red LED indicates that the microcontroller is receiving data from the bus, and the green one indicates it is sending data to the bus.

This is what the bottom of my board looked like when I was done.



In this image, red wires are power, black are ground, and white are signal wires.

With the power from the battery connected to the two battery pins on the board, you should be able to program the binary and see the yellow LED flash. If you don't want to buy the programmer, you can look here or here for more options...

Assuming you did buy one of the two programmers listed below, you need to download PonyProg and install it. About half-way down that page is a link to the download page. You should download whatever the latest version is, which is at the bottom of the list. You may have to reboot your machine before it works (I had to). I'm assuming you are running Windows - if you're running Linux, you can probably figure out how to do this stuff yourself.

The first time you run it, you need to do the following:

Calibration (from the Options menu)
Setup (from the Options menu)

When you run setup, choose whether you have the serial or parallel version, and if you are using serial, choose the COM port you have it plugged into. Once you've done that, load the binary file - ATmega128-pc-bioloid.hex using "Open Device File" in the File menu. Go to the "Device" menu, and choose "AVR Micro" and then "ATmega128". Once you've done that, you're ready to program. Plug the cable in to the back of your computer, and the 2x5 header at the other end into the ATmega128 board. The red wire in the ribbon cable should line up with the "1" silkscreen number on the ICSP header on the board.



Plug the battery in, and then execute "Write All" from the "Command" menu. After it is done, you should be able to unplug the battery, disconnect the programmer cable from the ATmega128 board, and then plug the battery back in. You should see the yellow LED start to flash about twice per second.

And that's it. Once you have the ATmega128 programmed, you should be able to plug in a servo, power up the whole thing, and start sending and receiving bytes as described in the AX-12 manual.



Connections:

ATmega128 Board:
pin 2 (UART-0, Rx)Tx pin on USB -> TTL converter
pin 3 (UART-0, Tx)Rx pin on USB -> TTL converter
pin 22 (Ground)Negative side of battery plug
pin 27 (UART-1, Rx)Bus Connection pin 1, UART-1 jumper pin 1
pin 28 (UART-1, Tx)UART-1 jumper pin 2
pin 35 (C0)Negative side (short end) of yellow/green LED
pin 36 (C1)Negative side (short end) of blue LED
pin 37 (C2)Negative side (short end) of red LED (red is for receive)
pin 52 (Vcc)Power for LEDs
pin + (Power +)Positive side of battery plug
pin - (Power -)Negative side of battery plug


USB -> TTL Board:
pin 2 (Rx)Tx pin on UART-0 (pin 2)
pin 3 (Tx)Rx pin on UART-0 (pin 3)
pin 5 (Ground)Negative side of battery plug


Bus Connector:
pin 1 (I/O)UART-1 Rx (pin 27)
pin 2 (Power)Positive side of battery plug
pin 3 (Ground)Negative side of battery plug




Parts List

Radio Shack
Prototyping Board - $4.29
Battery Terminal Block - $2.29
9.6 volt Battery & Charger - $24.99

Local Hobby Store
R/C Battery Connector - $5 (estimated) - must match the one on your charger, and fit into the one on your battery

Mouser
SIP Sockets (need quantity 2) - $16.96 ($8.48 each)
Bus Header - $0.97
LEDs (one of each) Green, Red, Yellow - $1.20, $1.17, $1.20
(note that these specific LEDs are designed to run off 5 volts, so they don't need a current limiting resistor)
2 pin Header - $0.66
2 pin Jumper - $0.15

Sparkfun
ATmega128 - $35.96
Programmer Cable (one of the two) Serial, Parallel - $11.95 each
USB -> TTL - $19.95
USB Cable - $2.95

Total Cost, excluding shipping and tax, is $129.68...

Places to cut costs: Battery & Charger (many people have these already, but must be 9.6 volts), Programmer Cable (see links in text for free programmer examples)

Not included in parts list: Tools (soldering iron, solder, flux, wire stripper), Wire (I use 22 gauge solid core wire)



If you don't have a soldering iron & associated gear, you can get by with this:

Solder - $8.99
Soldering Iron (Cheap) - $22.99
Soldering Flux - $5.99
Wire - $5.99 (three spools (red, green, black) of 22 gauge solid core)

Here's a good page on safety while doing hobbty robotics related work. This is also worth reading if you've never done this type of thing before...

Here's another excellent getting started page. Getting a book like this wouldn't be a bad idea either.



Created by: admin last modification: Tuesday 16 of January, 2007 [21:17:02 UTC] by admin

The original document is available at http://www.bioloid.info/tiki-index.php?page=pc%20serial