PocketMagic

March 22, 2009

Robo Evolution – how to build a better robot

Filed under: Electronics, Hardware, Research, Software — Tags: , , — radumotisan @ 3:51 pm

This topic will try to sum up my work related to robotics, and provide as much pictures an videos as possible for those of you interested in this subject.

Perseus 1, 2005-06-29
General:I’ve worked on this one for about 2 months, with lots of interruptions and having only little continuous work time.
It was my university graduation project and major research work was on artificial vision.
Platform: modified RC truck, with servo controlled direction on front wheels, and geared (weak) motor on back wheels for propulsion.
Hardware: video camera, powered on 2 AA batteries, 2.6GHz video transceiver powered on 8xAA batteries, original car 35MHz RC control board connected to car’s motors running on 4xAA batteries, remote PC running custom image processing software, that I’ve created at that time.
Block Schematics:

Functionality:
The performance was very good, the robot being capable of recognizing and following a laser spot projected in front of it (in the camera’s view port).
Here are a few pictures of the robot vision itself:

Pictures

Resources:
Front cover of my license work: cover.pdf
Snapshot of desktop application:

Perseus 2, 2007-12-04
General: in an attempt of continuing the perseus 1 project, the first improvement I’ve tried was to eliminate the need for a remote computer
Platform:
modified RC truck, with servo controlled direction on front wheels, and geared (weak) motor on back wheels for propulsion.
Hardware:
Mini ITX D201GLY2 motherboard with 1.3GHz Celeron CPU, 512MB RAM, IDE2CF and CF2SDCard adaptors for a 2GB SDCard based DOC (disk on chip), M2-ATX DC-DC PC power supply 160W, 4×8 AA rechargeable batteries connected for 10.4V @ 10.4Ah .
Block Schematics:

Functionality:
This design was a failure. The heavy batteries overloaded the motors, and the original H Bridge circuit transistors vaporized. The platform is too weak for the robot’s mass.
Additional problems: motherboard resets when motors are triggered since there is only one common power source. Some high capacitors or separate power sources would have solved this.
project was abandoned – seeking for a better platform.
Pictures

TwinMotion 1, 2009-03-01
General: Since I needed a stronger platform, but didn’t want to spend 300-400$ on commercial offers, I’ve built my own, strong, customizable robot platform FROM SCRATCH!
Platform: Big 28 cm diameter light wooden wheels, two geared (30rpm) strong motors , some metal pieces and screws. To fix the wheels on the motor-heads, I’ve created a custom bearing, out of some tick small diameter metal pipe.

Hardware: Robot “brain” under development, currently I’ve used it with my AtMega8 H-Bridged board, available here.
Block Schematics: Not yet available.
Functionality: Not yet available.
Pictures and videos




This video shows the platform in action, controlled by a simple ATMega8 microcontroller brain, that was only giving simple movement commands : forward x cm, turn left, move backwards x cm, turn left/right, etc.

TwinMotion update #1, 2009-03-22
General: Wheels needed better adjustment on motor axis, and I’ve decided to add a third wheel for stability, since running on two wheel can make the fixed-body turn upside down – and would create problems when using various environment sensors.
Platform:
A third wheel has been added.
Hardware: Currently the experimental setup is running on the same Atmega8 board.
Pictures and videos
Here’s a demo showing this platform, you can easily see how powerful it is, considering the complete setup is ~2 Kg weight.

To be continued…
Radu Motisan

A simple H-Bridge design

Filed under: Electronics, Hardware — Tags: , , — radumotisan @ 1:23 pm

Normally I wouldn’t a topic about such a simple device, but since there are many sites offering wrong information (for eg. this one short circuits your power source), I had to do it.

An H-bridge is an electronic circuit which enables a voltage to be applied across a load in either direction. If you need to learn more, read here.

Now, assuming you know what a hbridge is, let’s choose a topology for our implementation. You already know we’ll be needing transistors or mosfets (if not, please read the docs above), what you might not know is that these transistors will have to handle a high enough currents, especially when the motors they control are overloaded.

Some time ago, I’ve build a robot on a RC-truck, the load was so high because of the heavy batteries, that when the motors got the command to move forward they overheated and died.

So it’s important to use heat sinks, to dissipate the heat. So, for a h-bridge we will be needing 4 transistors, working in pairs at a time. If we use 2xPNPs and 2xNPNs we can have common collectors, and so, using a single heatsink per pair. For the topology this is the only requirement I will impose, and here is one possibility:

You will need to place the left side MJE2955 and MJE3055 on the same heatsink since they have common collectors. A separate heat sink for the right size transistors must be used.

These components support up to 10A current, so they will work well for small to medium motors.
Remember, a H-Bridge only controls 1 motor. So if you’ll need to driver the servo motor and also one main, propulsion motor you will need two separate h-bridges.

Here are some of the h-bridges I’ve created. On a board I usually create 2, since I mostly use 2 motored robots.

