I have this board: https://www.sparkfun.com/products/14414
And can run it using a SAMD21 just fine in standard i2c configuration.
However, I need to run this using a second i2c. The code is:
#define GNSS_PIN 5
// create a second serial for the GNSS module
// https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-wire
// SDA on 11 / SCL on 13
#include <Wire.h>
#include "wiring_private.h" // pinPeripheral() function
TwoWire Wire2(&sercom1, 11, 13);
#include <SparkFun_I2C_GPS_Arduino_Library.h>
I2CGPS GNSS;
#include <TinyGPS++.h>
TinyGPSPlus gps;
TinyGPSCustom pdop(gps, "GPGSA", 15); // $GPGSA sentence, 15th element
TinyGPSCustom hdop(gps, "GPGSA", 16); // $GPGSA sentence, 16th element
TinyGPSCustom vdop(gps, "GPGSA", 17); // $GPGSA sentence, 17th element
String response;
void setup() {
pinMode(GNSS_PIN, OUTPUT);
digitalWrite(GNSS_PIN, HIGH);
// Assign pins 11 & 13 to SERCOM functionality
pinPeripheral(11, PIO_SERCOM);
pinPeripheral(13, PIO_SERCOM);
Wire2.begin();
Serial.begin(115200);
Serial.println("GTOP Read Example");
if (GNSS.begin(Wire2) == false) {
Serial.println("Module failed to respond. Please check wiring.");
}
Serial.println("GPS module found!");
GNSS.enableDebugging();
}
void loop() {
//available() returns the number of new bytes available from the GPS module
//Serial.println("Wake up GNSS ...");
//response = GNSS.wakeup();
//Serial.println("GNSS says: "+response);
Serial.println("GNSS Module data: ");
while (GNSS.available()) {
gps.encode(GNSS.read()); //Feed the GPS parser
}
//Check to see if new GPS info is available
if (gps.time.isUpdated()) {
displayInfo();
}
delay(1000);
//Serial.println("Put GNSS asleep ...");
//response = GNSS.standby();
//Serial.println("GNSS says: "+response);
// response = "";
// while (GNSS.available()) {
// response += GNSS.read(); //Feed the GPS parser
// }
// Serial.println(response);
//delay(5000);
}
//Display new GPS info
void displayInfo() {
//We have new GPS data to deal with!
Serial.println();
if (gps.time.isValid()) {
Serial.print(F("Date: "));
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
Serial.print((" Time: "));
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(".");
Serial.println(gps.time.centisecond());
Serial.print("Time age: ");
Serial.print(gps.time.age());
Serial.println(); //Done printing time
} else {
Serial.println(F("Time not yet valid"));
}
if (gps.location.isValid()) {
Serial.print("Latitude: ");
Serial.println(gps.location.lat(), 6);
Serial.print("Longitude: ");
Serial.println(gps.location.lng(), 6);
Serial.print("Altitude: ");
Serial.println(gps.altitude.meters(), 3);
Serial.print("PDOP: ");
Serial.println(pdop.value());
Serial.print("HDOP: ");
Serial.println(hdop.value());
Serial.print("VDOP: ");
Serial.println(vdop.value());
Serial.print("Satellites: ");
Serial.println(gps.satellites.value(), gps.satellites.isValid());
Serial.print("Location age: ");
Serial.print(gps.location.age());
Serial.println();
} else {
Serial.println(F("Location not yet valid"));
}
}
This code doesn’t produce any output via serial. However, when I delete Wire2 from GNSS.begin(), the it loops at least.
What am I doing wrong? Is this a bug in the SparkFun_I2C_GPS_Arduino_Library ??