Gyroscope XV-3500CB back to default

Hi,

I have a Gyroscope XV-3500CB. connected on a analog port. the gyro works. But not as i want it.

The gyro is connected with a servo. when i turn the gyro, the servo will turn but when i stop turning the gyro the servo goes back to his default position (default output of the gyro).

Is it possible to change this? my target is to when i stop rotating the gyro, the servo stay's on the same place as i stopped the gyro.

This is the video of my gyro now:

And this is my (simple) code

#include <Servo.h>  
Servo myservo;  
int gyro =A8;
int waarde;


void setup() {

myservo.attach(9); 
}

void loop() {
 waarde = analogRead(gyro);
 waarde = map(waarde, 282, 320, 90, 179);
 myservo.write(waarde);   

}

The gyro is a "rate gyro" which outputs a signal proportional to how quickly you turn it. When you stop turning it goes back to the "not rotating" value. To get an estimate of how FAR (not how fast) the gyro has turned you have to add up the "how FAST" values. You will need to subtract the "not turning" value.

void loop() {
 int rate = analogRead(gyro);
 waarde += rate - 307;   //////  "not turning" value determined by experiment
 map(waarde, -100, 100, 10, 170);
 myservo.write(waarde);   
}

johnwasser:
The gyro is a "rate gyro" which outputs a signal proportional to how quickly you turn it. When you stop turning it goes back to the "not rotating" value. To get an estimate of how FAR (not how fast) the gyro has turned you have to add up the "how FAST" values. You will need to subtract the "not turning" value.

void loop() {

282

Hi, my non turning value (default when gyro is laying on my desk) is about 282.
When i use your code(thnx for that!) my servo drives like a crazy banana. left right left right, left left. And no respond from the gyro. i try'd to change the value's. like the 307 on this sentence. waarde += rate - 307; but no good response. I guess i am doing it terrible wrong..

If 282 is the value YOUR gyro produces when you are not rotating it, replace the 307 in my code with 282. That should help some.

If the servo reacts too violently you can put in a short delay, perhaps delay(100), to keep things from going wild.

Hi,

Just tested some different settings. The strange thing is when i use serial.printnl function for "int gyro" i will get steady 181 / 182 output. when i use serial.printnl for int waarde. the output is crazy .( 210 350 120 etc etc and it don't matter if i use a delay)

First try:
Your code with the 282 as default.

After this i used the same code, only with a delay(100); on the bottom of the code.

I have this code now, and when i turn the gyro the servo will turn and stay on his place. but when i move the gyro to quickly, the gyro will disorientated. is there a way to fix this? or is this a gyro problem?

#include <Wire.h>
#include <Servo.h>

#define Gyro_address B1101000
#define Register 0
#define ServoPin 2
// I2C CLock pin A21;
// I2C Data pin A20;

Servo servo1;

void setup()
{
//pinMode(2,OUTPUT);
Wire.begin();

//Serial.begin(9600);
servo1.attach(2);
}
int gyro_const = 16133;
int data;
double w; // grad/sec
double angle = 0;
unsigned int time1 = 0;
unsigned int time2 = 0;


void loop()
{
data = Get_Gyro_Data();
w=(data-gyro_const)/176;
time1 = micros();
angle+=w*(time1-time2)/1000000;
time2 = time1;
servo1.write((int)angle);
}

int Get_Gyro_Data()
{
int data;
Wire.beginTransmission(Gyro_address);
Wire.send(Register);
Wire.endTransmission();

Wire.requestFrom(Gyro_address, 2);
if(Wire.available()>=2)
{
data = Wire.receive();
data |= Wire.receive() << 8;
}
return data;

}