And here is a nice board having an ATMega8, a MAX232 for serial communication with a PC, and two h-bridges for controlling two big gear motors. Again I’ve used MJE2955/3055 pairs, but feel free to use any transistors/mosfets you have.

It runs well and it doesn’t heat up much. In case anyone needs further details on how this works, or other things like why we need the D1-D4 diodes, feel free to ask.

Also the R3,R4 resistors can be adjusted to suit your needs. For me, they are used to limit even further the current given by the microcontroller on the output control pins. Not really required in my case.

Radu Motisan

March 1, 2009

ATMega8 and DS18B20 (digital temperature sensor)

Filed under: Electronics, Hardware — Tags: , , , , , — radumotisan @ 1:29 pm

“The DS18B20 Digital Thermometer provides 9 to 12–bit centigrade temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and gound) for communication with a central microprocessor. It has an operating temperature range of –55°C to +125°C and is accurate to +-0.5°C over the range of –10°C to +85°C. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.” Read more about this sensor, here.

Since I had two DS18B20 sitting among my other electronic components, I’ve decided to hook one up to my ATMega8 test board and see if I manage to get some temperature readings. One wire to a microcontroller’s pin, and two other wires for 5V power.

Now we’re ready to go… well not quite, this is a digital sensor and first we need to understand the way it communicates.

I’ve also found some good resources online here. If the link doesn’t work for you, see the attached PDF.

Here’s my source code, to get you started right away:
atmega8_lcd_temp.zip

Bottom line, this sensor offer some impressive results, and works very well. It is a good addition to any microcontroller board for gathering some extra environment parameters, and all at the expense of a single PIN on the microchip.

Radu Motisan

February 13, 2009

ATmega8 and 2×16 HD44780 LCD

Filed under: Electronics, Hardware, Uncategorized — Tags: , , , — radumotisan @ 4:43 pm

Following my first article on the initial findings and results of my tests on the ATMega8, this article will show basic steps on how to connect a 2×16 characters LCD to the micro chip.

The reason for this is to have a way of debugging the microchip functionality, to output the results, the data and various other stuff. I can tell you this is a must have.

To use a minimum of I/O pins, I’ve decided to build a 4bit interface with the LCD. The hard part was to write the code, but finally after fixing several bugs and reading a lot of HD44780 documentation, I can say that I’ve completed a nice flexible code – meaning that you can easily configure the LCD pin connection.

The wiring diagram is below:

The code interface is also attached, not much to say about it here, since it’s full of technical details and bit-wise operations, but if anyone has questions feel free to use the comments form at the bottom.
To edit some parameters like frequency or PIN connections (you can change the I/O pins used by the LCD on the ATMega), have a look in lcd.h . Zip attached:
atmega8-lcd

Function lcd_string2 is very useful for outputting text, since it supports variable parameters similar to printf. So you can use it for outputting misc content: lcd_string2(“Hello World! %d\npocketmagic.net”,i);

Here are some pictures with my LCD running:

Next thing to do is to start connecting various sensors.

Radu Motisan

February 11, 2009

First steps with micro controllers (ATMega8)

Filed under: Electronics, Hardware — Tags: , , — radumotisan @ 5:33 pm
Purpose of this article:
1) to learn how to connect the Micro controller in a simple circuit and how to power it
2) to see how to create a simple programmer (a device to connect the micro controller to a PC for uploading software)
3) to present a simple software program in C that controls a series of LEDS
4) to show everything in action
Note: its my first time when I’m working with micro controllers. The info presented here might be inexact, but not incorrect, since I will stick to my findings and to the easy path for a beginner.
All that is presented below was the result of one day of reading, soldering, testing – a good score I would say.

Short Intro and Motivation
Since I’m a C++ developer for Embedded Devices, small processing units were always a strong point of interest for me. Furthermore, building a robot for my bachelor degree, a few years ago, required getting over serious hardware limitations related to power consumption and weight. So I’m still looking for a way to perfect my robot, and to extend its functionality, and the microcontrollers look like a very interesting approach, to say the least.

For a start, I had two micro controllers at hand: the popular ATMega8-16PU and the not-so-popular PIC24FJ64GA002. The first one I’ve bought on Ebay from a very good seller in Thailand:

For this article I will be targeting the ATMega8, since it gave me excellent results, thanks to available documentation. Can’t say the same about the PIC.

So let’s start:

Our first ATMega8 circuit
The ATMega8 is an excellent micro controller:

28 PINS (23 for Input/Output !!!)
8-Kbyte self-programming Flash Program Memory
1-Kbyte SRAM
512 Byte EEPROM
6 or 8 Channel 10-bit A/D-converter
Up to 16 MIPS throughput at 16 Mhz
2.7 – 5.5 Volt operation
Its datasheet is available here

