[Solved] Two different displays, TFT & OLED, OLED does not work

I have a project I have been working on involving using two different displays for my Mega 2560, but I cannot seem to get the OLED screen to activate with the touch screen in the same code, and I suspect it is the reset code interfering with each other.

#include <Elegoo_GFX.h>
#include <Elegoo_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0

#define LCD_RESET A4
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

My OLED screen operates on I2C (SDA & SCL), and is successful when I use a code strictly for it:

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

The Elegoo touchscreen is a 2.8 inch, and the reset pin on it is designated for Analog 4. I have tried changing the pin assignment for the OLED to something unused, but to no avail. The best I have gotten is a few random pixels to light up for a moment on startup.

What parameters can I change that would allow both to work? Thanks for any help.

I should have included that the void setup() includes:

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

Most I2C OLEDs have only got 4 pins.
Adafruit code wiggles a “RESET” pin e.g. 4

If you really have an accessible Reset pin on your OLED, connect it to a different pin i.e. not one that is used by the TFT. If you have the Reset pin, use it.

A regular 4-pin OLED should not mind the OLED_RESET in the constructor. Wiggling a non-existent pin does no harm. The 4-pin displays rely on “power-on” reset.

David.

david_prentice:
Most I2C OLEDs have only got 4 pins.
Adafruit code wiggles a "RESET" pin e.g. 4

If you really have an accessible Reset pin on your OLED, connect it to a different pin i.e. not one that is used by the TFT. If you have the Reset pin, use it.

A regular 4-pin OLED should not mind the OLED_RESET in the constructor. Wiggling a non-existent pin does no harm. The 4-pin displays rely on "power-on" reset.

David.

The OLED has no reset pin. It's just Ground, VCC, SDA, and SCL. I found an article instructing to set the pin to "-1" for this case. I changed it, but with no results.

I had assumed that you have a 4-pin OLED.

The "Elegoo" is just a Blue Mcufriend style Uno Shield. It uses digital# 2-9 and Analog# A0-A4
I2C on a Mega is on digital# 20,21

So the two displays use different pins on a Mega. They should work fine on a Mega. (it will not work on a Uno because the Uno has I2C on A4,A5)

Please post your full sketch. Attach it if it is too big to paste.

Elegoo TFTLCD library is just a hacked version of Adafruit_TFTLCD.
I don't know about Elegoo_GFX. I suspect it is a hacked Adafruit_GFX. You definitely do not need both hacked and genuine Adafruit_GFX.

Companies like Elegoo might be good for hardware. They might provide better documents. But I would be very wary of their hacked software libraries.

David.

I agree that it would likely be best to get the Elegoo libraries out of the picture, but am unsure how. The .h files just have the name changed from Adafruit to Elegoo, but the .cpp file has many more lines. I tried plugging in the Adafruit TFT library instead of Elegoo, but the screen is blank. I’ll have to explore another method.

I’ve attached my sketch. The “shift_test_complex” works for just the OLED display, while “dash_02” is what I’m trying to get working. This is for a Arduino dashboard I’m making for a school car project. My goal if to have the TFT display data, while the OLED shows the gear number. I intend to wire it into the Can-Bus of the vehicle for data acquisition, but that will be handled later.

Thank you again.

[EDIT]
I was able to replace the Elegoo libraries with modified Adafruit TFT libraries. The TFT display functions normally, but the OLED is still non-responsive.

shift_test_complex.ino (1.86 KB)

dash_02.ino (8.49 KB)

Your code "looks" ok. What happens with the OLED ?
Does it show the Adafruit "Splash screen" ?

Does your Serial display show the Gear number changing?
Does it show the LastShiftState correctly?

Note that nothing gets printed on the OLED unless Gear != LastShiftState or NeutralState != LastNeutralState
If your logic never gets there, nothing is shown.

David.

I have implemented a few lines of code in the "void setup()" to make the OLED screen fill on startup

  display.clearDisplay();
  display.fillRect(0, 0, 128, 32, WHITE);
  display.display();

This has been successful in that the entire screen lights up during startup. Unfortunately it goes blank once the rest of the loop initializes.

I have added "Serial.println" codes for the Gear and LastShiftState at the beginning of the loop. On the first cycle, it shows 1 & 0 respectively, then 1 & 1 on each cycle after. The Gear value does change when I input its button, and LastShiftState changes with it afterwards. This should meet the conditions to change the OLED output.

I then removed the conditional statements in the loop, and made it display Gear constantly, but the OLED will not display to any code inside the loop.

I have found what the problem is! :grin:

In my color definition, I had used simple names instead of more specific ones. For the OLED "WHITE" is to simply activate pixels, but it was confusing it with the WHITE for my TFT display.

I changed the definition to WHITE_TFT, and replaced the term throughout the code relating to the TFT display, and everything is functioning perfectly now.

Thanks again!