Hello,
I need some help over understanding some lines of code and maybe replacing them with possible to read for me ones.
I'm trying to make my accelometer work which is part of my thesis subject, for now I want to know how to read values of acceleration in three axis I read from datasheet registers adresses I can pick any axis register value and put it in the code so the value of g in this axis would be read, but since I'm using some found code for some other accelerometer I don't know how to aquire data from all 3 of the axis at the same time.
My question is if somebody could explain me why "char output[512]" is used on top and I know that it stores data for print but I don't know how exacly, and also I dont know what this lines does:
z = (((int)values[1]) << 8);
sprintf(output, "%d", z);
Serial.print(output);
// I mean I know that Serial.print just sends data as a string to serial monitor but it works as combination with sprintf and I not sure how?
Could somebody maybe write me example that could receive values of registers on top of the code and print them all as a single string using Serial.print maybe?
I attach datasheet for my accelometer so maybe you could also check if I'm connecting and communicating with it correctly?
//Hex values for registers: X-0x29 ; Y-0x2B ; Z-0x2D
// Ctrl_Reg1 - 0x20
#define accel_module (0x1D)
byte values[6];
char output[512];
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Wire.beginTransmission(accel_module);
Wire.write(0x20);
Wire.write(64);
Wire.endTransmission();
}
void loop()
{
int xregister = 0x2D;
int x,y,z;
Wire.beginTransmission(accel_module);
Wire.write(xregister);
Wire.endTransmission();
Wire.beginTransmission(accel_module);
Wire.requestFrom(accel_module, 7);
int i = 0;
while(Wire.available()){
values[i] = Wire.read();
i++;
}
Wire.endTransmission();
z = (((int)values[1]) << 8);
sprintf(output, "%d", z);
Serial.print(output);
Serial.write(10);
delay(100);
}
LIS35DE.pdf (646 KB)