Why is this an adventure? Because in contrast to my usual approach of buying only well-supported
devices from reputable U.S. vendors, this project breaks that pattern. Why? Because I wanted
a small and inexpensive monochrome organic LED (OLED) display –
see HERE – to display real time data. I also use LCDs for this
job, but they are relatively large and power-hungry, which makes them much less desirable for use
in battery-powered projects.
Adafruit sells a 128x64 pixel 0.96" (diagonal) display, but it costs $20. You can draw graphics on this display (and others, too) using Adafruit's very nice GFX graphics library, but that's not necessary for this simple text-based project. What do do? There are lots of off-shore (invariably Chinese) sources for these small OLED displays. If that kind of sourcing doesn't bother you politically and you don't mind dealing with delivery issues, this is an option. (The order for displays I used for this project was so late on delivery that Amazon assumed it was lost and issued a credit refund to my account, even though the order was allegedly shipped from a U.S. location. A similar order from another Chinese supplier placed in March had still not arrived as of the end of July, so CAVEAT EMPTOR!) Here's a breadboard layout to test the display. I used a SparkFun RedBoard UNO compatible just because I had sitting on my desk. The display is an IZOKEE 0.96" I2C 12864 128x64 pixel OLED bought from KeeYees-US for $13 for three displays – a very sigificant price improvement over domestic equivalents! The displays already have breadboard-ready 4-pin headers soldered on and they come in a cute little plastic snap-lid case. Text displayed on this device is very bright and sharp white on a black background. Note that it's powered through the UNO's 3.3 V pin, but 5 V is also OK. Finally, frustrating experience has taught me that although these small OLEDs from various sources all LOOK the same, there are differences that must be accounted for in your code. |
// https://github.com/Seeed-Studio/Seeed_Learning_Space/tree/master/ // Grove%20-%20OLED%20Display%200.96''(SSD1315)V1.0 #include "U8g2lib.h" #include "Wire.h" U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); void setup(void) { u8g2.begin(); } void loop(void) { u8g2.clearBuffer(); //Reads right side up with pins on left. Otherwise... //u8g2.setFlipMode(1); //reads with pins on right. // clear the internal memory u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font u8g2.drawStr(10,10,"Hello World!"); // write to internal memory u8g2.sendBuffer(); // transfer to the display delay(1000); u8g2.clearDisplay(); delay(1000); }When I compile this code, this warning message appears:
/* U8g2_DHT22.ino,D. Brooks, August 2020 https://github.com/Seeed-Studio/Seeed_Learning_Space/tree/master/ Grove%20-%20OLED%20Display%200.96''(SSD1315)V1.0 See U8g2.ino for OLED use. */ #include "U8g2lib.h" #include "Wire.h" #include "DHT.h" #define DHTTYPE DHT22 #define DHTPIN 8 DHT dht(DHTPIN, DHTTYPE); U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); void setup(void) { u8g2.begin(); dht.begin(); } void loop(void) { u8g2.clearBuffer(); //Reads right side up with pins on left. Otherwise... //u8g2.setFlipMode(1); //reads with pins on right. // clear the internal memory delay(3000); u8g2.setFont(u8g2_font_ncenB08_tr); u8g2.drawStr(5,10,"T (C): "); u8g2.setCursor(70,10); u8g2.print(dht.readTemperature(),1); u8g2.drawStr(5,25,"RH (%): "); u8g2.setCursor(70,25); u8g2.print(dht.readHumidity(),0); u8g2.sendBuffer(); }Here's the breadboard layout. The display is actually sharper and easier to read than it appears in this image.
Code Update: The code examples given above work for the IZOKEE 0.96" OLED but not for the seemingly identical SeeedStudio device. Here's "Hello world" code that does work with the SeeedStudio 0.96" OLED on an UNO, as sent to me in response to a request to the SeeedStudio support team. The critical step is using the appropriate "constructor" statement – U8G2_SSD1306... |
/* U8g2_seeedstudio.ino, August 2020 Works with SeeedStudio 0.96" OLED. Code sent by SeeedStudio support team. */ #include "Arduino.h" #include "U8g2lib.h" #ifdef U8X8_HAVE_HW_SPI #include "SPI.h" #endif #ifdef U8X8_HAVE_HW_I2C #include "Wire.h" #endif U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); void setup(void) { u8g2.begin(); } void loop(void) { u8g2.clearBuffer(); // clear the internal memory u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font u8g2.drawStr(0,10,"Hello World!"); // write something to the internal memory u8g2.sendBuffer(); // transfer internal memory to the display delay(1000); }