cancel
Showing results for 
Search instead for 
Did you mean: 

Timestamp Readings from the LSM6DSO

ItaiS
Associate

So this is a broad question, but I have been combing through the LSM6DSO datasheet all day, and I know that the sensor returns its own timestamp data. Beyond that, however, I am struggling to access this data. (My acceleration and gyro values are returned just fine.) I tried using the readRegister() function, and I tried seeing what values I get from printing (TIMESTAMP_EN). 

I am working in the Arduino IDE, and using the SparkFun board of the LSM6DSO, connected to an ESP32 Thing Plus C via the Qwiic connection, so there's no guesswork about the wiring. Here is my code:

 

#include "SparkFunLSM6DSO.h"
#include "Arduino.h"
#include "Wire.h"

#define TIMESTAMP0_REG 1

LSM6DSO myIMU; //Default constructor is I2C, addr 0x6B
float t0, t, dt, t_total, f = 0;
int cycles = 0;

void setup() {
  Serial.begin(115200);
  while(!Serial);
  //Wire.setSDA(0);
  //Wire.setSCL(1);
  Wire.begin();
  //Wire.setClock(100000);
  delay(10);
 
  if(myIMU.begin()) {
    Serial.println("Ready.");
  } else {
    Serial.println("Could not connect to IMU.");
    Serial.println("Freezing");
  }

  if(myIMU.initialize(BASIC_SETTINGS))
    Serial.println("Loaded Settings.");

  delay(2000);
}


void loop() {
  float x, y, z, gx, gy, gz, tempF;
  t0 = millis();

  x = myIMU.readFloatAccelX();
  y = myIMU.readFloatAccelY();
  z = myIMU.readFloatAccelZ();
  gx = myIMU.readFloatGyroX();
  gy = myIMU.readFloatGyroY();
  gz = myIMU.readFloatGyroZ();
  // tempF = myIMU.readTempF();
 
  Serial.println();
  Serial.print("X = ");
  Serial.print(x, 3);
  Serial.print("\tY = ");
  Serial.print(y, 3);
  Serial.print("\tZ = ");
  Serial.print(z, 3);
  Serial.print("\tGX = ");
  Serial.print(gx, 3);
  Serial.print("\tGY = ");
  Serial.print(gy, 3);
  Serial.print("\tGZ = ");
  Serial.print(gz, 3);
  //Serial.print("\tTEMP_F = ");
  //Serial.print(tempF, 3);
  Serial.println();
 
  t = millis();
  dt = t - t0;
  t_total += dt;
  cycles++;
  f = 1000 * float(cycles) / t_total;
 
  Serial.print("cycle #");
  Serial.print(cycles);
  Serial.print("\tt = ");
  Serial.print(t_total/1000, 2);
  Serial.print("\tdt = ");
  Serial.print(dt/1000, 3);
  Serial.print("\tavg freq = ");
  Serial.print(f, 2);
  Serial.println("Hz");

  Serial.print(myIMU.readRegister(0x40));
  Serial.print("\t");
  Serial.println(t_total);
  if(t_total > 60000) {
    Serial.println("bruh");
    while(1);
  }
}
1 REPLY 1
Federica Bossi
ST Employee

Hi @ItaiS ,

Welcome to ST Community!

Please, follow our PID example for LSM6DSO Timestamp 🙂

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.