Hello,
I am having trouble getting the SS1306 OLED to work with RP2040, could be an issue with the I2C. The OLED works fine in 5V logic on arduino uno but even following a few tutorials for similar screen and using several libraries, I cannot get the screen to work. Not sure if I need to configure I2C and SDA in code. Please advise.
//128X64 OLED - ADAFRUIT GPS
//OLED DECLARATIONS
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
#define I2C_ADDRESS 0x3C // 0X3C+SA0 - 0x3C or 0x3D
#define RST_PIN -1 // Define proper RST_PIN if required.
SSD1306AsciiAvrI2c oled;
//GPS VARIABLES & DECLARATIONS
#include <Adafruit_GPS.h> //Load the GPS Library. Make sure you have installed the library form the adafruit site above
#include <SoftwareSerial.h> //Load the Software Serial Library. This library in effect gives the arduino additional serial ports
SoftwareSerial mySerial(2, 3); //Initialize SoftwareSerial(RX 2, TX 3), and tell it to connect through pins 2 and 3
Adafruit_GPS GPS(&mySerial); //Create GPS object
String NMEA1; //We will use this variable to hold our first NMEA sentence
String NMEA2; //We will use this variable to hold our second NMEA sentence
char c; //Used to read the characters spewing from the GPS module
void setup() {
Serial.begin(115200); //Turn on the Serial Monitor
GPS.begin(9600); //Turn GPS on at baud rate of 9600
GPS.sendCommand("$PGCMD,33,0*6D"); // Turn Off GPS Antenna Update
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Tell GPS we want only $GPRMC and $GPGGA NMEA sentences
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
delay(1000); //Pause
#if RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0
// Call oled.setI2cClock(frequency) to change from the default frequency.
oled.setFont(Adafruit5x7);
uint32_t m = micros();
oled.clear();
//oled.println("GPS: FIX | LoRa: RX");
}
void loop() {
readGPS(); //This is a function we define below which reads two NMEA sentences from GPS
}
void readGPS(){ //This function will read and remember two NMEA sentences from GPS
clearGPS(); //Serial port probably has old or corrupt data, so begin by clearing it all out
while(!GPS.newNMEAreceived()) { //Keep reading characters in this loop until a good NMEA sentence is received
c=GPS.read(); //read a character from the GPS
}
GPS.parse(GPS.lastNMEA()); //Once you get a good NMEA, parse it
NMEA1=GPS.lastNMEA(); //Once parsed, save NMEA sentence into NMEA1
while(!GPS.newNMEAreceived()) { //Go out and get the second NMEA sentence, should be different type than the first one read above.
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
NMEA2=GPS.lastNMEA();
Serial.println(NMEA1);
Serial.println(NMEA2);
Serial.println("");
}
void clearGPS() { //Since between GPS reads, we still have data streaming in, we need to clear the old data by reading a few sentences, and discarding these
while(!GPS.newNMEAreceived()) {
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
while(!GPS.newNMEAreceived()) {
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
//OLED PRINT SECTION
{
//FIX
oled.setCursor(0,0);
oled.print("GPS Fix: "); oled.print((int)GPS.fix); oled.print("|"); oled.print((int)GPS.fixquality); oled.print(" Sat: "); oled.println((int)GPS.satellites);
//DATE
oled.setCursor(0,1);
oled.print("Date: "); oled.print(GPS.month, DEC); oled.print('/'); oled.print(GPS.day, DEC); oled.print("/20"); oled.println(GPS.year, DEC);
//CLOCK
int t1;
String t2;
int t3;
String t4;
oled.setCursor(0,2);
oled.print("Time: ");
if (GPS.hour < 8) {
t1 = GPS.hour + 16;
if (t1 < 10){t2 = "0" + t1;
oled.print(t2);oled.print(':');}
else {
t2 = t1;
oled.print(t2);oled.print(':');
}
}
else{
t3 = GPS.hour - 8;
if (t3 < 10){t4 = "0" + t3;
oled.print(t4);oled.print(':');}
else {
t4 = t3;
oled.print(t4);oled.print(':');
}
}
if (GPS.minute < 10) { oled.print('0'); }
oled.print(GPS.minute, DEC); oled.print(':');
if (GPS.seconds < 10) { oled.print('0'); }
oled.print(GPS.seconds, DEC);
oled.setCursor(0,3);
oled.print("Lat: "); oled.print(GPS.latitude/100, DEC); oled.print(GPS.lat);
oled.setCursor(0,4);
oled.print("Long: "); oled.print(GPS.longitude/100, DEC); oled.print(GPS.lon);
oled.setCursor(0,5);
oled.print("Speed (kt): "); oled.print(GPS.speed);
oled.setCursor(0,6);
oled.print("Ang: "); oled.println(GPS.angle);
oled.setCursor(0,7);
oled.print("Alt: "); oled.print(GPS.altitude, 1); oled.print("m ("); oled.print(GPS.altitude *3.28084, 0); oled.print("ft)");
delay(10000);
oled.clear();
oled.setCursor(0,0);
oled.print("LoRa RFM96X Messages:");
oled.setCursor(0,1);
oled.print("TX: "); //ADD msg HERE
oled.setCursor(0,5);
oled.print("RX: "); //ADD msg HERE
delay(5000);
oled.clear();
}
}