PA101D GPS module i2c comms (Arduino Yun)

I am trying to use the the PA101D GPS module from Pimoroni and having some odd behaviour using this breakout board. The aim of the project is to add different sensors and setup anchor watch with the GPS module. The problem is when I try to execute any other code with the GPS I2C comm's, I lost connection with the GPS module. For example if I try to write the GPS data to SD card, it will not read any data back from the GPS module.

I am using the Adafruit library "Adafruit_GPS.h" and the other examples i.e. parsing I2C have a similar problem. What I cannot understand from the data sheet is if the GPS module is buffering data which must be read out, I would have thought when reading the GPS using char c = GPS.read(); it would provide the latest position?

Has anyone used this GPS module with i2c and found a way just to poll it for data every few minutes and eliminated a conflict on the i2c bus?

#include <Adafruit_GPS.h>
#include "FS.h"
#include "SD.h"
#include "SPI.h"

// Connect to the GPS on the hardware I2C port
Adafruit_GPS GPS(&Wire);

void setup()
{
// wait for hardware serial to appear
while (!Serial);

// make this baud rate fast enough to we aren't waiting on it
Serial.begin(115200);
delay(1000);

Serial.println("Adafruit GPS library basic I2C test!");
GPS.begin(0x10); // The I2C address to use is 0x10
}

void loop() {
if (Serial.available()) {
char c = Serial.read();
GPS.write(c);
}
if (GPS.available()) {
char c = GPS.read();
appendFile(SD, "/gpstestfile.txt", "kkk");
Serial.write(c);
}
}

// SD functions

void readFile(fs::FS &fs, const char * path){
Serial.printf("Reading file: %s\n", path);

File file = fs.open(path);
if(!file){
    Serial.println("Failed to open file for reading");
    return;
}

Serial.print("Read from file: ");
while(file.available()){
    Serial.write(file.read());
}
file.close();

}

void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Writing file: %s\n", path);

File file = fs.open(path, FILE_WRITE);
if(!file){
    Serial.println("Failed to open file for writing");
    return;
}
if(file.print(message)){
    Serial.println("File written");
} else {
    Serial.println("Write failed");
}
file.close();

}

void appendFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Appending to file: %s\n", path);

File file = fs.open(path, FILE_APPEND);
if(!file){
    Serial.println("Failed to open file for appending");
    return;
}
if(file.print(message)){
    Serial.println("Message appended");
} else {
    Serial.println("Append failed");
}
file.close();

}

That code doesn't make sense to me. Writing three characters to the SD card for every byte read from the GPS makes the communication rather slow. You should at least read a complete NMEA record before writing to the card .

Have had similar problems with a Pimoroni GPS I2C module blending an SSD1306. Was basically an SRAM problem, I was using an UNO. Runs fine on a MEGA256. Not sure what H/Ware you're using but the behaviour you describe sounds a lot like my experience.

Also you don't need to include SPI.h in your sketch, the GPS lib drags it and others in upon compile. @chrisknightley kindly pointed this out, get a look at the below, line 62

Yep.
But it should be added that writing multiple #includes <SPI.h> doesn't cause any problems.

This is because the line 14, 15 and 324 of header file below coded that if it is already that included, it will be ignored altogether.
Below is the link to the SPI library.

I did wonder about that thnx.

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