Posts: 1
Joined: Sun Jan 06, 2019 9:51 am

How to get good timestamps on Accelerometer and Gyroscope data

Sun Jan 06, 2019 10:01 am

Hi all, I'm working through a data logger setup that includes collecting data from the Adxl345 accelerometer and the ITG3200 gyro. I've gotten some basic drivers set up, data logging code running, and have been collecting data but I'm hitting some weird problems with times. Currently I'm just using the system clock (time.time()) to generate a timestamp for each data point. The results seem somewhat nonsensical though and the data seems closer to reality when I simply generate artificial timestamps at around the time delay of one period (based on the frequency set on the device).

So this is my question. I'm generating data (Accel for example) at a higher rate than the pi can collect it, but I want as much of that data as I can get. My assumption was that if I poll as fast as I can and record the timestamp at each poll the system clock would be close enough to the actual data time to work. Now that that doesn't seem to be the case, how do I generate correct timestamps for my data? I could do what I'm doing after the fact now and use the frequency of the accelerometer and just add it each time, but as I'm almost certain to miss some datapoints this would drift over time and have inaccuracies. Yet I can't find anything in the datasheet that speaks to giving me time values of any sort.

An alternative would be to read the FIFO that the accelerometer has, but in that case too I can't figure out how the timestamps would work. If I pull the FIFO cache do I just calculate backwards from the present moment to determine when each of those points came from?

This is a known problem though that people regularly solve so I can't help but think I'm missing something obvious; can anyone help me out on what it is?

Return to “Automation, sensing and robotics”