GY-80

I am trying to get data from a GY-80 sensor using I2C. I am currently trying to access the accelerometer data and have been kind of successful. I can only get 2 axes to work at a time, and I am unsure why this is the case.

XYZ_Axis_Acceleromter.ino (1.52 KB)

Could it be that you've got the Y axis read commented-out?

Please, if you only got a tiny amount of code, just POST IT, don't make us download it.

Sorry, here is the code. I commented some of it out because I was doing some testing to see what the issue was.

#include <Wire.h>

int ADXLAddress = 0x53; // Device address in which is also included the 8th bit for selecting the mode, read in this case.

#define X_Axis_Register_DATAX0 0x32 // Hexadecima address for the DATAX0 internal register.
#define X_Axis_Register_DATAX1 0x33 // Hexadecima address for the DATAX1 internal register.
#define Y_Axis_Register_DATAY0 0x34
#define Y_Axis_Register_DATAY1 0x35
#define Z_Axis_Register_DATAZ0 0x36
#define Z_Axis_Register_DATAZ1 0x37

#define Power_Register 0x2D // Power Control Register

int X0,X1,X_out;
int Y0,Y1,Y_out;
int Z0,Z1,Z_out;

void setup() {
Wire.begin(); // Initiate the Wire library
Serial.begin(9600);
delay(10);
// Enable measurement
Wire.beginTransmission(ADXLAddress);
Wire.write(Power_Register);
// Bit D3 High for measuring enable (0000 1000)
Wire.write(8);
Wire.endTransmission();
}

void loop() {
Wire.beginTransmission(ADXLAddress); // Begin transmission to the Sensor
//Ask the particular registers for data
Wire.write(X_Axis_Register_DATAX0);
Wire.write(X_Axis_Register_DATAX1);

// Wire.write(Y_Axis_Register_DATAY0);
// Wire.write(Y_Axis_Register_DATAY1);

Wire.write(Z_Axis_Register_DATAZ0);
Wire.write(Z_Axis_Register_DATAZ1);

Wire.endTransmission(); // Ends the transmission and transmits the data from the two registers

Wire.requestFrom(ADXLAddress,6); // Request the transmitted bytes from the two registers

if(Wire.available()<=6) {
delay(1000);
X0 = Wire.read(); // Reads the data from the register
X1 = Wire.read();

Y0 = Wire.read();
Y1 = Wire.read();

Z0 = Wire.read();
Z1 = Wire.read();
}

Serial.print("X0= “);
Serial.print(X0);
Serial.print(” X1= ");
Serial.println(X1);

Serial.print("Y0= “);
Serial.print(Y0);
Serial.print(” Y1= ");
Serial.println(Y1);

Serial.print("Z0= “);
Serial.print(Z0);
Serial.print(” Z1= ");
Serial.println(Z1);
}

I give up.

  while(Wire.available()<=6) { } // changed
  //  delay(1000);
    X0 = Wire.read(); // Reads the data from the register
    X1 = Wire.read();
    Y0 = Wire.read();
    Y1 = Wire.read();
    Z0 = Wire.read();
    Z1 = Wire.read();
 
    Serial.print.......... and so on

So I changed it up a bit and when I add the <=6 part, it won’t at all print to my serial monitor. I apologize, I just started learning this all a couple days ago, any help past this updated code would be great!

#include <Wire.h>

int ADXLAddress = 0x53;

#define X_Axis_Register_DATAX0 0x32
#define X_Axis_Register_DATAX1 0x33
#define Y_Axis_Register_DATAY0 0x34
#define Y_Axis_Register_DATAY1 0x35
#define Z_Axis_Register_DATAZ0 0x36
#define Z_Axis_Register_DATAZ1 0x37
#define Power_Register 0x2D // Power Control Register

int X0,X1;
int Y0,Y1;
int Z0,Z1;

void setup() {
Wire.begin();
Serial.begin(9600);
Wire.write(Power_Register);
}

void loop() {
Wire.beginTransmission(ADXLAddress); // Begin transmission to the Sensor
//Ask the particular registers for data
Wire.write(X_Axis_Register_DATAX0);
Wire.write(X_Axis_Register_DATAX1);
Wire.write(Y_Axis_Register_DATAY0);
Wire.write(Y_Axis_Register_DATAY1);
Wire.write(Z_Axis_Register_DATAZ0);
Wire.write(Z_Axis_Register_DATAZ1);

Wire.endTransmission(0); // Ends the transmission and transmits the data from the 6 registers

Wire.requestFrom(ADXLAddress,6,1); //Send stop signal at end of request which is what the 1 is

while(Wire.available()<=6); {
delay(1000);
X0 = Wire.read(); // Reads the data from the register
X1 = Wire.read();
Y0 = Wire.read();
Y1 = Wire.read();
Z0 = Wire.read();
Z1 = Wire.read();
}

Serial print…

“<=” should ofcourse be “<”