I suggest you download the ATMega8 image to the left and print it, since you will need it often to consult the PIN layout when doing your circuit.

The Input/Output pins are important when it comes to how many devices you want to connect/control/use. To control a simple LED you will need to use 1 PIN (for output). To control a temperature sensor, you will need another PIN (for input).

To do a simple circuit and power the micro controller, first thing you need to know is that you need a stable 5V power source. The best way to achieve this is to use a regulator like the 7905/7805. This component has constant output regardless of the input current – in regards to some given boundaries, of course.
Here is the circuit. I suggest you use sockets for the ATMega8, to easily change your chip on your board.

By implementing the schematics above, you’ll have the microchip powered. But you’ll need to program it in order to have a useful result.

A parallel programmer for the ATMega 8
A programmer is a hardware interface that connects the micro controller to a PC.
On the PC you create a software program, that you can then upload to the ATMega8 using the programmer. It’s quite simple.

To make things easier, I’ll describe how you can create a parallel programmer, but this will work for you only if your computer has a parallel port since that’s where you need to connect it. If it doesn’t, you can purchase an USB2Parallel adapter or build an USB Programmer directly (you can use this)

For the parallel programmer you’ll need a LPT 25pin connector and 4×470 Ohm resistors. This is the way you need to make the connections for the BSD type parallel programmer:

Here’s how I’ve managed to set it up:

Writing the software
Let’s try something simple – like controlling a LED on/off.
For this, we need to attach the led to any of the ATMega8′s available I/O pins.
I’ll use Pin 28 named PC5. This pin is part of the PORTC set of 7 pins PC0 – PC6. Notice there are other sets of pins like PORTB (PB0-PB7) and PORTD (PD0-PD7).

So the wiring is like this:

Next you’ll need a C compiler for the ATMega8 and a software programmer that will upload the compiled code to the micro controller.
For the compiler I’ve used AVR Studio from ATmel. Download the 3 files below and install them in the given order (the avr studio itself and 2 additional service packs):
1 AVR Studio, version 4.13, build 528 (73.8mb)
2 AVR Studio 4.13 SP1 (build 557) (37mb)
3 AVR Studio 4.13 SP2 (build 571) (45mb)

For the uploader I’ve used AVRDude that comes with the WinAVR package:
WinAVR

As soon as you’ve installed everything, start AVR Studio. You’ll get a page like this:

Click on “New Project”, and select AVR GCC, then add a project name “TestLED” and select a location to store the new project’s files:

Click Next, and in this new page you can select “AVR Simulator” and to the right under Device, select ATMega8 as show below:

Simply press Finish, and you can start writing code:

First things we need to know:
#include
Will include this library in our project so we can access basic Input/Output functions and macros.

int main() is the entry point of our program, here is where the program execution starts.

So, first thing to do is to set the PORTC as output. For this we’ll use a special register named DDRC:
DDRC = 0×20;

why 0×20? Let’s have a look in binary:

PC6 PC5 PC4 PC3 PC2 PC1 PC0
0 1 0 0 0 0 0

Basically we set a value of 1 to the position associated with our target pin.
To set all pins to output, the value would have been:
DDRC = 0x7F (in binary: 1111111)

To control other ports (B or D) you can use DDRB or DDRD in a similar way. At this point you should consult the micro controller’s datasheet available here.

Next thing to do is to turn the led on and off by code. We want this in an infinite loop, so here’s the approach:
DDRC = 0×20; //PC5 set to output
while (1) //forever
{
PORTC = 0×20; //set PC5 on . again computed in binary
delay_cycles(1000); //a short delay to keep led on
PORTC = 0; //all C Pins off
delay_cycles(1000); //a short delay to keep led off
}

An even better approach that doesn’t interfere with other PORTC pin’s settings would be:
DDRC |= 0×20;
while(1)
{
PORTC |= 0×20; //set 1 on first position, or simpler: PORTC = 0×20;
waitd();
PORTC &= 0x5F; //remove position 5 value, or simpler: PORTC = 0×0;
waitd();
}

You can download my code here:
testled.zip

After the code is ready, press Build in the menu. It will produce a .hex file, in this case testled.hex
Go to WinAVR folder, and enter the BIN subfolder. Copy testled.hex here and make sure your parallel programmer is connected.
Type in this command:
avrdude -p atmega8 -c bsd -U flash:w:testled.hex:i
If everything goes right, you will see a progress bar indicating the code upload to the micro controller:

As soon as the software is uploaded, the code will be automatically executed.
Sometimes you might need to disconnect your parallel programmer after the code has been uploaded!

Here’s my ATMega8 micro controller and several leds connected to multiple I/O pins:


Hope you find this useful. Thanks go to:
elforum.ro and the good people there
Society of Robots tutorials
CrazyTB’s blog

I’ve already built a very stable and flexible 4bit HD44780 LCD interface for the ATMega8, so stay tuned for the next article.

Radu Motisan

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.