//Compass code by toniz https://forum.arduino.cc/t/gps-and-compass/1101707/25?page=3
//GPS code from https://lastminuteengineers.com/neo6m-gps-arduino-tutorial/
//Direction https://forum.arduino.cc/t/direction-course-from-tinygps-plus-library/448207
//Commands Self
//Direction -35.67593568404272, 147.51781339739313
#define des_LAT -35.67593568404272
#define des_LNG 147.51781339739313
//Compass
#include <Wire.h>
#include <QMC5883LCompass.h>
QMC5883LCompass compass;
//Gps
#include <TinyGPS++.h>
#include <PicoSoftwareSerial.h>
int RXPin = 21;
int TXPin = 16;
int GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial gpsSerial(RXPin, TXPin);
void setup()
{
//Compass
Serial.begin(115200);
Wire.begin();
compass.init();
//GPS
gpsSerial.begin(GPSBaud);
}
void loop()
{
//Compass
int x, y, z;
compass.read();
x = compass.getX();
y = compass.getY();
z = compass.getZ();
float heading = atan2(y, x);
if(heading < 0) heading += 2*PI;
float headingDegrees = heading * 180/M_PI;
//GPS
while (gpsSerial.available() > 0)
if (gps.encode(gpsSerial.read()))
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.print(" No GPS detected");
while(true);
}
if (gps.location.isValid())
{
Serial.print("| Lat: ");
Serial.print(gps.location.lat(), 6);
Serial.print(" | Long: ");
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(" Location: Not Available");
}
Serial.print(" | Hed: ");
Serial.print(headingDegrees);
Serial.print("*");
//Direction
double distanceToDestination = TinyGPSPlus::distanceBetween(gps.location.lat(), gps.location.lng(), des_LAT, des_LNG);
double courseToDestination = TinyGPSPlus::courseTo(gps.location.lat(), gps.location.lng(), des_LAT, des_LNG);
const char *directionToDestination = TinyGPSPlus::cardinal(courseToDestination);
int courseChangeNeeded = (int)(360 + courseToDestination - headingDegrees)% 360;
courseChangeNeeded= map(courseChangeNeeded, 0, 360, 180, -180);
Serial.print(" | DistRemain= ");
Serial.print(distanceToDestination);
Serial.print("m, | CourseAdjust= ");
Serial.print(courseChangeNeeded);
Serial.print(" | Speed: ");
Serial.print(gps.speed.kmph());
Serial.println("Km/h|");
}
//Commands
this code is for a GPS and Compass combo originally written to work on a Arduino uno but i need to convert it so it can work (still in C++) on a Raspberry Pico. I have got the GPS working but i am having trouble with the multiple I2C pins on the Pico and how to specify which pins to use.