Changing Arduino_MKRGPS library to use Serial2

Hello!

I am currently working on a project involving cellular and GPS capabilities. Specifically, a friend of mine and I are working with the "Arduino MKR compatible LTE/GNSS BG95 Shield" and the "Arduino MKR GPS Shield." We are trying to get the cellular shield and the GPS shield to communicate with our Arduino MKR Zero microcontroller, although both shields use the same hardware serial Serial1 communication interface. It appears that the cellular board is hard coded to certain pins that correspond to Serial1, and it cannot be changed.

So, we are trying to change the MKR GPS library to use Serial2 instead of Serial1. We've setup Serial2 as an additional UART interface, (using this tutorial: https://docs.arduino.cc/tutorials/communication/SamdSercom) but we cannot figure out how to have the MKR GPS library use the Serial2 instead of Serial1. Would anyone be able to help us out with this?

Thanks so much in advance!

Try just changing that last line in the library

And use

GPSClass GPS(Serial2, 9600, serialDDC, 400000, 7);

This is what defines the global instance

You might have some small issues about Serial2 not known so might need to declare that as extern for the library to link

Alternatively remove the line and add it in your own .ino to create your own instance of the GPSClass using Serial2 in which case the line in the .h Arduino_MKRGPS/GPS.h at 071ab7a98fe14768b39e995bb200ee3f9af41084 · arduino-libraries/Arduino_MKRGPS · GitHub where it’s defined as extern is probably no longer needed

(Typed from my iPhone so can’t really test)

Thank you for your help! I was able to take the last 2 lines:

289. static SerialDDC serialDDC(Wire, 0x42, 0xfd, 0xff);
290. GPSClass GPS(Serial2, 9600, serialDDC, 400000, 7);

and add this to my sketch to get the MKR_GPS to work on my Serial2.

great - glad it helped !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.