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

    Lopy with pytrack, how connect/use GPS?

    Scheduled Pinned Locked Moved LoPy
    gpslopypytrack
    76 Posts 5 Posters 33.6k Views 5 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.
    • Z Offline
      zceld
      last edited by

      @zceld

      I am happy to inform you that with this code I have at least managed to obtain coordinates without failure:

      Code:

      import machine
      import math
      import network
      import os
      import time
      import utime
      from machine import RTC
      from machine import SD
      from machine import Timer
      from L76GNSS import L76GNSS
      from pytrack import Pytrack
      # setup as a station
      
      import gc
      
      time.sleep(2)
      gc.enable()
      
      # setup rtc
      rtc = machine.RTC()
      rtc.ntp_sync("pool.ntp.org")
      utime.sleep_ms(750)
      print('\nRTC Set from NTP to UTC:', rtc.now())
      utime.timezone(7200)
      print('Adjusted from UTC to EST timezone', utime.localtime(), '\n')
      py = Pytrack()
      l76 = L76GNSS(py, timeout=30)
      chrono = Timer.Chrono()
      chrono.start()
      #sd = SD()
      #os.mount(sd, '/sd')
      #f = open('/sd/gps-record.txt', 'w')
      while (True):
      
      coord = l76.coordinates()
      #f.write("{} - {}\n".format(coord, rtc.now()))
      print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free()))
      

      Result:

      0_1516214696327_Captura de pantalla 2018-01-17 19.38.15.png

      Thank you very much to all of you who have had to endure my clumsiness and have helped me especially: @seb and @livius, include @crumble ! :-)

      taking advantage of the post with the doubts and problems that I have had, I will shortly upload a guide in Spanish (since it is already in English) on the subject to facilitate other people.

      1 Reply Last reply Reply Quote 0
      • O Offline
        olliec
        last edited by

        @zceld I appear to be having a similar issue that you were having, with a LoPy4 and PyTrack.
        My error however is "I2C bus error"..

        I've updated the PyTrack to 0.0.8 (tried via Windows 10 and Debian) and LoPy4 to 1.14.0.b1, ran "os.mkfs('/flash')" and re-uploaded the files from a ZIP download of the Git (https://github.com/pycom/pycom-libraries).

        This is what I get (I added the "print(e)" in pycoproc.py which is returning "I2C bus error"):

        0_1516209064068_Capture.PNG

        @zceld - was there anything else you did other than update PyTrack via your Mac?!

        Z 1 Reply Last reply Reply Quote 0
        • Z Offline
          zceld @olliec
          last edited by zceld

          @olliec said in Lopy with pytrack, how connect/use GPS?:

          was there anything else you did other than update PyTrack via your Mac?!

          hello, well, you'll see that the only thing I did was really update, I attached the screenshots of what I did. I honestly do not know why you can fail, surely you can get a hand those who really know. The teachers who have guided me.

          Screenshots:
          0_1516224146742_Captura de pantalla 2018-01-17 22.22.15.png

          0_1516224269789_Captura de pantalla 2018-01-17 22.24.16.png

          Greetings, I will be here attentive to your problem to know how it is solved. luck.

          O 1 Reply Last reply Reply Quote 0
          • O Offline
            olliec @zceld
            last edited by

            @zceld :( yeah I think my error is different.. I'll start a new thread. Thanks anyways!

            Z 1 Reply Last reply Reply Quote 0
            • Z Offline
              zceld @olliec
              last edited by

              @olliec good luck!

              1 Reply Last reply Reply Quote 0
              • sebS Offline
                seb
                last edited by

                Hi,

                I'm glad you got it working! The out of memory issue is a known problem with the GPS library on our older devices that have less RAM. This is due to the large amount of string data that needs to be processed. The advice is to retry a few times and once it gets a lock it will start working. This library will need to be improved in the future to try fix this.

                It is very interesting that the update via windows didnt work but via mac it did, I will pass this on to the rest of the team.

                Thanks,
                Seb

                Z 1 Reply Last reply Reply Quote 0
                • Z Offline
                  zceld @seb
                  last edited by

                  @seb
                  Good afternoon, I just got back on.
                  Seeing that happiness is not forever. Since today again I have not managed to obtain GPS coordinates. I'm back in Windows, I'll mention it, but I do not think the problem comes from here. The story is that he always runs out of memory.0_1516286186039_1.PNG

                  Is there anything I can do ?

                  Z L C 3 Replies Last reply Reply Quote 0
                  • Z Offline
                    zceld @zceld
                    last edited by zceld

                    @seb
                    Apart from the memory issue, I do not know how to solve it. I have other doubts to see if you can help me:

                    • Every time I run 'gc.mem_gree ()'. Am I occupying memory? More than anything because as you can see in the image is going down the amount of free memory, until I run 'gc.colletct ()' that seems to empty the cache. It is right ? Image:
                      0_1516290411473_2.PNG

                    -On the other hand, executing 'gc.collect ()' and then executing this code to obtain the coordinates, it seems that I avoid the full memory error, but instead it always stays that way and does not continue until I cancel. The doubt is that I do not know if it is because it does not find GPS today or what happens ...
                    code:

                    import machine
                    import math
                    import network
                    import os
                    import time
                    import utime
                    from machine import RTC
                    from machine import SD
                    from machine import Timer
                    from L76GNSS import L76GNSS
                    from pytrack import Pytrack
                    # setup as a station
                    
                    import gc
                    
                    time.sleep(2)
                    gc.enable()
                    
                    # setup rtc
                    rtc = machine.RTC()
                    rtc.ntp_sync("pool.ntp.org")
                    utime.sleep_ms(750)
                    print('\nRTC Set from NTP to UTC:', rtc.now())
                    utime.timezone(7200)
                    print('Adjusted from UTC to EST timezone', utime.localtime(), '\n')
                    py = Pytrack()
                    l76 = L76GNSS(py, timeout=30)
                    chrono = Timer.Chrono()
                    chrono.start()
                    #sd = SD()
                    #os.mount(sd, '/sd')
                    #f = open('/sd/gps-record.txt', 'w')
                      while (True):
                         coord = l76.coordinates()
                         #f.write("{} - {}\n".format(coord, rtc.now()))
                         print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free()))
                    

                    0_1516290424908_3.PNG

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

                      @zceld

                      Apart from the memory issue, I do not know how to solve it

                      use simple fix for this
                      https://github.com/pycom/pycom-libraries/pull/43/files

                      think about people first, then computers

                      Z 1 Reply Last reply Reply Quote 0
                      • Z Offline
                        zceld @livius
                        last edited by

                        @livius said in Lopy with pytrack, how connect/use GPS?:

                        use simple fix for this

                        This solution and you told me about it and the thing is that you have to replace lines 74 and 75 with the lines that are in green, right?
                        0_1516291101532_4.PNG

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

                          @zceld
                          Yes, but you have indentation problem
                          remember that python work on proper indentation.
                          nmea line must be indented

                          think about people first, then computers

                          Z 1 Reply Last reply Reply Quote 0
                          • Z Offline
                            zceld @livius
                            last edited by

                            @livius said in Lopy with pytrack, how connect/use GPS?:

                            @zceld
                            Yes, but you have indentation problem
                            remember that python work on proper indentation.
                            nmea line must be indented

                            I suppose you mean this:
                            0_1516291578535_5.PNG
                            But then how do I fix it?

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

                              @zceld
                              0_1516291674076_70f8f1fd-c46e-4ca8-87d2-e34858750cce-image.png

                              think about people first, then computers

                              Z 1 Reply Last reply Reply Quote 0
                              • Z Offline
                                zceld @livius
                                last edited by

                                @livius

                                Perfect!. working correctly again. I do not understand how a tabulation can give an error. XDD it shows that I am new? Thank you very much again, although I'll probably come back with something else. But good Thanks to your patience as always.

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

                                  @zceld

                                  Is there anything I can do ?

                                  You can try to call the garbage collector before and after you read the coordinates.

                                  The better solution. Implement the GPS stuff by your own and share the code with us. You have to read the stream from the GPS chip into fix allocated buffers and parse them by your own. If you need only the coordinates, it is simple, you will need around 100 lines of code. I stuck with my version :-(. Had no time to work on it.

                                  L 1 Reply Last reply Reply Quote 0
                                  • Z Offline
                                    zceld @zceld
                                    last edited by

                                    @livius
                                    Well, I have another doubt. I am trying to send the coordinates by LoRa and it gives me the following problem that I do not know how to solve.
                                    0_1516292916315_6.PNG

                                    Other questions more:

                                    print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free()))
                                    

                                    This returns (latitude, longitude) - (Real time clock) - free ram
                                    But and the altitude?
                                    The time can be updated?

                                    L C 2 Replies Last reply Reply Quote 0
                                    • L Offline
                                      livius @zceld
                                      last edited by livius

                                      @zceld said in Lopy with pytrack, how connect/use GPS?:
                                      touple is not buffered
                                      you need bytes you can try to cast this as bytes() but for lora better is using pack.
                                      look at samples about lora in official docs https://docs.pycom.io/

                                      Time you can update from wifi connection
                                      by e.g.

                                      rtc.ntp_sync("pool.ntp.org")
                                      

                                      or retrive it from GPS
                                      or some external device for DCF or MSF

                                      think about people first, then computers

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

                                        @zceld

                                        But and the altitude?
                                        The time can be updated?

                                        If you look into the code of the library you will see, that only the coordinates are read from the GPS. No altitude and no dateTime.

                                        The time information is read from WiFi. You will need access to an NTP server.

                                        The sentence which is used to get the coordinates contains the time as well, but not the date. If you need only the time, you can simply add this to the library.

                                        For date and time you have to add support for parsing additional NMEA sentences.

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

                                          @crumble
                                          better use existing one
                                          https://github.com/livius2/micropyGPS
                                          and exctend it if needed

                                          think about people first, then computers

                                          Z 1 Reply Last reply Reply Quote 0
                                          • Z Offline
                                            zceld @livius
                                            last edited by

                                            @livius
                                            Thank you very much for the recommendation but using 'microGPS' gives me a lack of memory again.
                                            0_1516633835702_7.PNG

                                            On the other hand I do not know if to take advantage of this post or open another one. It is on the subject LoRa that I do not understand very well the programming examples. I am using this one.

                                            Using a board in sending mode, and another in receiver mode, I do not understand why there are messages sent by LoRa that are lost or not picked up by the receiver.
                                            This captur reciver:
                                            0_1516634446145_8.PNG

                                            transmitter:0_1516634503753_9.PNG
                                            print:
                                            identifier-identifier-counter-longitude-latitude

                                            As you can see in the image of the receiver, it goes from counter 7 to 10 and has lost message 8 and 9

                                            • issuer code:
                                            import machine
                                            import math
                                            import network
                                            import os
                                            import time
                                            import utime
                                            import pycom
                                            from machine import RTC
                                            from machine import SD
                                            from machine import Timer
                                            from L76GNSS import L76GNSS
                                            from pytrack import Pytrack
                                            
                                            from network import LoRa
                                            import socket                                                                 
                                            lora = LoRa(mode=LoRa.LORA)                                                  
                                            s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)                   
                                            # setup as a station
                                            
                                            import gc
                                            
                                            time.sleep(2)
                                            gc.enable()
                                            
                                            # setup rtc
                                            rtc = machine.RTC()
                                            rtc.ntp_sync("pool.ntp.org")
                                            utime.sleep_ms(750)
                                            print('\nRTC Set from NTP to UTC:', rtc.now())
                                            utime.timezone(7200)
                                            print('Adjusted from UTC to EST timezone', utime.localtime(), '\n')
                                            py = Pytrack()
                                            l76 = L76GNSS(py, timeout=30)
                                            chrono = Timer.Chrono()
                                            chrono.start()
                                            j=0 #accountant
                                            while (True):
                                            
                                                coord = l76.coordinates()
                                            
                                                #Codigo Personalizado para enviar por LoRa Posicon:
                                                x = "witeklab-"+"12345678Z-"+str(j)+"-"+str(coord[0]) + "-"+str(coord[1])
                                                s.setblocking(True)
                                                s.send(x)
                                                print(x)
                                                time.sleep(2) #Pausa entre toma de coordenadas.
                                                j=1+j
                                            

                                            receiver code:

                                            from network import LoRa
                                            import socket
                                            import machine
                                            import time
                                            import pycom
                                            
                                            # initialize LoRa in LORA mode
                                            # more params can also be given, like frequency, tx power and spreading factor
                                            lora = LoRa(mode=LoRa.LORA)
                                            
                                            # create a raw LoRa socket
                                            s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
                                            
                                            while True:
                                                # send some data
                                                for x in range(5):
                                            
                                                  s.setblocking(False)
                                                  data = s.recv(64)
                                                  time.sleep(0.1)
                                                  print(data)
                                            C L 2 Replies 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
                                            • 1 / 4
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom