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

    Wipy 2.0 and save data on my pc, not in flash memory

    Scheduled Pinned Locked Moved WiPy 2&3
    wipy2.0i2cpycompythonsaving data
    100 Posts 2 Posters 25.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.
    • V Offline
      VFlorio94
      last edited by

      @robert-hh And I 'm not able to use serial terminal

      1 Reply Last reply Reply Quote 0
      • V Offline
        VFlorio94 @robert-hh
        last edited by

        @robert-hh Sorry, but I need your help one more if is possible.
        I have to acquire data from IMU for a long time ( 20 minuts) and write the data on file.
        but also this time I have the error

        ╝Traceback (most recent call last):
         File "<stdin>", line 22, in <module>
        MemoryError: memory allocation failed, allocating 2048 bytes
        ╝>
        

        Here there are the simple code lines that I wrote. This error is terrible for me, probably I make an error on how to do this . please , can you Help me please?

        import machine 
        import pycom
        from machine import Timer
        import time
        import lib_imu
        from machine import I2C
        from machine import PWM
        
        chrono = Timer.Chrono()
        lib_imu.set_configmode()
        time.sleep(0.07)
        lib_imu.set_units()
        time.sleep(0.3)
        lib_imu.set_mode('ndof')
        List =[]
        chrono.start()
        while 1 :
            lap = chrono.read()
            if lap <= 1200: 
                eul = lib_imu.get_euler()    
                List.append(eul[0])
                time.sleep(0.02)
            else:
                print("Salvataggio su file")
                file_dati = open("dati360.txt", "w")
                file_dati.write(repr(List[1:len(List)]))
                file_dati.close()
                print("fine")
                chrono.stop()
                del List
                break
        
        robert-hhR 1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @VFlorio94
          last edited by

          @vflorio94 So you want first to collect for 1200 seconds data, with a delay of 20 ms each. I do not know how long taking a value needs, if have someting in mind like ~100 ms, which give a list of 10000 entries, and then you want to store that. AFAIK, the basic mp object type needs 8 bytes/entry, so you need 80kbytes for the fill table. Being already low on memory, the list append fails soon, when the runtime engine of micropython wants to allocate more memory for the list, roughly after 128 cycles.
          So no, you simply cannot do that with a WiPY2. You have to write to SD in shorter cycles, even if that would interrupt your data acquisition.
          Alternatively, use a device with more memory, like a WiPy3.

          V 1 Reply Last reply Reply Quote 0
          • V Offline
            VFlorio94 @robert-hh
            last edited by

            @robert-hh So, if i want to collect as more possible data in 1200 s how frequently can i take values?

            robert-hhR 2 Replies Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @VFlorio94
              last edited by

              @vflorio94 You should collect & write at the same time. Since the writikng is buffered, most of the write operations will not take long.

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

                @vflorio94 The code could look like:

                import machine 
                import pycom
                from machine import Timer
                import time
                import lib_imu
                from machine import I2C
                from machine import PWM
                
                chrono = Timer.Chrono()
                lib_imu.set_configmode()
                time.sleep(0.07)
                lib_imu.set_units()
                time.sleep(0.3)
                lib_imu.set_mode('ndof')
                with open("dati360.txt", "w") as file_dati:
                    chrono.start()
                    lap = chrono.read()
                    while lap < 1200
                        file_dati.write(repr(lib_imu.get_euler()[0]))
                        time.sleep(0.02)
                        lap = chrono.read()
                print("fine")
                chrono.stop()
                
                V 1 Reply Last reply Reply Quote 0
                • V Offline
                  VFlorio94 @robert-hh
                  last edited by

                  @robert-hh Thank you, I did in this way and the code run, but the real sample isn't 0.02 s but each 0.035 s. And I don't know why?!

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

                    @vflorio94 Taking the measurement and writing takes time too. Now you know, it's about 0.015s.

                    V 2 Replies Last reply Reply Quote 0
                    • V Offline
                      VFlorio94 @robert-hh
                      last edited by

                      @robert-hh Thank you very much for your help. I've never scheduled with Python, so for me is very difficult and I have to do this for my master thesis. For me you were very valuable.
                      thank you.

                      1 Reply Last reply Reply Quote 0
                      • V Offline
                        VFlorio94 @robert-hh
                        last edited by

                        @robert-hh Hi, sorry for my insistence. I have a new problem

                        ╝Traceback (most recent call last):
                          File "<stdin>", line 24, in <module>
                        OSError: 28
                        ╝>
                        

                        but i don't know why, because Yesterday this code run and now it give me this message.
                        the code is this one

                        import machine 
                        import pycom
                        from machine import Timer
                        import time
                        import lib_imu
                        from machine import I2C
                        from machine import PWM
                        import gc
                        
                        chrono = Timer.Chrono()
                        lib_imu.set_configmode()
                        time.sleep(0.05)
                        lib_imu.set_units()
                        time.sleep(0.05)
                        lib_imu.set_mode('ndof')
                        # List =[]
                        file_dati = open("datiprova_tempo20.txt", "a")
                        chrono = Timer.Chrono()
                        chrono.start()
                        lap = chrono.read()
                        while lap <= 1200: 
                            #eul = lib_imu.get_euler()
                            file_dati.write(repr(lap) + "\t ")
                            file_dati.write(repr(lib_imu.get_euler()[0]) + "\t ")
                            time.sleep(0.02)
                            lap = chrono.read()
                        file_dati.close()
                        print("fine")
                        chrono.stop()
                        

                        Can you help me please?

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

                          @vflorio94 Error 28 means: "No space left on device"
                          So your file system is full. You have to delete some files, or better change your code to save on an SD card. The internal flash file system is pretty small. I do not know why, because most of the FiPy's flash is not used.

                          V 1 Reply Last reply Reply Quote 0
                          • V Offline
                            VFlorio94 @robert-hh
                            last edited by

                            @robert-hh I delete each file.txt that I write before on the device with Filezilla.0_1534410021987_Screenshot (1).png

                            Yesterday and the day before in this condition I can wrote file.txt on the device, but now I can't and it give me this error.
                            but on the memory there are only those file.py.

                            robert-hhR 2 Replies Last reply Reply Quote 0
                            • robert-hhR Offline
                              robert-hh @VFlorio94
                              last edited by

                              @vflorio94 Are there any other files in the subdirectories, like in lib?

                              V 1 Reply Last reply Reply Quote 0
                              • V Offline
                                VFlorio94 @robert-hh
                                last edited by

                                @robert-hh No, there aren't any file in the subdirectory. But Yesterday it run program and saved them on memory.
                                after I collected data I deleted immediately file.txt. But now I have this error.
                                Probably do not filezilla really delete file?

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

                                  @vflorio94 At the REPL prompt, you can also get the file list and free space with:
                                  import uos
                                  uos.listdir()
                                  uos.getfree("/flash")

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

                                    @vflorio94 Filezilla just sends commands to the ftp server of the FiPy.

                                    1 Reply Last reply Reply Quote 0
                                    • V Offline
                                      VFlorio94 @robert-hh
                                      last edited by robert-hh

                                      @robert-hh I use the command that you wrote and it gives me the message:

                                      import uos
                                      print(uos.listdir())
                                      print(uos.getfree("/flash"))
                                      
                                      
                                      
                                      >>>
                                      ['main.py', 'sending.py', 'sys', 'lib', 'cert', 'boot.py', 'datiprova_tempo20.txt', 'lib_imu.py', 'interval_position.py']
                                      0
                                      ╝╝>```
                                      

                                      but it's incredible, just Yesterday it run. and I don't know what can I do now?!

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

                                        @vflorio94 You can tell the size ofdatiprova_tempo20.txt with:
                                        import uos
                                        uos.stat('datiprova_tempo20.txt')

                                        Every time you call your script this file will get larger, since you open that in append mode "a". I am just wondering why this file is not shown in the FileZilla screen dump.

                                        V 1 Reply Last reply Reply Quote 0
                                        • V Offline
                                          VFlorio94 @robert-hh
                                          last edited by

                                          @robert-hh said in Wipy 2.0 and save data on my pc, not in flash memory:

                                          You can tell the size ofdatiprova_tempo20.txt with:
                                          import uos
                                          uos.stat('datiprova_tempo20.txt')
                                          Every time you call your script this file will get larger, since you open that in append mode "a". I am just wondering why this file is not shown in the FileZilla screen dump.

                                          now I delete also the function 'interval.py' and 'sending.py' but it continue to give me the same error.

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

                                            @vflorio94 But how large is 'datiprova_tempo20.txt'? That is the file which grows by about 50kBytes on every execution of your script.

                                            V 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
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 5 / 5
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom