i try to read the ZAxis L/H Registers with a Mega.
First Step is to set config 1 Register to 124 (01111100) and enable the Z Achsis.
Second Step is reading the Registers 2C/2D.
But my code isnt working. Hope anybody can help me.
#include <Wire.h>
byte1 data;
byte2 data;
void setup(){
Serial.begin(57600);
Serial.println("Start");
Wire.begin();
Wire.beginTransmission(0x19);
Wire.write(0x32); //Adresse im Speicher
Wire.write(0x124);
Wire.endTransmission();
}
void loop(){
Wire.beginTransmission(0x19);
Wire.write(0x44); //Speicherzelle bei der das Lesen anfängt
Wire.endTransmission();
Wire.requestFrom(0x19, 1);
byte data = Wire.read();
Serial.println(data1);
Wire.beginTransmission(0x19);
Wire.write(0x44); //Speicherzelle bei der das Lesen anfängt
Wire.endTransmission();
Wire.requestFrom(0x19, 1);
byte data = Wire.read();
Serial.println(data2);
delay(500);
}
0x19 -> 19h-> Device Adress
0x20-> Config Register 1 Adress
0x7C-> 01111100, The Bits to config the Device how the description in Datasheet of LIS2DH
0x2C-> The OUT_Z_L Register
0x2D-> The OUT_Z_H Register
I was perfectly fine with variables in everything. Made it much more readable. They just where not defined anywhere which made the code uncompileable...
But what exactly is the problem you're facing? Is it printing the wrong value? If so, how do you know?