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.

    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



  • @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



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



  • @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



  • 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



  • @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.



  • 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))



  • @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



  • @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.