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?
1 Answer 1
- The SSD1306Wire code, its development history and discussions can be found here on github.com.
- The Google search pattern "scroll site:github.com/ThingPulse/esp8266-oled-ssd1306" can be used to find all matches to "scroll" on these web pages. There appears to be interest in vertical scrolling by others but no support as of yet. There also appears to be some horizontal scrolling support or success as discussed in this github.com issue for this project.
- Also in that thread, there is a link to another DSS1306 github.com project which explicitly states it supports horizontal scrolling.
answered Apr 5, 2023 at 12:27
SSD1306Wire.h