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