hi, gotten 9dof imu sensor stick sparkfun includes adxl345 accelerometer, itg-3200 mems gyroscope , hmc5883l magnetometer.
i decided test on accelerometer first. i've connected 4.7k resistor ohms both sda , scl. input voltage 3v of arduino micro.
here adxl345 accelerometer code internet:
my display output, getting:
x: 0 y: 5 z: 264
my 'x' remains @ 1, 0 or -1
my y remains around 5,6,7 values
my z remains around 263, 264
all these values when board resting on horizontal surface. understand should display of 0,0,1 x, y, z values respectively.. no. because should convert unit?
im not quite sure how check accuracy of values displayed.. there method check?
and how conversion of units bytes unit, g ?
please help, , thank in advance!
i decided test on accelerometer first. i've connected 4.7k resistor ohms both sda , scl. input voltage 3v of arduino micro.
here adxl345 accelerometer code internet:
code: [select]
#include <adafruit_sensor.h>
#include <wire.h>
#define adxl345_address (0x53)
#define adxl345_register_xlsb (0x32)
#define adxl_power_ctl (0x2d)
#define adxl_pwrctl_measure (1 << 3)
int accelerometer_data[3];
char c;
void setup()
{
wire.begin();
serial.begin(9600);
for(int = 0; < 3; ++i)
{
accelerometer_data[i] = 0;
}
init_adxl345();
}
void loop() {
read_adxl345();
serial.print("accel: ");
serial.print(accelerometer_data[0]); // x-axis
serial.print("\t");
serial.print(accelerometer_data[1]); // y-axis
serial.print("\t");
serial.print(accelerometer_data[2]); // z-axis
serial.print("\n");
delay(500);
}
void init_adxl345()
{
byte data = 0;
i2c_write(adxl345_address, adxl_power_ctl, adxl_pwrctl_measure);
i2c_read(adxl345_address, adxl_power_ctl, 1, &data);
serial.println((unsigned int)data);
}
void i2c_write(int address, byte reg, byte data) {
wire.begintransmission(0x53);
wire.write(reg);
wire.write(data);
wire.endtransmission();
}
void i2c_read(int address, byte reg, int count, byte* data) {
int = 0;
wire.begintransmission(0x53);
wire.write(reg);
wire.endtransmission();
wire.begintransmission(0x53);
wire.requestfrom(0x53,count);
while(wire.available()){
c = wire.read();
data[i] = c;
i++;
}
wire.endtransmission();
}
void read_adxl345()
{
byte bytes[6];
memset(bytes,0,6);
i2c_read(adxl345_address, adxl345_register_xlsb, 6, bytes);
for (int i=0;i<3;++i)
{
accelerometer_data[i] = (int)bytes[2*i] + (((int)bytes[2*i + 1]) << 8);
}
}
my display output, getting:
x: 0 y: 5 z: 264
my 'x' remains @ 1, 0 or -1
my y remains around 5,6,7 values
my z remains around 263, 264
all these values when board resting on horizontal surface. understand should display of 0,0,1 x, y, z values respectively.. no. because should convert unit?
im not quite sure how check accuracy of values displayed.. there method check?
and how conversion of units bytes unit, g ?
please help, , thank in advance!
no, because sitting on desk adxl345 subject 1g field of earth. if flip upside down, z values should go negative. if put on side x or y show 263-264.
the accelerometer can calibrated high precision clever algorithms or can subtract offset , multiply "g per lsb" shown in datasheet.
depending on want do, may or may not make sense remove 1g constant.
the accelerometer can calibrated high precision clever algorithms or can subtract offset , multiply "g per lsb" shown in datasheet.
depending on want do, may or may not make sense remove 1g constant.
Arduino Forum > Using Arduino > Programming Questions > 3 axis Accelerometer ADXL345
arduino
Comments
Post a Comment