subota, 13. listopada 2012.

AVR SERVO PROJECT

AVR SERVO PROJECT  WITH LEGO DUPLO

After this project I can enyoy playing with AVR and with my son at the same time.
Isn't that perfect?

There is a great selection of Lego  Technic or even Mastermind availible. I personally think these are great toys for both education and entertainment. However, I like to make things my way, and also still need DUPLO size for my son (3+)!






EXPLANATION

How and what I did with pictures

STEP 1: Carving a DUPLO Brick and mounting a servo


The material of Lego is actually very nice for modelling. The skalpel or any knife can be used for initial carving. After that centre part can be milled by some kind of grinding tool.


Surely it can easily be done aesthetically better, but it fits perfectly even without a glue. One can also add some glue, while I like it to be more flexible (replacement etc.)

 STEP 2: How to control the servo ?

Servo actuator is not really just the motor. In this case it is a complex system capable of holding the position we want very precisely, and moving arround as we command it. Inside the package there are: Electrical motor, high ratio gearbox, position measuring device and the control circuit. There are three wires coming out of a servo like this: Ground, +5V and signal line.

I did not like the way servos are controlled until I actually tried it. 

One thing is sure - you won't be able to control servo without some kind of external control circuit. Micro-controllers are the most reasonable way of controlling a servo. They work perfectly as a pair.

For all my projects I use AVR. For this project I used both Atmega8 and Atmega32, but any other suitable uC can be used. Take a look at the mess of my control circuit:


It is not completely visible, since I packet it all inside a butter box.

The reason why to use micro-controller is the following: Servos need a PWM signal for setting the angle reference, and with uC you can very easily create PWM signal.

PWM stands for Pulse Width Modulation, and although it might not sound simple, it is not a very complicated concept. In this case, it means that servo will expect to be ticked in 20 ms (miliseconds) intervals at signal line. If not, it will simply not work. The angle is controlled by a duration of these impulses. Typically, a duration of 1 - 2 ms will mean a variation of let's say 180 degrees. For example, if you give an impulse of 1 ms every 20 ms servo will position itself at 100 °. If you give an 1.5 ms impulse it will position at 130 °. This concept is great because it gives you the possibility to virtually change the position every 20 ms. That's the frequency of 50 Hz by the way.

In micro-controller you can do this in two ways: Using PWM with 20 ms period (recommended) or manually using a simple delay functions. PWM method is neat because micro-controllers can do it automatically in the background, and it will not affect the rest of the program.

Here is the basic principle:
 STEP 3: Programming the controller

I do not plan to go to the details of PWM programming, becouse many people already did that. There are some very useful links for this matter at the end of this post.
However, I'll post the C code here only to show how simple it is:



The code is made for: AVR , Clock frequency F_CPU = 1 MHz

If you ignore the complicated setup for registers (you can always just copy it), it is possible to setup the position by simply setting OCR1A. 1180 means 90 ° and 2050 means 180 °. you can also set other values. Usually, OCR1A values need to be adjusted by experimenting for different servo models.

 STEP 4: Applications -- Finally!

Example 1: Brick lifter tractor


Example 2: The ramp


Example 3: The creepy bear


These examples are best seen in action on the video. Check it out here

First two examples are controlled as described. Third one is different, the position is proportional to analog input connected to accelerometer module. That way the hand follows motions of the module.

Anyway, servos are great devices, and except of these examples showing playing with them, they can be used in many serious applications. There are a few models available for under 4 $, and so far I haven't managed to destroy a single one, meaning they are also durable. I recommend trying to use servo to anyone interested.

SOME TECHNICAL DATA:

Servo motor:                                      9G
Servo Stall Torque at 4.8 V:           1.2 kg/cm (16.7 oz/in)
Servo speed at 4.8 V (no load):     0.12 sec / 60 °            
Micro-controller:                              Atmega8, Atmega32


REFERENCES:

EXTREME ELECTRONICS - SERVO MOTOR CONTROL

SOCIETY OF ROBOTS - PWM TUTORIAL

These two references and a basic knowledge in Micro-controllers are all you need to start working with servos.

If you have some questions about overall concept I'd be glad to answer.
vpsus@yahoo.com

četvrtak, 30. kolovoza 2012.

ATMEGA ROBOJEEP


I'd like to share this little project, comprising of some interesting concepts. After learning a few things about microcontrollers and some peripherals, I wanted to finally create something that can move. Being short of time, I have chosen as simple solution as possible, and that was using one of my son's toys for my project.
Even before I wanted to use computer to program some actions, not only in software. This can also be called a simple robotic project, but let's leave that for some other. If you want to control something "live" with your computer wireless or wired, this is one of the good ways to do it. 

You can see it in action, here is the video:

             YOUTUBE VIDEO


I will present making of and principles in a few steps:

