OLED Display - TTGO LORA32

Hi Everyone,

I’ve just purchased some ESP32 based boards with an intergarted OLED display.
I’ve been able to load WLED onto them but no luck getting the OLED display to work with the OLED Usermod. I’ve set the correct pins in use (SDA:4 SCL15) but still no display.

Would anyone be able to help with this? all the code had been compiled in Arduino IDE and uploads OK.

Many Thanks!

Here’s some info on the board if it helps:

Correct pins for your project is 21 and 22

1 Like

I’ve had issues with the i2c OLED displays where the base address was misconfigured. Are you using 0x3c from the following example in your usermod.cpp?

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32

You beat me to it, I found this article useful. Pinout Instructable

But in instruction to board they stating SDA-4 SCL-15 and don’t forget RST-16! Very important because I have board with build in OLED and without reset it’s not working

1 Like

#include <Arduino.h>
#include “wled.h”
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/

uint8_t SCL_PIN = 15;
uint8_t SDA_PIN = 4;
uint8_t RST_PIN = 16;

#define U8X8_PIN_SCL SCL_PIN
#define U8X8_PIN_SDA SDA_PIN
#define U8X8_PIN_RESET RST_PIN

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_RESET, U8X8_PIN_SCL, U8X8_PIN_SDA); // Pins are Reset, SCL, SDA

// gets called once at boot. Do all initialization that doesn’t depend on
// network here
void userSetup() {
u8x8.begin();
u8x8.setPowerSave(0);
u8x8.setContrast(10); //Contrast setup will help to preserve OLED lifetime. In case OLED need to be brighter increase number up to 255
u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8.drawString(0, 0, “Loading…”);
}

// gets called every time WiFi is (re-)connected. Initialize own network
// interfaces here
void userConnected() {}

// needRedraw marks if redraw is required to prevent often redrawing.
bool needRedraw = true;

// Next variables hold the previous known values to determine if redraw is
// required.
String knownSsid = “”;
IPAddress knownIp;
uint8_t knownBrightness = 0;
uint8_t knownMode = 0;
uint8_t knownPalette = 0;

long lastUpdate = 0;
long lastRedraw = 0;
bool displayTurnedOff = false;
// How often we are redrawing screen
#define USER_LOOP_REFRESH_RATE_MS 5000

void userLoop() {

// Check if we time interval for redrawing passes.
if (millis() - lastUpdate < USER_LOOP_REFRESH_RATE_MS) {
return;
}
lastUpdate = millis();

// Turn off display after 3 minutes with no change.
if(!displayTurnedOff && millis() - lastRedraw > 3601000) {
u8x8.setPowerSave(1);
displayTurnedOff = true;
}

// Check if values which are shown on display changed from the last time.
if (((apActive) ? String(apSSID) : WiFi.SSID()) != knownSsid) {
needRedraw = true;
} else if (knownIp != (apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP())) {
needRedraw = true;
} else if (knownBrightness != bri) {
needRedraw = true;
} else if (knownMode != strip.getMode()) {
needRedraw = true;
} else if (knownPalette != strip.getSegment(0).palette) {
needRedraw = true;
}

if (!needRedraw) {
return;
}
needRedraw = false;

if (displayTurnedOff)
{
u8x8.setPowerSave(0);
displayTurnedOff = false;
}
lastRedraw = millis();

// Update last known values.
#if defined(ESP8266)
knownSsid = apActive ? WiFi.softAPSSID() : WiFi.SSID();
#else
knownSsid = WiFi.SSID();
#endif
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
knownBrightness = bri;
knownMode = strip.getMode();
knownPalette = strip.getSegment(0).palette;

u8x8.clear();
u8x8.setFont(u8x8_font_chroma48medium8_r);

// First row with Wifi name
u8x8.setCursor(1, 0);
u8x8.print(knownSsid.substring(0, u8x8.getCols() > 1 ? u8x8.getCols() - 2 : 0));
// Print ~ char to indicate that SSID is longer, than owr dicplay
if (knownSsid.length() > u8x8.getCols())
u8x8.print("~");

// Second row with IP or Psssword
u8x8.setCursor(1, 1);
// Print password in AP mode and if led is OFF.
if (apActive && bri == 0)
u8x8.print(apPass);
else
u8x8.print(knownIp);

// Third row with mode name
u8x8.setCursor(2, 2);
uint8_t qComma = 0;
bool insideQuotes = false;
uint8_t printedChars = 0;
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case ‘"’:
insideQuotes = !insideQuotes;
break;
case ‘[’:
case ‘]’:
break;
case ‘,’:
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
// Fourth row with palette name
u8x8.setCursor(2, 3);
qComma = 0;
insideQuotes = false;
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case ‘"’:
insideQuotes = !insideQuotes;
break;
case ‘[’:
case ‘]’:
break;
case ‘,’:
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}

u8x8.setFont(u8x8_font_open_iconic_embedded_1x1);
u8x8.drawGlyph(0, 0, 80); // wifi icon
u8x8.drawGlyph(0, 1, 68); // home icon
u8x8.setFont(u8x8_font_open_iconic_weather_2x2);
u8x8.drawGlyph(0, 2, 66 + (bri > 0 ? 3 : 0)); // sun/moon icon
}

1 Like

@Henry This code should work if not try to replace with this:

U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(U8X8_PIN_RESET, U8X8_PIN_SCL, U8X8_PIN_SDA);

@srg74 Thank you so much for your help with this!
I’ve just downloaded your new code and saved it as wled06_usermod.ino and put it in my wled00 folder (removing usermod.cpp) but I’m now getting a compile error:

Arduino: 1.8.12 (Windows 10), Board: “TTGO LoRa32-OLED V1, 80MHz, 921600, None”

wled06_usermod:2:10: error: #include expects “FILENAME” or

  • #include “wled.h”*

Thanks @lanman1 I think they’ve used different pins on this board:

Please download latest version of WLED! Since v0.10 code have been refactored and not using ino extension. Plus you will have a lot more cleaner code and more effects, thanks to @Aircoookie :slight_smile:
One more thing - project overgrowth Arduino IDE and now preferably to use Platformio IDE which is much more powerful.

Thanks @srg74 I’m using the latest build but I was still using the old .ino file because that was whats in the usermod github repo for the OLED mod.

I’ve just got the Platformio IDE running on my laptop as recomended but I can’t see how to add in my board as it isn’t a standard one?

Also where would I paste in the code you provided? I guess it would be under usermod.cpp but I wasn’t sure if the entire file neeeded replacing with your code or putting under one of the loops?

Really greatful for your help with this thank you :smiley:

Your board would be a generic ESP32dev. First try to compile WLED which is working with your board without OLED functionality. If this part is working then just replace code to file usermode.cpp with code I posted. And compile code again. Hopefully everything will work.

Hi @srg74 I’ve been able to upload the stadard code to my ESP32 and it worked with no errors.
When I replaced the usermod with the code you provided I now get the error messages in the image.
I think its something to do with it not loading in a library?
Thanks again!

Uncomment in platformio.ini

#For use SSD1306 OLED display uncomment following
#U8g2@~2.27.2

@srg74 I’ve just done a search in the platformio.ini file within WLED and I can’t see any mention of that text. Is it something I need to type in manually?

Thanks!

Line #169
And when you copy and paste change quote marks in #include “wled.h” . Somehow this forum replaced with wrong one

Sorry @srg74 I dont 100% get what you mean. I’ve gone into the usermod file and used the correct "
what do I need to do on line 169 of the Platformio.ini file?
I’ve attace some screenshots to hopefully help.


This is master repository. Look at line 169 and uncomment.

@srg74 strange how my original download of the repository didn’t have the same file.
I’ve now downloaded the one you linked and overwritten the old platformio file and uncommented the item on line 169.
As a test I ran the Build task for my board which the defaul usermod.cpp file whic then gave me the error:

***** [.pio\build\esp32dev\lib730\U8g2_ID942\U8x8lib.cpp.o] Error 1**


Also when copying and pasting the code you provided it seems to be changing the formatting of the commas " " which is breaking the code.