Gyro control of a xbox controller (help!)

Hi all,

Yep I'm a total newbie, know jack-sh$t about programming (sorta)..

OK, first I have MS, so I have a few problems, so, I am currently building a project to control my xbox controller! ( it's the hands you know!)

So far, I have a an L3G4200D gyro hooked up to my arduino,

and I found some code that gives me a "stable" output and a good solid o position etc,

this hopefully will drive (for the moment) 3 servos, one one for each, X, Y, Z, axis,

as if controlling a Helicopter etc, These will in-turn turn the potentiometers on the xbox controllers right and left thumb sticks, To control view direction ie, pitch, roll, yaw etc

in game...

The Gyro will be on a pair of video glasses (Vuzix Wrap 1200), the idea being that when I move my head up & down and roll left to right the the gyro output will replace the xbox controllers sticks! same thing as FPV (first person view) for flying model air planes and heli's etc, accept this is all in game!

OK,

So now I need help with the code for converting the output of the gyro to the servos!

The basic code for playing with a servo obviously is not the way...

The servos are connected to pins 9, 10, 11 ( white signal wire) red and black to power and grnd ( 5v battery pack to supply servos with common ground with arduino) noted from another thread..

(NOTE: the servos will be replaced soon-ish with an AD5206 digital pot) with luck..

Here's the code I have already:


#include <Wire.h>

#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23

int Addr = 105; // I2C address of gyro
int x, y, z;

void setup(){
Wire.begin();
Serial.begin(9600);
writeI2C(CTRL_REG1, 0x1F); // Turn on all axes, disable power down
writeI2C(CTRL_REG3, 0x08); // Enable control ready signal
writeI2C(CTRL_REG4, 0x80); // Set scale (500 deg/sec)
delay(100); // Wait to synchronize
}

void loop(){
getGyroValues(); // Get new values
// In following Dividing by 114 reduces noise
Serial.print("Raw X:"); Serial.print(x / 114);
Serial.print(" Raw Y:"); Serial.print(y / 114);
Serial.print(" Raw Z:"); Serial.println(z / 114);
delay(500); // Short delay between reads
}

void getGyroValues () {
byte MSB, LSB;

MSB = readI2C(0x29);
LSB = readI2C(0x28);
x = ((MSB << 8) | LSB);

MSB = readI2C(0x2B);
LSB = readI2C(0x2A);
y = ((MSB << 8) | LSB);

MSB = readI2C(0x2D);
LSB = readI2C(0x2C);
z = ((MSB << 8) | LSB);
}

int readI2C (byte regAddr) {
Wire.beginTransmission(Addr);
Wire.write(regAddr); // Register address to read
Wire.endTransmission(); // Terminate request
Wire.requestFrom(Addr, 1); // Read a byte
while(!Wire.available()) { }; // Wait for receipt
return(Wire.read()); // Get result
}

void writeI2C (byte regAddr, byte val) {
Wire.beginTransmission(Addr);
Wire.write(regAddr);
Wire.write(val);
Wire.endTransmission();
}


Most of it means nothing to me (yet!)

How do I add to it and incorporate the code for the servos????

A very steep learning curve I know, But really any help is so appreciated..

Regards to all,

Alex :fearful:

and I found some code that gives me a "stable" output and a good solid o position etc

Those would be these values?

  Serial.print("Raw X:");  Serial.print(x / 114);
  Serial.print(" Raw Y:"); Serial.print(y / 114);
  Serial.print(" Raw Z:"); Serial.println(z / 114);

If so, what kind of values are you getting? How do you want to map those to the range that the servo understands?

What range of servo values is needed to move the joystick end-to-end?

Hi,
Dont know just yet what the servo ranges are!

Q: " Serial.print("Raw X:"); Serial.print(x / 114);
Serial.print(" Raw Y:"); Serial.print(y / 114);
Serial.print(" Raw Z:"); Serial.println(z / 114);
Is that a typo on the third line for the serial.println(z/

And do I just add the code to the bottom of the other?
Thanks..

All I know is that the pot's on the controller travel 35 degres eitherside of zero, so I guess the servos will need to travel only the same amount!

And do I just add the code to the bottom of the other?

That was your code, just posted properly, which is probably why you didn't recognize it. It shows some output. You haven't answered the question about whether it is that output that you are viewing to determine that you are getting ""stable" output and a good solid o position", nor have you shown any of that output.

so I guess the servos will need to travel only the same amount!

Not necessarily. Depending on how the servo is moving the pots, the servo may need to move more or less than the same amount as the potentiometers can travel.