First of all, some technical data if someone is interested:
       Used Vehicle:                   Jeep (Nikko)
       Microcontroller:            Atmega32 (AVR)
       DC Motor driver IC:      L293D
       Bluetooth module:        BC417143 
       On board LCD:               HD47780 20x16                        

 1. Disassembly of existing vehicle and preparation works

Not much of a craft, but it is good to have a good vehicle like this one. Here are a few photos from the start:

I decided to remove the complete original electronic interface. Original Jeep used 4 1.5 V batteries, taking two series, +3 V and - 3V out for forward and reverse motor direction. I took out only GND and +6V, as I have a special driver IC able to reverse the voltage. Of course, it is also needed to take out two motor leads.

2. Preparing the equipement

For my project's I usually use proto-boards, or specially designed universal board. I made this board myself for other purposes, but anything else with an uC on it can be used. Check out my References chapter at the end for details and interesting sources.

The setup in general

Bluetooth way of communication is chosen becouse it gives a very simple way of communication between devices in both directions. And the magic simple way is called UART. This name is related with serial communication by two wires (Tx Rx). This is used not only on serial RS232 port on computer, but also in industrial communication, with a similar protocol, only the equipement is a little bit more expensive. Bluetooth makes Tx and Rx wireless, not endangering the simplicity. Besides, almost every laptop or mobile phone uses a bluetooth.

I bought a 3.3V BC417143 based Bluetooth module, which I had to prepare for 5V levels used with ATmega32A. I suggest getting already prepared 5 V version.

Motor driver chip is L293D. One IC can handle 2 motors (starting and reversing), and is simple enough and cheap. It had been attached to protoboard on Jeep's hood. I suggest to use some of Reference links below to find out how it works.

In the video, you will see one wire coming out from the Jeep. At that moment I could not get enough power from my batteries, since I need at least 8 V at my regulator to get constant 5 V. Additional battery pack shall be attached to existing 5 V to achieve that, and at the time I could not connect all this so I just used "powerfull" wall adapter to get steady 9V. 12 V battery could also be used.

When everything is assembled, the Robo Jeep looks like this: 

3. Programming, testing, getting it to work

It is preety obvious that this is the hardest part. However, since today there are a great sources online, it is only hard to learn how to use them. AVR is used here, but any other uC might be used for this. I use AVR with free AVR Studio from Atmel. DC motor driver is hardwired to uC with three wires. Two of them determine the direction, and one enables the motor. I also implemented PWM for speed regulation here, but it can also work without it (ON/OFF).

I also added HD47780 LCD display to this project only because it helps me to debug while programming, but later I used it do display messages sent from the laptop which is pretty neat. I suggest using such a debugging method, but it is optional.

So first I tested everything without any communication just to see how motor driver works. 

4. Communication

Communication with the vehicle is actually the main task of this project. As allready mentioned it is done trough UART. The great thing about it is that UART function is embedded in many devices like micro controllers, computer COM ports, bluetooth devices. That makes using it more simpler, and hardware more usable and stable. Below is the diagram of the way devices are interconnected here.

Using UART it is possible to send some messages from one side to the other. Transmission is secured and monitored by hardware and works automatically. In this case, bluetooth adapter serves only as a bridge between computer and controller. The same could be done by connecting wires directly to the computer, using USB to UART converter for example. A good way of data can be transmitted this way, but in this project only some characters are sent, or a few words.

Generally, when you have UART ready you can use hyper terminal to send commands from the computer. For example you send F, and it means move forward for a part of second. FFFF would mean move forward a few times and similar. Also some special codes can be used to send message to display like ? Hello word sent means display Hello on LCD. This is the way it is done here. But if you want something nicer than typing commands you can also create a graphical interface. When you don't want to use special compilers like visual studio, you can use this trick: Use VBA - visual basic for aplications. That way I made the interface in Microsoft Power Point using VBA. It looks like this:


VBA programming is not very complicated, but in case like this you do need to find some specfic functions somewhere, or create it yourself.

This is all I will say about this project. It can be infinitely modified and enacted for many functions and purposes. It's purposes is only to demonstrate how this can work, and to relax a bit from some more complicated implementations. And by the way, this is my first blog ever, so I might have written too much, but I hope this is helpful to someone.
 

4. References

These references also serve as a thanks to all the great experts  from which I learned so much.

DAHRMANITECH  -    DESIGN WITH MICROCONTROLLERS 

EXTREME ELECTRONICS - L293D  -- For DC motor control using L293D

EMCELETTRONICA - VBA UART  


5. Additional functionallity

Clearly, many additional functions and devices can be added to a project like this. For example, later I connected a servo motor and created a bluetooh controlled ramp (tollgate). My son had a wery neat new toy! Here is the photo:

 
And this is a nice site for instructions how to use a servo:

EXTREME ELECTRONICS - SERVO

And by the way, servos are really great devices to use with micro controllers. Even the cheapest ones from ebay work nice. I have tried 9G so far, and it's just fine!

                                                             vpsus@yahoo.com