Display is not showing anything

I am using this display
Screenshot_20240121_094202
with this i2c expander


in esp-wroom-32. I used this code:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <PS2Keyboard.h>
#include <WiFi.h>
#include <HTTPClient.h>


#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET -1  // Reset pin not used
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

const int PS2_DATA_PIN = 19;  // Pin connected to the data line of the PS2 keyboard
const int PS2_IRQ_PIN = 18;   // Pin connected to the IRQ line of the PS2 keyboard

PS2Keyboard keyboard;

String ssid = "";
String password = "";

void setup() {

  Serial.begin(115200);

  // Connect to Wi-Fi
  connectToWiFi();

  Wire.begin(SDA, SCL);  // Initialize I2C with the specified pins

  if (!display.begin()) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;
  }

  display.display();  // Clear the display
  delay(2000);        // Pause for 2 seconds
  display.clearDisplay();


}

void connectToWiFi() {
  pinMode (33, HIGH);
  Serial.println("Enter Wi-Fi SSID:");
  while (ssid.length() == 0) {
    while (keyboard.available()) {
      char c = keyboard.read();
      if (c == PS2_ENTER) {
        Serial.println(ssid);
        break;
      } else {
        ssid += c;
      }
    }
  }


  Serial.println("Enter Wi-Fi password:");
  while (password.length() == 0) {
    while (keyboard.available()) {
      char c = keyboard.read();
      if (c == PS2_ENTER) {
        Serial.println(password);
        break;
      } else {
        password += c;
      }
    }
  }


  Serial.println("Connecting to Wi-Fi...");
  WiFi.begin(ssid.c_str(), password.c_str());
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
 


  // Display a welcome message
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10, 10);
  display.println("Welcome to LearnMateAI...!");
  display.display();
  delay(3000);  // Display the welcome message for 3 seconds
  display.clearDisplay();
}

String getChatGPTResponse(String userQuery) {
  HTTPClient http;

  String apiUrl = "https://api.openai.com/v1/chat/completions";  // Update with the correct endpoint
  String apiKey = "YOUR_OPENAI_API_KEY";  // Replace with your OpenAI API key

  http.begin(apiUrl);
  http.addHeader("Content-Type", "application/json");
  http.addHeader("Authorization", "Bearer " + apiKey);

  String requestBody = "{\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},{\"role\": \"user\", \"content\": \"" + userQuery + "\"}]}";

  int httpResponseCode = http.POST(requestBody);
  String response = http.getString();

  http.end();

  return response;
}

void loop() {

  while (keyboard.available()) {
    char c = keyboard.read();
    if (c == PS2_ENTER) {
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("You asked:");
      display.println();
      display.print("-> ");
      display.print(keyboard.read());




      // Get response from ChatGPT
      String userQuery = "";
      while (keyboard.available()) {
        userQuery += keyboard.read();
      }

  
      String chatGPTResponse = getChatGPTResponse(userQuery);

      display.println();
      display.println();
      display.println("LearnMateAI says:");  // Change this line
      display.println("-> " + chatGPTResponse);



      display.display();
    }
  }
}
 

but my display is not showing anything.
Please help.

Your code references the Adafruit SSD1306 library. Your display does not appear to be an SSD1306 type display. The SSD1306 is usually found in OLED displays, and at first glance your display appears to be an LCD type display. It resembles an ST7920 type I have in front of me at the moment, but the connector labels don't entirely match up.

1 Like

Are you kidding? No, I can't give you code and a circuit diagram. I've just told you that you probably don't have the display you think you have. I have no idea what kind of display it is that you have. It resembles a display I have here, but it's definitely not the same. It could have any kind of controller on it.

Seems to be a habit.

@oliur - Your IDE and various libraries has been causing you to not complete your projects. Un-install all your Arduino IDE versions, along with the left over libraries folders... then re-install the newest IDE.

2 Likes

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