Get and write data to a file at 800Hz Pysense

  • Hi all,

    I am using a Lopy4 and Pysense to read data from the built-in accelerometer at 800Hz. Data is written to a file on SD card, but each write operation takes me 10ms, no matter what changes I make. Therefore, what I have in fact now is the measurements at 100Hz.

    I tried to save to flash, change the content of the file, but it also takes the same amount of time. What can I do to have measurements at a high frequency (800Hz) saved in a file?

  • This post is deleted!

  • @jcaron AFAIK, file I/O is already buffered. Glancing at the code, it seems to be 512 byte. I recalled 4k, but that was for the ESP8266 port. So using a larger buffer may improve things.

  • @gabrielapb for the SD card write side of things, you could (and probably should, really) buffer data for a while and only write once your buffer is full.

    This should help with performance, but also to minimise the number of writes to flash (a flash cell has a maximum number of writes in its lifetime).

    You want your buffer to be a multiple of the sector size on your filesystem, ideally.

    Note that you will probably need to use threads to avoid blocking the data capture while your write.

  • @gabrielapb Looking at the data sheets, you can speed up reading the sensor. By default I2C is set to 100kHz, but you can use 400kHz. Also. the method acceleration uses three calls to read 3*2 bytes, unpacks that, scales it and returns a tuple. You can use a single call to read all 6 bytes. If you put this call into you main loop, skip the data extraction and just write the raw binary data, you'll save a lot of time. The nice representation of the data can be done later.

  • @gabrielapb O do not know what a standard time is for that. But maybe you have to make your own minimal driver. But i never made or could make data acquisition and processing at a rate faster than 250 Hz.

  • @robert-hh Hi, I am using the LIS2HH12 library at 800Hz (max rate), but the reading operation takes 3ms. Do you know if this is the standard time for Pycom?

  • @gabrielapb At which rate can you effectively read from the accelerometer? The MP devices and the Pycom ones are not very fast, and when writing to SD, even buffered, you will have longer write times. What I did once was sending the data to a PC for storing. But that only helps if the raw data acquisition is sufficiently fast.

Log in to reply

Pycom on Twitter