Hi, I've been trying to use an OLED display with a Fingerprint sensor, both of them are working well individually, but when I try to work with them in the same code, It is impossible to detect the OLED. What am I doing wrong? Also, It shows that the oled is working correctly If i just run the "tryoled" even if it is not connected
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
SoftwareSerial sensorSerial(2, 3); // RX, TX
Adafruit_Fingerprint finger(&sensorSerial);
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
sensorSerial.begin(57600); // Start communication with the fingerprint sensor
delay(100); // Small delay before initializing the OLED
tryoled(); // Initialize the OLED display
delay(200); // Small delay after OLED before initializing the fingerprint sensor
tryfinger(); // Initialize the fingerprint sensor
}
void loop() {
// You can add more logic here if needed
}
void tryfinger() {
if (finger.verifyPassword()) {
Serial.println("Fingerprint sensor detected!");
} else {
Serial.println("Error: Fingerprint sensor not detected");
}
}
void tryoled() {
Serial.println("Searching for OLED...");
// Try to initialize the OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS)) {
Serial.println("❌ OLED NOT detected.");
// Do not stop the program, simply exit the function
return;
}
Serial.println("✅ OLED detected successfully.");
// Display message on the OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("OLED OK!");
display.display();
}