Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Get and write data to a file at 800Hz Pysense

    Scheduled Pinned Locked Moved LoPy
    8 Posts 4 Posters 462 Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G Offline
      gabrielapb
      last edited by gabrielapb

      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?

      robert-hhR J 3 Replies Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @gabrielapb
        last edited by

        @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.

        G 1 Reply Last reply Reply Quote 0
        • G Offline
          gabrielapb @robert-hh
          last edited by

          @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?

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @gabrielapb
            last edited by

            @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.

            1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @gabrielapb
              last edited by robert-hh

              @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.

              1 Reply Last reply Reply Quote 1
              • J Offline
                jcaron @gabrielapb
                last edited by

                @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.

                robert-hhR 1 Reply Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh @jcaron
                  last edited by

                  @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.

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    cc
                    last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • 1 / 1
                    • First post
                      Last post

                    Pycom on Twitter

                    Pycom