and i'm trying to get a lateral movement perception control and put the signal outpu from the gyro directly in the analog input of the arduino board...but can't get any changing value !!
i use this code :
/////////////////////////////////////////////////
int gyroIN=0;
That gyro does provide it output through pulses like those sent to a servo, in fact the output is designed to drive a servo. To get information from it you need to measure the pulse width. Have a search for the pulseIn command. You can also find a more complex method for reading the value using interrupts mentioned in this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1201890734/12
you mentioned your trying to get a lateral movement info, note that gyro outputs a signal that is proportional to rotationial movement. You may need to think about a different kind of sensor for lateral movement
i testing with the pulseIn commande, but i don't understand the result.
the gyro give in retour incoherant value between 1060 and 20000.... and somtime it's freezing for 2 or 3 second...
what's wrong with it ?
any idea?
this is the code i use for the pulseIn function .
/*
read signal from gyro
*/
int gyroPin = 4; // gyro input
int falsPinConnection = 5 ; // fals signal for initialise the gyro
unsigned long Duration; // gyro value
int refraichissement=20;
int lastPulse=0;
//int iRange = 1024; //range for value
//int iLeft = 1200; // value min (don't konw now this value)
//int iRight = 500; // value max (don't konw now this value)
void setup() {
beginSerial(9600);
pinMode(gyroPin, INPUT);
pinMode(falsPinConnection,OUTPUT); // nead by gyro
digitalWrite(falsPinConnection,HIGH); // for initialise it
}
// function for controling servo with pulse, using for send intial pulse to gyro
void controlServo(int angle,int NbPin){
int pulse = angle;
if(millis()-lastPulse >=refraichissement){
digitalWrite(NbPin,HIGH);
delayMicroseconds(pulse);
digitalWrite(NbPin,LOW);
}
lastPulse=millis();
}
void loop(){
controlServo(600,5);//initialise gyro
Duration = pulseIn(gyroPin, HIGH); // read the servo pulse and write it
//Duration = ( Duration - iLeft ) * iRange / ( iRight - iLeft ) - iRange / 2; // range the signale between value
serialWrite('Y');
serialWrite('-> ');
printInteger(Duration);
printByte(10);
}
and i'm trying to get a lateral movement perception control and put the signal outpu from the gyro directly in the analog input of the arduino board...but can't get any changing value !!
i use this code :
/////////////////////////////////////////////////
int gyroIN=0;
i think that the gyro signal is a pulse value like a servo motor....but how to do this ????
fbm
I doubt that this will help you, but just in case it is news...
An R/C gyro can't detect lateral motion, it detects rotation.
An R/C gyro is a rate gyro, not a position gyro. It only outputs non-null pulse widths while the gyro is turning. If you turn it 45 degrees and leave it there, the pulse width momentarily goes non-null, then becomes null (1.5mS ?) when there is no more turning.
Usually these devices are put inline between the receiver and the rudder servo, and modify the rudder command pulse width. Is it possible that, lacking an input pulse train, the gyro does not output any pulses at all. (Causing your freeze?)(Grasping at straws here.)
That gyro does have a head lock mode, but to use it you need to have the gain pot set to more than 50%. You may need to play around with both the gain setting on the gyro and the pulse width on pin 5 to get anything sensible out of it. Try changing the pulse width to 1500 and see if that gives more meaningful results. If you have a 10k pot that you can put on an analog input you can use that to adjust your pulse widths between 1000 and 2000 us. Adjust the width so that the readings from pulseIn do not drift when the gyro is not moving.
And has already been mentioned, the gyro will return rotational information, not lateral movement.