Screen compatibility issues

I have been having a problem with a project that i am trying to complete, the project that i am trying to complete is a gps module (atgm336h) and DHT22 temperature and humidity sensor that will have there information stored locally in the non volatile memory and the speed and temp data will be displayed on a 0.96inch oled display, the data that is stored is the longitude, latitude, altitude, speed, date, time, temperature and humidity.i first tried this on the arduino uno but quickly ran out of storage space so i found a suitable replacement in the form of a waveshare RP2040 zero that has enough space to store data on the non volatile memory, but now i have found that the gps and dht22 data can be stored with no problems but the screen will not work i have writen code that is only to test the oled but nothing has worked so far.

here is the code that is to do everything

 #include <Arduino.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <TinyGPS++.h>
#include <DHT.h>
#include <EEPROM.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define DHT_PIN 8
#define DHT_TYPE DHT22
DHT dht(DHT_PIN, DHT_TYPE);

#define GPS_SERIAL Serial1 // UART1 for GPS
TinyGPSPlus gps;

void setup() {
  Serial.begin(9600);
  GPS_SERIAL.begin(9600);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  dht.begin();
  
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("GPS Speed & Temp");
  display.display();
  delay(2000);
  display.clearDisplay();
}

void loop() {
  while (Serial.available() > 0) {
    char receivedChar = Serial.read();
    
    if (receivedChar == '*') {
      printData(); // Print data when '*' is received
    }
    
    if (gps.encode(receivedChar)) {
      display.clearDisplay();
      display.setCursor(0, 0);
      
      if (gps.speed.isValid()) {
        display.print("Speed: ");
        display.print(gps.speed.kmph());
        display.println(" km/h");
      } else {
        display.println("Speed: N/A");
      }

      float temperature = dht.readTemperature();
      if (!isnan(temperature)) {
        display.print("Temp: ");
        display.print(temperature);
        display.println(" °C");
      } else {
        display.println("Temp: N/A");
      }
      
      display.display();
      
      // Store data in EEPROM
      storeData(temperature, gps.location.lng(), gps.location.lat(), gps.altitude.meters(), gps.speed.kmph(), gps.time.isValid() ? gps.time.hour() : -1, gps.date.isValid() ? gps.date.day() : -1, gps.date.isValid() ? gps.date.month() : -1, gps.date.isValid() ? gps.date.year() : -1);
    }
  }
}

void storeData(float temp, float lon, float lat, float altitude, float speed, int hour, int day, int month, int year) {
  // Define EEPROM addresses for data storage
  int address = 0; // Start address

  // Store the data in EEPROM
  EEPROM.put(address, temp);
  address += sizeof(temp);

  EEPROM.put(address, lon);
  address += sizeof(lon);

  EEPROM.put(address, lat);
  address += sizeof(lat);

  EEPROM.put(address, altitude);
  address += sizeof(altitude);

  EEPROM.put(address, speed);
  address += sizeof(speed);

  EEPROM.put(address, hour);
  address += sizeof(hour);

  EEPROM.put(address, day);
  address += sizeof(day);

  EEPROM.put(address, month);
  address += sizeof(month);

  EEPROM.put(address, year);
  address += sizeof(year);

  EEPROM.commit();
}

void printData() {
  float temp;
  float lon;
  float lat;
  float altitude;
  float speed;
  int hour;
  int day;
  int month;
  int year;

  int address = 0; // Start address

  EEPROM.get(address, temp);
  address += sizeof(temp);

  EEPROM.get(address, lon);
  address += sizeof(lon);

  EEPROM.get(address, lat);
  address += sizeof(lat);

  EEPROM.get(address, altitude);
  address += sizeof(altitude);

  EEPROM.get(address, speed);
  address += sizeof(speed);

  EEPROM.get(address, hour);
  address += sizeof(hour);

  EEPROM.get(address, day);
  address += sizeof(day);

  EEPROM.get(address, month);
  address += sizeof(month);

  EEPROM.get(address, year);
  address += sizeof(year);

  Serial.print("Temperature: ");
  Serial.print(temp);
  Serial.print(" °C, Longitude: ");
  Serial.print(lon);
  Serial.print(", Latitude: ");
  Serial.print(lat);
  Serial.print(", Altitude: ");
  Serial.print(altitude);
  Serial.print(" meters, Speed: ");
  Serial.print(speed);
  Serial.print(" km/h, Time: ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(gps.time.minute());
  Serial.print(":");
  Serial.print(gps.time.second());
  Serial.print(", Date: ");
  Serial.print(day);
  Serial.print("/");
  Serial.print(month);
  Serial.print("/");
  Serial.println(year);
}

can somebody please help me to understand why the code isnt working or help me fix it so that it can work. I am using the arduino ide to upload the code.

Check what controllers the OLED libray is made for.
I don't know the RP2040 at all.

Hi and welcome.

There are many oled displays. Should we take a guess?

Any compile errors?

You can add a FRAM module to the UNO. The ones I use have 32K bytes, interface via I2C and are only a few dollars.

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