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

    micropython logging to CSV

    Scheduled Pinned Locked Moved MicroPython
    micropythoncsvlogging
    5 Posts 2 Posters 1.6k Views 2 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.
    • T Offline
      tttadam
      last edited by

      Hi there,

      I am working on a device which suppose to log values, and I want to store the result in CSV format, for easier handling from code and for the future.
      I found a handy python library for that (csv), but VS cannot import that library. Is it possible that csv library has not been ported to micropython? Can you recommend me a solution or a workaround? Am I doing it the "right way" or there is some other best practices?
      Thanks,

      https://docs.python.org/2/library/csv.html

      E 1 Reply Last reply Reply Quote 0
      • E Offline
        Eric73 @tttadam
        last edited by

        @tttadam CSV is unefficient way to store data
        ex: to store the value 100 you use 3 octet plus a comma sign as separator (4 bytes to store a value that fit in one byte!)
        In embedded system memory (even for storage) is expensive !
        The better way to store your value is to pack it in binary form (using ustruct micropython module) and write this binary package in your file.
        You can simply on PC side, write a little software in python that unpack your embedded file to csv

        T 1 Reply Last reply Reply Quote 1
        • T Offline
          tttadam @Eric73
          last edited by

          @eric73 Thank you for making it clear for me. My intention was never to store the data on flash.
          I forget the mention that I will store the data on sd card. I think there is a plenty of space there.

          This is error what I get:

          Traceback (most recent call last):
            File "boot.py", line 3, in <module>
          ImportError: cannot import name csv
          E 1 Reply Last reply Reply Quote 0
          • E Offline
            Eric73 @tttadam
            last edited by Eric73

            @tttadam boot.py is not the rigth place to have some code running, keep this file only for startup board setting (bluetooth and wifi) and place your code in main.py or other file (not mandatory but a good practice).

            CSV is no more than several ascii string line write i a file with a separator (popular is ',' or ';') between value. CVS module from python provide a lot of helper function to do advance stuff on CSV file, if you only :
            Write first line of your file with name colomn of your field (ex: Time,temp,Sensor name) (not mandatory but a good practive to name your field for post-processing)
            Then write the followings lines with value
            1538988400,25.2,T1
            1538988401,25.1,T1
            1538988401,25.3,T1
            ...
            Then you have a perfectly valid CSV file you can open in PC with OpenOffice Calc for exemple.

            T 1 Reply Last reply Reply Quote 1
            • T Offline
              tttadam @Eric73
              last edited by

              @eric73 I am just creating the file and the first row, in my mind that's belongs to initialization. But correct me if not.
              Okay than I just use the basic file operations.
              Thank you! :)

              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