0

I'm a 13 years old boy and I am doing a project with esp01 and an OLED screen to display project ideas on the OLED with the ChatGPT API. The answer is displayed on the OLED but I would like it to scroll from bottom to top and so on to the next query so I can see the whole answer.I noted that the only library that worked for me for the esp01 was the SSD1306Wire library .My code is :

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <Wire.h>
#include <SSD1306Wire.h>
#include <ArduinoJson.h> 

const char* ssid = "WIFI_NAME";
const char* password = "WIFI_PASSWORD";

const char* apiEndpoint = "https://api.openai.com/v1/engines/text-davinci-002/completions";
const char* apiToken = "OPENAI_TOKEN";

SSD1306Wire  display(0x3c, 2, 0);  
void setup() {
 Serial.begin(115200);
 
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
   delay(1000);
   Serial.println("Connecting to WiFi...");
 }

 Serial.println("Connected to WiFi");

 display.init();
 display.flipScreenVertically();
 display.setFont(ArialMT_Plain_10);
}

void loop() {
 WiFiClientSecure client;
 client.setInsecure();
 HTTPClient http;
 http.begin(client, apiEndpoint);
 http.addHeader("Content-Type", "application/json");
 http.addHeader("Authorization", "Bearer " + String(apiToken));
 String payload = "{\"prompt\": \"TEXT_TO_QUERY\",\"temperature\":0.8,\"max_tokens\":40}";
 int httpResponseCode = http.POST(payload);
 String response = "";

 if (httpResponseCode == 200) {
   response = http.getString();
   int startIndex = response.indexOf("text\":") + 7;
   int endIndex = response.indexOf("\",\"index\"");
   response = response.substring(startIndex, endIndex);
   response.replace("\\n", "\n");
   Serial.println(response);
 } else {
   Serial.print("Error: ");
   Serial.println(httpResponseCode);
 }

 http.end();


 display.clear();
 display.drawStringMaxWidth(0, 0, 128, response);
 display.display();

 delay(18000000);  
}

Could anyone help me?

9
  • have you looked at the example sketches?
    – jsotola
    Commented Apr 2, 2023 at 23:06
  • The 5 hour pause is supposed to be 30 minutes, my mistake. The library doesn't seem to have example sketches. Commented Apr 2, 2023 at 23:48
  • then do an internet search for SSD1306Wire.h
    – jsotola
    Commented Apr 3, 2023 at 0:47
  • But my problem is that the library does not support the scroll function Commented Apr 3, 2023 at 11:08
  • 1
    I would like the texte to scroll smoothly From the bottom to the top Commented Apr 3, 2023 at 20:20

1 Answer 1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.