HardwareSerial ss(2)? UART connection on 16/17 for a GPS Antenna



  • I am hoping someone can clear up some confusion for me about the way to access/use pins 16/17 on my Grey.

    Simple Question: How do I use HardwareSerial with pins 16/17 to communicate with a GPS antenna?

    More about what I am doing and have tried:

    I am trying to use the AT6558 GPS Unit with my grey realizing that it doesn't have the correct GROOVE port without the M5GO Bottom 2. So I have hooked it up to 5v/GND and pins 16/17, but I am still not getting any data transfer. I believe the issue might be with the approach.

    Using the sample code as a guide I am declaring HardwareSerial ss(2). I haven't found documentation on what (0) and (2) are but I assume they are for the different GROOVE ports, 2 being "C", and 0 being "A". Is that correct?

    In my setup() I have tried various things to initialize including
    Serial2.begin(19200, SERIAL_8N1, RX_PIN, TX_PIN) //I defined the rx and tx pins earlier as 16/17
    ss.begin(GPSBaud, SERIAL_8N1, RX_PIN, TX_PIN) // I tried this based on some forum posts I found. the GPSBaud is9600 per the Unit's product page.
    ss.begin(GPSBaud)

    I have tried both Serial2.begin and ss.begin(GPSBaud) in the same sketch, tried just the ss.begin with the additional info and also just the ss.begin(GPSBaud). Nothing seems to make any difference. The rest of my code is just trying to pull Lat/lon and if tried using the TinyGPS++ examples to pull just the basics as well as some other methods with TinyGPS sending some NMEA data pulling RMCONLY which i have used in the past on other GPS modules and projects.

    So I believe my issue comes down to actually declaring pin 16/17. I thought using HardwareSerial(2) would automatically declare those pins, but when i dug into some of the libraries, specifically M5LoRa i found that the default SS pin is 6 and is declared in the SPISettings.

    I know that was long winded but hopefully makes sense.

    Thanks for any and all feedback!



  • I still haven't had any luck cracking this one. Does anyone know if there is a difference from the way the M5GO bottom accesses 16/17 for RxTx vs just connecting to those pins that are open? I can't imaging there would be some difference to the way those pins are defined. I assumed the HardwareSerial ss(2) is calling those pins.



  • Slight update. On a hunch I ran the code over the serial monitor and I am pulling in data. The same code that is giving me results in the serial monitor is having issues when i try to initialize the M5Stack display.

    The code i grabbed was the "KitchenSink" from the TinyGPS++ library. This was originally setup for SoftwareSerial so I tweaked it to this.

    **#include <TinyGPS++.h>
    #include <M5Stack.h>

    static const uint32_t GPSBaud = 9600;
    #define RX_PIN 16
    #define TX_PIN 17

    // The TinyGPS++ object
    TinyGPSPlus gps;

    HardwareSerial ss(2);

    // For stats that happen every 5 seconds
    unsigned long last = 0UL;

    void setup()
    {
    Serial.begin(115200);
    ss.begin(GPSBaud, SERIAL_8N1, RX_PIN, TX_PIN);**

    Something happens when i try to initialize the M5stack though. If i put M5.begin, or M5.Power.begin() in the code it doesn't seem to work.

    So what "wires" are getting crossed here? It is reading data and showing on the serial monitor without .begin() on the M5 just fine, but i can't get it to initialize and show me the location on the display.

    Thanks.



  • Hello @Shift1313

    I think you are very close, just get rid of the Serial.begin(115200); when you add M5.begin() and M5.Power.begin().

    There is another Serial.begin() inside M5.begin() and ESP32 doesn't like it when the same serial port is initialized twice.

    Good luck!

    Thanks
    Felix



  • @felmue said in HardwareSerial ss(2)? UART connection on 16/17 for a GPS Antenna:

    Hello @Shift1313

    I think you are very close, just get rid of the Serial.begin(115200); when you add M5.begin() and M5.Power.begin().

    There is another Serial.begin() inside M5.begin() and ESP32 doesn't like it when the same serial port is initialized twice.

    Good luck!

    Thanks
    Felix

    Thanks Felix! I did get it working yesterday without the serial.begin like you said but didn't understand why that was the case. I thought this would be the simple part!

    I'm going to work on a simple example I hope and post it back here.

    Thanks again!



  • Ok, here is the simple program I came up with using the TinyGPS++ library. Hopefully It will help someone else who comes across this same problem. I still don't know what I can do to access the correct GROOVE port since the M5 base is for Core2, but at least I have a temp solution to keep developing my project.

    The complete program below works on my Core Gray with pins connecting my AT6550 to 5v, gnd, 16 and 17 on the core. This uses lat, long and speed on a simple display that is easy to read.

    #include <M5Stack.h>
    #include <TinyGPS++.h>

    static const uint32_t GPSBaud = 9600;

    TinyGPSPlus gps;

    HardwareSerial ss(2);

    void setup() {
    M5.begin();
    M5.Power.begin();
    ss.begin(GPSBaud, SERIAL_8N1, 16, 17);
    M5.Lcd.setTextSize(4);
    M5.Lcd.setCursor(40,10);
    M5.Lcd.println("Simple GPS");
    M5.Lcd.println("_____________");

    }

    void loop() {

    while (ss.available() > 0)
    gps.encode(ss.read());

    M5.Lcd.setTextSize(3);

    M5.Lcd.setCursor(0,100);
    M5.Lcd.printf("Lat: ");
    M5.Lcd.setCursor(100,100);
    M5.Lcd.print(gps.location.lat(), 6);

    M5.Lcd.setCursor(0,150);
    M5.Lcd.printf("Lon: ");
    M5.Lcd.setCursor(100,150);
    M5.Lcd.print(gps.location.lng(), 6);

    M5.Lcd.setCursor(0,200);
    M5.Lcd.printf("MPH ");
    M5.Lcd.setCursor(100,200);
    M5.Lcd.print(gps.speed.mph());

    }