ESP8266 driving 2 ST7789 240x240 IPS and one 0.49" OLED code source works but modified code fails

Good morning,

I am making a basic project:
An ESP8266MOD dev board driving 2 IPS screen and showing the same image on each and an OLED with a counter on it.
The system has 3 buttons, Two to increment/decrease the number and one to change the image.

All the images are loaded in the LittleFS of the ESP and converted to raw from jpeg using imageconverter565.

I used as my basis for this code:

From these very forums.

This code runs fine, absolutely no errors, images load just fine and roll no issue.

I also tested it by making my own images and changing the name both in the code and name of the file to make sure I wasn't messing up anything.

I manually added the example sketch for the OLED from the
ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays

Library downloaded directly form the Arduino IDE.

The clock demo runs fine on its own and my modified script just adding the clock allows the ESP to drive both screens and the clock with no issues.

I modified the script thus:


//====================================================================================
//                                  Definitions
//====================================================================================
// Comment out if image files have a header and reverse byte order, see notes above
#define UTFT_FORMAT

// Uncomment if using UTFT format with 80MHz SPI and visible image tearing occurs
//#define ADD_DELAY   // This decreases the pixel rate deliberately so the TFT can cope

//====================================================================================
//                                  Libraries
//====================================================================================
//Call up the SPIFFS FLASH filing system
#include <LittleFS.h>
#define SPIFFS LittleFS

#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"
#include "ssd1306.h"
#include "OLEDDisplayUi.h"
#include "images.h"

TFT_eSPI tft = TFT_eSPI();       // Invoke custom library

SSD1306Wire display(0x3c, SDA, SCL);
OLEDDisplayUi ui ( &display );

// Variables
int imageIndex = 0; // Index of the current image
int counter = 0;    // Counter value

// Define pins for buttons
const int button1Pin = 8;
const int button2Pin = 9;
const int button3Pin = 6;

//====================================================================================
//                                    Setup
//====================================================================================
void setup()
{
  Serial.begin(115200); // Used for messages

  tft.begin();
  tft.setRotation(0);  // 0 & 2 Portrait. 1 & 3 landscape
  tft.fillScreen(TFT_BLACK);
  
    // Initialize displays
  display.init();

  const char* Init = "Initiative";
  const char* Showing = "Line 3. Italic text";

  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.setFont(ArialMT_Plain_24);
  display.drawString(0, 8, String(Init));
  display.drawString(0, 8, String(Showing));

  // Initialize buttons
  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);
  pinMode(button3Pin, INPUT_PULLUP);

  if (!SPIFFS.begin()) {
    Serial.println("SPIFFS initialisation failed!");
    while (1) yield(); // Stay here twiddling thumbs waiting
  }
  Serial.println("\r\nInitialisation done.");

  listFiles(); // Lists the files so you can see what is in the SPIFFS
  drawRaw("/kitty.raw", 0, 0, 240, 240);
  delay(500);
}

void updateCounter() {

  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.setFont(ArialMT_Plain_24);
  display.drawString(0, 8, String(counter));
  Serial.println("Counter hit++");
}

void displayImage(int index) {
  String imagePath = "/image" + String(index) + ".raw";
  File imageFile = LittleFS.open(imagePath, "r");
  if (!imageFile) {
    Serial.println("Failed to open image file");
    drawErrorTriangle();
    return;
  }
  drawRaw(imagePath.c_str(), 0, 0, 240, 240);
  imageFile.close();
}

void drawErrorTriangle() {
  // Draw a small triangle in the center of the screen as an error indicator
  tft.fillTriangle(tft.width() / 2 - 10, tft.height() / 2 + 5,
                   tft.width() / 2, tft.height() / 2 - 10,
                   tft.width() / 2 + 10, tft.height() / 2 + 5,
                   TFT_RED); // Use TFT_RED or an appropriate color
}

//====================================================================================
//                                    Loop
//====================================================================================
void loop()
{
  // Check button presses
  if (digitalRead(button1Pin) == LOW) {
    // Switch to the next image
    Serial.println("Switch to the next image");
    imageIndex = (imageIndex + 1) % 4; // Assuming you have 4 images
  displayImage(imageIndex);
  }
  if (digitalRead(button2Pin) == LOW) {
    // Increment counter
    counter++;
    updateCounter();
    Serial.println("Init up");
  }
  if (digitalRead(button3Pin) == LOW) {
    // Decrement counter
    counter--;
    updateCounter();
    Serial.println("Init down");
  }
}

I made sure the files I upload using LittleFS load fine and work with my source script.

However when I upload this script i just get a black screen and random dots on the OLED.

I did use ChatGPT to do some additions like the failsafe and rewritting some of the code where it would not compile but whilst it compiles it doesn't give anything when it runs.

Thanks in advance.

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