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

    Solved: SiPy + PyTrack: GPS Example simplified to basic GPS only fails with MemoryError

    Scheduled Pinned Locked Moved SiPy
    sipypytrackgpsmemoryerror
    16 Posts 6 Posters 5.6k 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.
    • M Offline
      Meirssv
      last edited by Meirssv

      I tested a bare minimum code sample for a GPS-test on a SiPy+PyTrack setup. This code (see below) fails after a while with MemoryError:

      File "main.py", line 7, in
      File "/flash/lib/L76GNSS.py", line 56, in coordinates

      I found a reference to what I think is described in a bug post on the library here on github.

      The SiPy+PyTrack is lying next to a window inside. If this is the reason for this issue, can we catch this kind of error and resume the code gracefully, so it will not interrupt the execution?

      Is there someone who got the PyTrack working without exceptions?

      from L76GNSS import L76GNSS
      from pytrack import Pytrack
      
      py = Pytrack()
      l76 = L76GNSS(py, timeout=60)
      while(True):
          coord = l76.coordinates()
          print("{}".format(coord))
      
      L C A 3 Replies Last reply Reply Quote 0
      • L Offline
        livius @Meirssv
        last edited by

        @meirssv said in SiPy + PyTrack: GPS Example simplified to basic GPS only fails with MemoryError:
        what if you change it to:

        from L76GNSS import L76GNSS
        from pytrack import Pytrack
        import gc
        
        py = Pytrack()
        l76 = L76GNSS(py, timeout=60)
        while(True):
             coord = l76.coordinates()
             print("{}".format(coord))
             gc.collect()
        

        think about people first, then computers

        M 1 Reply Last reply Reply Quote 0
        • M Offline
          Meirssv @livius
          last edited by Meirssv

          @livius Yes, even tried that one, still same effect, it fails with memoryerror after a while. (Also running next to a window inside) -> I saw some responses on the forum with comparable PyTrack/MemoryErrors that it can be related to indoor use, but in the end, the code should not interrupt, it should gracefully handle the problem -even when using it inside-.

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @Meirssv
            last edited by livius

            @Meirssv
            Is above error valid for lib from github https://github.com/pycom/pycom-libraries/tree/master/pytrack/lib or you have some modified/older version?
            i ask because line 55 is break
            which is not informative at all

            think about people first, then computers

            M 1 Reply Last reply Reply Quote 0
            • M Offline
              Meirssv @livius
              last edited by

              @livius Yeah... sorry, that's a typo. It was line 56, the nmea-append stuff... will change in my original post.

              L 1 Reply Last reply Reply Quote 0
              • L Offline
                livius @Meirssv
                last edited by livius

                @meirssv

                what if you change line 74 and 75 to

                                if len(nmea) > 1024: # i suppose here can be safe changed to 82 which is longest NMEA frame
                                    nmea = nmea[-5:] #   $GNGL without last L
                

                think about people first, then computers

                M 2 Replies Last reply Reply Quote 0
                • M Offline
                  Meirssv @livius
                  last edited by

                  @livius Seems sensible to me... I will give it a try later on, I am not in the office now. Will post feedback when available.

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    crumble @Meirssv
                    last edited by

                    @meirssv the GPS example lib uses a lot of strings. So it uses too much memory. As well it uses only the GNSS sentence and not the GPS sentence. Some people seem to have problems getting coordinates. Maybe this is the cause. I was surprised that in my area I can receive GNSS indoor.

                    It would be nice, if pycom gives us a better library. I am currently try to fix this for myself using bytearray instead of strings. But beside that I have sparly time, I notice with every line why I hate python. Writing performant MicroPython is no fun. I know that I can rewrite 98% of my code as soon as it runs :-/

                    Beside that I miss an emulator, if I have some time and no device. There is still hope, that the next firmware gives us the 2nd core and MicroPython 1.9.x which may use less memory. It would be nice, if pycom focus more on the software than on new hardware.

                    M 1 Reply Last reply Reply Quote 1
                    • M Offline
                      Meirssv @crumble
                      last edited by

                      @crumble If you buy a PyTrack, especially designed to put on a LoPy or SiPy or WhateverPy, you'd expect the core function (GPS) to work with one of these Py-boards, I guess not. Would an upgrade to the upcoming LoPy4 be a resolution? It has 4x RAM and twice the flash of the SiPy1 and it because it adds SigFox to the Lora radio, so it would be an alternative to the SiPy1?

                      C 1 Reply Last reply Reply Quote 0
                      • C Offline
                        crumble @Meirssv
                        last edited by

                        @meirssv said in SiPy + PyTrack: GPS Example simplified to basic GPS only fails with MemoryError:

                        @crumble If you buy a PyTrack, especially designed to put on a LoPy or SiPy or WhateverPy, you'd expect the core function (GPS) to work with one of these Py-boards, I guess not.

                        Hardware is working. If you look on the software, all is marked as beta. Reading the data from the GPS chip works fine. So you got all they promised. Converting the GPS data in a format which is more user friendly seems to be the task of the community. The actual l76gnss library seems to be an example how to receive the data from the chip.

                        There is plenty of information from the GPS chip which the library does not deal with. Or there are features missing, like callbacks when you enter an area. But implementing the whole stuff means, that you waist a lot of RAM and flash. There is no linker which removes unused features. If we have such limited resources, we have to implement for each project only the parts we need.

                        Yes, the MicroPython part is much easier as reading the documentation of each chip and counting bits and cycles, but you still have to know what you are doing. Don't trust the propaganda ;) There will be never a system where you need no knowledge and skills to invent stuff.

                        Would an upgrade to the upcoming LoPy4 be a resolution? It has 4x RAM and twice the flash of the SiPy1 and it because it adds SigFox to the Lora radio, so it would be an alternative to the SiPy1?

                        Yes. Throwig hardware against the lib shall work.
                        And it will be much more as 4 times of RAM. A LoPy has around 64k free RAM. The newer models will have around 3MB. But additinally to the Guru Meditations we will get Chip and FastRAM again ;) (see the good old Comodore Amiga refernces) . OK, as far as I understood the MicroPython 1.9 docu, the external RAM is implemented as some kind of virtual memory. So we do not have to take care of it, unless we run into performance problems.

                        Maybe there are two solutions with the actual lib and old hardware.

                        • Reduce the timeout settings, so that there will be less strings created until a gc.colltect() is called. And call gc.collect() in front of the l76.coordinates()

                        • Place some gc.collect() in the lib. But this will be a performance decrease.

                        M 1 Reply Last reply Reply Quote 0
                        • M Offline
                          Meirssv @crumble
                          last edited by

                          @crumble said in SiPy + PyTrack: GPS Example simplified to basic GPS only fails with MemoryError:

                          Hardware is working. If you look on the software, all is marked as beta. Reading the data from the GPS chip works fine. So you got all they promised.

                          You've got a point there... I was assuming these libraries were mostly finished libs, did not really think about it in that way.

                          1 Reply Last reply Reply Quote 0
                          • M Offline
                            Meirssv @livius
                            last edited by

                            @livius said in SiPy + PyTrack: GPS Example simplified to basic GPS only fails with MemoryError:

                            what if you change line 74 and 75 to

                                            if len(nmea) > 1024: # i suppose here can be safe changed to 82 which is longest NMEA frame
                                                nmea = nmea[-5:] #   $GNGL without last L
                            

                            Success! This is now running more then 12 hours and got a fix, without MemoryError. Thanks!

                            L 1 Reply Last reply Reply Quote 0
                            • L Offline
                              livius @Meirssv
                              last edited by

                              @meirssv
                              Thank you for confirmation
                              i have created pull request with the change
                              https://github.com/pycom/pycom-libraries/pull/43

                              think about people first, then computers

                              1 Reply Last reply Reply Quote 1
                              • R Offline
                                robmarkcole
                                last edited by

                                Picking up this thread, I want to read my GPS coords with my lopy. Using the following I get no data - I am inside the house so presumably this is just a reception issue?

                                from L76GNSS import L76GNSS
                                >>> from pytrack import Pytrack
                                >>> py = Pytrack()
                                >>>
                                >>> l76 = L76GNSS(py, timeout=60)
                                >>> coord = l76.coordinates()
                                >>> print("{}".format(coord))
                                (None, None)
                                
                                sebS 1 Reply Last reply Reply Quote 0
                                • sebS Offline
                                  seb @robmarkcole
                                  last edited by

                                  @robmarkcole

                                  It can sometime take a while to acquire a lock. Try placing the Pytrack somewhere with a clear line of sight to the sky, such a window and leave it there for a few minutes.

                                  1 Reply Last reply Reply Quote 0
                                  • A Offline
                                    andrethemac @Meirssv
                                    last edited by

                                    @meirssv I've managed to construct a GPS tracker with a SiPy module. But I've use this gps lib ( https://forum.pycom.io/post/16183 ) from neuromistyx. Works great. because L76 is slow I've added a timeout of 3 minutes.

                                    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