🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    First Project - GPS on Core2 w/ UIFlow2.0

    PROJECTS
    3
    9
    2.9k
    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.
    • DeckyonD
      Deckyon
      last edited by

      So, I am working on a simple first project using the GPS. I am basing it off the one for the ENVII. I have a Core2 with UIFLow 2.0 Below is the code. It displays the labels, and displays what looks like data from the GPS, but it never changes and is not correct as if it is not finding satellites or even looking for them. Is there something else I need to do in the code to initialize the GPS Unit correctly. I am not a coder, this is literally my first time trying anything like this. I got the Core2 and the GPS to start learning. Yes, I have been outside and waited with clear skies and the Core2 has plenty of battery.

      import os, sys, io
      import M5
      from M5 import *
      from hardware import *
      from unit import GPSUnit

      rect0 = None
      rect1 = None
      rect2 = None
      rect3 = None
      rect4 = None
      label0 = None
      label1 = None
      label2 = None
      label3 = None
      label4 = None
      label5 = None
      label6 = None
      label7 = None
      label8 = None
      i2c0 = None
      gps_0 = None

      def setup():
      global rect0, rect1, rect2, rect3, rect4, label0, label1, label2, label3, label4, label5, label6, label7, label8, i2c0, gps_0

      i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000)
      gps_0 = GPSUnit((13, 14))
      gps_0.set_time_zone(-5)
      gps_0.uart_port_id(1)
      M5.begin()
      Widgets.fillScreen(0x5b5b5b)
      rect0 = Widgets.Rectangle(0, 0, 320, 23, 0xffffff, 0x000167)
      rect1 = Widgets.Rectangle(0, 215, 320, 23, 0xffffff, 0x000167)
      rect2 = Widgets.Rectangle(0, 30, 320, 47, 0xffffff, 0xfbff8e)
      rect3 = Widgets.Rectangle(0, 83, 320, 47, 0xffffff, 0x1c6527)
      rect4 = Widgets.Rectangle(0, 136, 320, 47, 0xffffff, 0x760000)
      label0 = Widgets.Label("label0", 2, 32, 1.0, 0x222222, 0xfbff8e, Widgets.FONTS.DejaVu18)
      label1 = Widgets.Label("label1", 2, 54, 1.0, 0x222222, 0xfbff8e, Widgets.FONTS.DejaVu18)
      label2 = Widgets.Label("label2", 2, 86, 1.0, 0xffffff, 0x1c6527, Widgets.FONTS.DejaVu18)
      label3 = Widgets.Label("label3", 2, 108, 1.0, 0xffffff, 0x1c6527, Widgets.FONTS.DejaVu18)
      label4 = Widgets.Label("label4", 2, 2, 1.0, 0xffffff, 0x000167, Widgets.FONTS.DejaVu18)
      label5 = Widgets.Label("label5", 217, 2, 1.0, 0xffffff, 0x000167, Widgets.FONTS.DejaVu18)
      label6 = Widgets.Label("label6", 2, 217, 1.0, 0xffffff, 0x000167, Widgets.FONTS.DejaVu18)
      label7 = Widgets.Label("label7", 2, 138, 1.0, 0xffffff, 0x760000, Widgets.FONTS.DejaVu18)
      label8 = Widgets.Label("label8", 2, 161, 1.0, 0xffffff, 0x760000, Widgets.FONTS.DejaVu18)

      def loop():
      global rect0, rect1, rect2, rect3, rect4, label0, label1, label2, label3, label4, label5, label6, label7, label8, i2c0, gps_0
      M5.update()
      label0.setText(str((str('Date: ') + str((gps_0.gps_date)))))
      label1.setText(str((str('Time: ') + str((gps_0.gps_time)))))
      label2.setText(str((str('Lat:') + str((gps_0.latitude)))))
      label3.setText(str((str('Long:') + str((gps_0.longitude)))))
      label4.setText(str((str('Sats:') + str((gps_0.satellite_num)))))
      label5.setText(str((str('Alt:') + str((gps_0.altitude)))))
      label6.setText(str((str('Quality:') + str((gps_0.pos_quality)))))
      label7.setText(str((str('Speed (KPH):') + str((gps_0.speed_kph)))))
      label8.setText(str((str('Course:') + str((gps_0.course)))))

      if name == 'main':
      try:
      setup()
      while True:
      loop()
      except (Exception, KeyboardInterrupt) as e:
      try:
      from utility import print_error_msg
      print_error_msg(e)
      except ImportError:
      print("please update to latest firmware")

      UIFlow 2

      Data So far on Core2

      1 Reply Last reply Reply Quote 0
      • robskiR
        robski
        last edited by robski

        @deckyon said in First Project - GPS on Core2 w/ UIFlow2.0:

        So, I am working on a simple first project using the GPS. I am basing it off the one for the ENVII. I have a Core2 with UIFLow 2.0 Below is the code. It displays the labels, and displays what looks like data from the GPS, but it never changes and is not correct as if it is not finding satellites or even looking for them. Is there something else I need to do in the code to initialize the GPS Unit correctly. I am not a coder, this is literally my first time trying anything like this. I got the Core2 and the GPS to start learning. Yes, I have been outside and waited with clear skies and the Core2 has plenty of battery.

        have you tried any of factory examples - easyloader or arduino for gps just to prove that it is working? also your GPS unit is the UART type - blue port correct? Do you have bottom expansion with blue port on your Core2? if no then you need to reconfigure it
        your code: gps_0 = GPSUnit((13, 14))
        GPS connected to PortA gps_0 = GPSUnit((33, 32))

        0_1707316513495_gpsuart.jpg

        GPS unit docs

        M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ

        DeckyonD 1 Reply Last reply Reply Quote 1
        • DeckyonD
          Deckyon @robski
          last edited by

          @robski Will check that when I get home. I was hoping to get comfortable with the whole UIFlow 2.0, not being a coder.

          robskiR 1 Reply Last reply Reply Quote 0
          • robskiR
            robski @Deckyon
            last edited by robski

            @deckyon sometimes is easier to show your hardware setup (picture) what modules and how you have connected to controller then code for crosscheck

            using red port I2c for unit with UART blue port needs to "tell" controller that it has to be configured with baudrate and parity matching gps unit its not only pin config

            M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ

            1 Reply Last reply Reply Quote 0
            • robskiR
              robski
              last edited by

              added photo explains it,
              you have no Core2 bottom extension with uart blue portC on it.
              you are connecting UART type gps unit (blue port) in to Core2 default I2C port - which can and needs to be reconfigured to accept UART type of communication

              M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ

              1 Reply Last reply Reply Quote 1
              • DeckyonD
                Deckyon
                last edited by

                @robski said in First Project - GPS on Core2 w/ UIFlow2.0:

                gps_0 = GPSUnit((33, 32))

                Did some fiddling, including finally figuring out how to make those changes, and it is now working! Now, to do some programming and figure out how to change the strings into ints so I can do some math conversions.
                Thanks all!

                also, need to come up with a real UI as well. But, I am just glad it is working.

                1 Reply Last reply Reply Quote 0
                • robskiR
                  robski
                  last edited by

                  nice one,

                  "Now, to do some programming and figure out how to change the strings into ints so I can do some math conversions"

                  from uiflow1 examples:
                  label0.set_text(str(gps_0.latitude))
                  label1.set_text(str(gps_0.longitude))
                  label2.set_text(str(gps_0.latitude_decimal))
                  label3.set_text(str(gps_0.longitude_decimal))

                  M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ

                  1 Reply Last reply Reply Quote 0
                  • ajb2k3A
                    ajb2k3
                    last edited by ajb2k3

                    @Deckyon the ports are colour coded for a reason. the GPS has a blue connector and is supposed to only connect to blue ports.

                    however the ESP32 using a connection matrix and as @robski pointed out you can redefine the pins a port uses. but may cause issue later on in code.

                    @robski said in First Project - GPS on Core2 w/ UIFlow2.0:

                    nice one,

                    "Now, to do some programming and figure out how to change the strings into ints so I can do some math conversions"

                    from uiflow1 examples:
                    label0.set_text(str(gps_0.latitude))
                    label1.set_text(str(gps_0.longitude))
                    label2.set_text(str(gps_0.latitude_decimal))
                    label3.set_text(str(gps_0.longitude_decimal))

                    in the maths menu you will find a Convert to int block designed just for this task.
                    0_1707385781517_Screenshot 2024-02-08 at 09.49.18.png

                    UIFlow, so easy an adult can learn it!
                    If I don't know it, be patient!
                    I've ether not learned it or am too drunk to remember it!
                    Author of the WIP UIFlow Handbook!
                    M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                    DeckyonD 1 Reply Last reply Reply Quote 0
                    • DeckyonD
                      Deckyon @ajb2k3
                      last edited by

                      @ajb2k3 I wanted to change the altitude to ft, speed to mph. I found the Maths group, but ended up having to first Convert to Float, then Convert to Int, then I could do the conversions. Also made the labels a bit easier to figure out at a glance.

                      lblAlt.setText(str((str('Alt (ft):') + str(((int(float(gps_0.altitude))) * 3.281)))))
                      lblSpd.setText(str((str('Speed (mph):') + str(((int(float(gps_0.speed_kph))) * 1.609)))))

                      Thanks for the assist. Now on to a cooler UI now that I have the data I want.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post