It’s done! The first goal is achieved! The Dagu is self-sufficient! …  Arduino controlled

http://www.youtube.com/watch?v=qFTJShisqRg

Advertisements

The secret of the servo control

To use a servo with the Arduino, you have two possibilities. You can use the servo library, or you control the servo with your own code. But to write your code, you need to know the basics, how a servo works.
There are two facts: The cycle or refresh time and the pulse width.

The cycle or refresh time.
It’s not enough to send a position value to the servo. You must do this over and over again! If you don’t do this the servo forget the actually position and start to move. The normal cycle or refresh time is 25 ms (some sources in the internet say 20 ms). Each 25 ms you must send the position value.

The pulse width.
With the pulse width you tell the servo the position you want.
The longer the pulse, the longer moves the servo. Different servos has different values, but they are similar.
The path of movement is left (short way)- middle – right (long way). So are also the pulse width values. You reach the left position with 500 µs, the middle position with 1500 µs and the right position with 3000 µs pulse width.
The pulse width to reach the middle position is always 1500 µs. But the other two values are different, depending of the type of servo. So it’s possible you starts with 700 µs and ends with 2700 µs or earlier. You should test it.

 

servo_position

The HC-SR04 problem is solved!

Ok, a look at the HC-SR04 datasheet explains and solves the problem.

The speed of ultra sonic is 343 m/s. To measure a distance from 1m, it’s need round about 6 milliSeconds (actually there are two meter, one meter to the destination and one meter back).

So we need a special time for one measurement cycle and we are not able to make as many measurements per second as we want.
The HC-SR04 datasheet shows us the measurement cycle and the cycle time.
 
HC-SR04_datasheet

The cycle time must be less than 16 Hz. This is not possible with Timer0 and Timer2. Both timer are 8 Bit, and with a prescaler of 1024 we get as slowest frequence 61 Hz (16.000.000 / 1024*256). Therefore we need to use Timer1 if we want to measure permanently.

Here an example for a measurement function:

void Eyes_measurement() {
  digitalWrite(Eyes_Trigger,LOW);        // to be sure the Trigger is down
  delayMicroseconds(2);
  digitalWrite(Eyes_Trigger,HIGH);       // start a measurement
  delayMicroseconds(10);
  digitalWrite(Eyes_Trigger,LOW);        
  pulsdauer = pulseIn(Eyes_Echo,HIGH);   // get the result
  distance = pulsdauer / 58;             // value in cm
}

A bad day yesterday!
I tried to optimize the “The little One” code, but it was not successfully. I got a timing problem. To use the interrupt timer2 for the ultra sonic, the frequence is to high, also with a prescaler of 1024. But timer 1 is current in use …

The little one was born!

I’ll start a new project.

At first, the new project should be an LED cube. An 4x4x4 LED cube with red LEDs. There are amazing videos with great effects on youtube. The preparations are finished already, the sketch are designed.

But now, I found Dagu, a rover 5 robot platform. I would start this project in summer 2014. But now I can’t wait so long!