Hey guys! I have a quick question for you. I've been on the Google machine for a while now trying to find a solution, but alas, I can't seem to come up with one.
My project uses a Wemos D1 Mini to get the contents of a text file and display it on an OLED display. It also prints out the text to the serial monitor. When it prints to serial, the whole message is displayed as expected, but I can not for the life of me get the entire thing on the OLED. It's probably beyond my knowledge right now, so I'd like to borrow some of yours.
Below is the current code that I have.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "ESP8266WiFi.h"
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
ESP8266WiFiMulti WiFiMulti;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.println();
for (uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] WAIT %d...\n", t);
Serial.flush();
delay(1000);
}
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("Winternet", "password");
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Hello world!");
display.display();
}
void loop() {
if ((WiFiMulti.run() == WL_CONNECTED)) {
WiFiClient client;
HTTPClient http;
Serial.print("[HTTP] begin...\n");
if (http.begin(client, "http://callmecarlos.com/carlos.txt")) { // HTTP
Serial.print("[HTTP] GET...\n");
int httpCode = http.GET();
if (httpCode > 0) {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
display.setTextWrap(false);
display.startscrollleft(0x00, 0x07);
const char* printout = payload.c_str();
display.clearDisplay();
display.setCursor(0,0);
display.println(printout);
display.display();
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
} else {
Serial.printf("[HTTP} Unable to connect\n");
}
}
delay(10000);
}
I've also tried to do the below section with just a normal variable.
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
display.clearDisplay();
display.setCursor(0,0);
display.println(payload);
display.display();
So, can you please point me in the right direction? Thank you so much for your time.