Hello everyone ! I'm using LSM9DS0 accelerate Sensors.When the sensors are connected directly to the
Arduino DUE I get the proper accelerate readings.I set my frequency to 1600Hz and accelerate 16g.This is my code.
#include <SPI.h> // Included for SFE_LSM9DS0 library
#include <Wire.h>
#include <SFE_LSM9DS0.h>
#define LSM9DS0_XM 0x1D // Would be 0x1E if SDO_XM is LOW
#define LSM9DS0_G 0x6B // Would be 0x6A if SDO_G is LOW
LSM9DS0 dof(MODE_I2C, LSM9DS0_G, LSM9DS0_XM);
#define PRINT_RAW
#define PRINT_SPEED 1 // 500 ms between prints
unsigned long startTime;
const byte INT1XM = 3; // INT1XM tells us when accel data is ready
const byte INT2XM = 2; // INT2XM tells us when mag data is ready
const byte DRDYG = 4; // DRDYG tells us when gyro data is ready
float abias[3]= {0, 0, 0}, gbias[3] = {0, 0, 0};
float ax, ay, az;
float tempX[32]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
float tempY[32]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
float tempZ[32]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
float data1[192];
float data[3];
float g = 0 , t = 0 , u = 0;
int ii=0;
int d,i,j,k,q;
void setup()
{
Serial.begin(115200); // Start serial at 115200 bps
// Use the begin() function to initialize the LSM9DS0 library.
// You can either call it with no parameters (the easy way):
Wire.begin();
Wire.setClock(400000L);
// Or call it with declarations for sensor scales and data rates:
uint16_t status = dof.begin();
pinMode(INT1XM, INPUT);
pinMode(INT2XM, INPUT);
pinMode(DRDYG, INPUT);
dof.setAccelScale(dof.A_SCALE_16G);
dof.setAccelODR(dof.A_ODR_1600);
dof.setAccelABW(dof.A_ABW_773);
dof.calLSM9DS0(gbias, abias);
delay(100);
Serial.flush();
}
void loop()
{
Serial.flush();
{
startTime = millis();
dof.readAccel1();
q = dof.data5[1];
for( ii=0; ii<q; ii++){
float a = (dof.tempX[ii]);
a = a * 0.000732;
Serial.print(a);
Serial.print(",");
}
Serial.println(startTime);
startTime = 0 ;
while (Serial.available())
{Serial.read();Serial.flush();
}
}
}
and this is part of LSM9DS0.cpp code
void LSM9DS0::readAccel1()
{
uint8_t data[6] = {0, 0, 0, 0, 0, 0};
int samples, ii, c, abc;
c = xmReadByte(CTRL_REG0_XM);
xmWriteByte(CTRL_REG0_XM, c | 0x40); // Enait for change to take effect
// Wnable accelerometer FIFO stream mode and set watermark at 32 samples
xmWriteByte(FIFO_CTRL_REG, 0x20 | 0x1F); // Eable accelerometer FIFO
delay(15); // delay 1000 milliseconds to collect FIFO samples
samples = (xmReadByte(FIFO_SRC_REG) & 0x1F);
for(ii=0;ii<samples;ii++)
{
xmReadBytes(OUT_X_L_A, &data[0], 6);
tempX[ii] = ((int16_t)data[1] << 8) | data[0];
tempY[ii] = ((int16_t)data[3] << 8) | data[2];
tempZ[ii] = ((int16_t)data[5] << 8) | data[4];
}
data5[1] = samples;
c = xmReadByte(CTRL_REG0_XM);
xmWriteByte(CTRL_REG0_XM, c & ~0x40); // Disable accelerometer FIFO
xmWriteByte(FIFO_CTRL_REG, 0x00); // Enable accelerometer bypass mode
}
Every resault's interval is about 30ms.
But my result isn't fast.It is about 718Hz.I don't know where is the problem.
Could anyone help me in this case??
