So I go this great little module (
https://amzn.to/2SPSKtX), which is based on the ESP8266 chip, which is widely used for adding WiFi to Arduino projects, but then I noticed that it is a micro controller all unto itself, and so I thought, why not simplify, and just use this chip, eliminating the Arduino?

And so there I was, having pretty good luck, but displaying anything on the little screen was a nightmare! The typical Hello World examples would only display text for a minute or so, and then it would go blank.

So here, for future reference, is the basic code that I came up with to produce a simple, small, constant out put to the oled:

include <U8g2lib.h>
//U8g2 Contructor
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=/ 16, / clock=/ 5, / data=/ 4); // Alternative board version. Uncomment if above doesn't work. // U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, / reset=/ 4, / clock=/ 14, / data=*/ 2);
int y = 0;
void setup(void) {
u8g2.begin();
u8g2.setFont(u8g2_font_t0_11_tf); // set the target font to calculate the pixel width
u8g2.setFontMode(0); // enable transparent mode, which is faster
}
void loop(void) {
u8g2.firstPage();
do {
printOut(0, "output1 output1 " + (String)y);
printOut(1, "output2 " + (String)y);
printOut(2, "output3 " + (String)y);
//printOut(3, "output4 " + (String)y);
} while ( u8g2.nextPage() );
y++;
delay(1000);
}
u8g2_uint_t x = 0;
void printOut(int line, String msg) {
char mytext[msg.length() + 1];
msg.toCharArray(mytext, msg.length()+1);
u8g2_uint_t width = u8g2.getUTF8Width(mytext); // calculate the pixel width of the text
u8g2.setFont(u8g2_font_t0_11_tf); // set the target font
x = (line * 8) + 8;
u8g2.drawUTF8(0, x, mytext); // draw the text
}

You can see I’ve broken out the actual function to write to the oled so that we don’t have that messy bit of code in the middle of the loop. I’d like to get rid of some of the other bits of code as well, but for now, that is working base code!

%d bloggers like this: