Notifications
Clear all

[Solved] OLED Displays

8 Posts
5 Users
1 Likes
1,273 Views
bwchester
(@bwchester)
Active Member
Joined: 3 years ago
Posts: 11
Topic starter  

Hello Folks,

Sorry if this exists elsewhere but I did a search for OLED and didn't find anything relevant.

I have a 1.3 inch I2C OLED display that looks like a display used in the OLED article but running the examples provided in the article https://dronebotworkshop.com/oled-arduino/ do not work nor do the Adafruit ssd1306 examples.  I have modified the examples to use my 128 x 64 screen size and correct i2c address.  In all examples, I get a very narrow area running the width of the screen by maybe 8 pixels high, where something seems to be happening and the rest of the screen is mainly black with scattered white dots.

I have managed to get this display to work very well with several ESP32 boards using the <oled.h> library (which does not compile for the NANO) so I know the display is good.  What I want to do now is to use the display with an Arduino Nano project I am working on but no joy.

Is there perhaps, something in the  Adafruit_SSD1306.cpp file I need to change as apposed to just the header file?  I have looked at the .cpp file but honestly can't make heads or tails of it.

I should also mention that I've tried the display with 3 different Nanos and an UNO to eliminate the controller but no joy on any of them.  I have a smaller .9 inch OLED display which works but is only 32 lines (pixels?) as apposed to the 64 on this display.

I am a noob and have likely overlooked something but just can't rap my seniors head around it.

Thanks in advance for any suggestions.

Brian


   
Quote
Topic Tags
bwchester
(@bwchester)
Active Member
Joined: 3 years ago
Posts: 11
Topic starter  

Hello again,

Well, after many days of pulling out my hair I managed to discover a different library to use with my 1.3 inch display and the Nano.  I have downloaded U8G2 which so far allows me to display 6 rows and 21 columns of text at the libraries default settings.  One interesting problem with this library is text has to start not at the 1st pixel position (0,10) but at the 3rd pixel (2,10) as seen here:

u8g2.drawStr(2,10,"Hello World!");

Using 0 (zero) or 1 leaves the first two columns of pixels off of the H.  Also running down the entire right side of the screen is a two pixel wide column of solid white with some black pixels intermixed.  Bought a second display through amazon.ca and get the same results.

At least I am having some sort of success.  

Has anyone else had trouble with these 1.3" OLED displays?

Thanks for reading this,

Brian


   
ReplyQuote
bwchester
(@bwchester)
Active Member
Joined: 3 years ago
Posts: 11
Topic starter  

I can't believe my luck.  Took another look at the U8G2 library and discovered the following line:

U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);

My little 1.3" OLED display is now fully functional!  It now used the entire screen size of 128x64 and is extremely fast compared to the line (constructor??) of:

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);

Hope this will help anyone else who chooses to use this type of display.

Brian ? 


   
RonRus reacted
ReplyQuote
OldCodger
(@oldcodger)
Eminent Member
Joined: 2 years ago
Posts: 23
 

I have just joined the group and saw this post.  I was going to suggest U8G2.

 

I bought a 1.2 inch OLED from Pimoroni and it got that running brilliantly.


   
ReplyQuote
OldITGuy
(@olditguy)
New Member
Joined: 3 years ago
Posts: 1
 

I am very new to Arduino and was having difficulty with my 128x64 display. I too discovered the U8G2 library, which I find very easy to understand and use. However, I was not paying attention to one aspect of the constructor:  U8G2_SH1106_128X64_NONAME_#_HW_I2C u8g2(U8G2_R0)

Where the "#" is sets the buffer size and I could not get the display to show the entire buffer. I learned I needed to set that to "F"" in order to have the entire screen cover by the buffer in memory. "F"= full, as opposed to "1" or "2" which caused problems for me. I get a "Low memory available" warning on the Nano for my project, but that's OK. The XIAO has plenty of memory.


   
ReplyQuote
Jonel34
(@jonel34)
Active Member
Joined: 9 months ago
Posts: 5
 

Hello folks, 

I am quite new to Arduino and was having a little challenge with a 124 x 64 OLED screen I bought. 

I realized it does not work with the Adafruit SSD1306 library but with the Adafruit sh110X library instead.

My current issue is that I am trying to reading data from a DHT22 using an Uno R3 but all I get is the text without the actual temperature and humidity readings; which looks like this

Temperature: nan C 

Humidity: nan %

I think it may have to do with the sketch I wrote, however I can't seem to pin point the exact mistake.

Hence I am attaching my code and a picture of the current display. 

Any help that can be given is greatly appreciated. 

Thank you. 

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Adafruit_Sensor.h>
#include "DHT.h"

#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET -1
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define DHTPIN 2 // Digital pin connected to the DHT sensor

// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Wire.begin();
display.begin(i2c_Address, true);
dht.begin();
delay(2000);
display.clearDisplay();
display.setTextColor(SH110X_WHITE);
}

void loop() {
delay(2000);

//read temperature and humidity
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
}

//clear display
display.clearDisplay();

// display temperature
display.setTextSize(1);
display.setCursor(0,0);
display.print("Temperature: ");
display.setTextSize(2);
display.setCursor(0,10);
display.print(t);
display.print(" ");
display.setTextSize(2);
display.print("C");

// display humidity
display.setTextSize(1);
display.setCursor(0, 35);
display.print("Humidity: ");
display.setTextSize(2);
display.setCursor(0, 45);
display.print(h);
display.print(" %");

display.display();
}
IMG 20220816 163645 HDR

   
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3403
 

@jonel34 Add a Serial.println of h and t to make sure they have valid readings and I see a 128 x 64 instead of 124 x 64, does that make a diff?

"Don't tell people how to do things. Tell them what to do and let them surprise you with their results.” - G.S. Patton, Gen. USA
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon


   
ReplyQuote
Jonel34
(@jonel34)
Active Member
Joined: 9 months ago
Posts: 5
 

@zander 

Thank you very much Ron. Your suggestions were just spot on. Problem resolved. 

Thank you so much. 

PXL 20220817 154114545

Below is how the code looks now. 

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Adafruit_Sensor.h>
#include "DHT.h"

#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's

#define SCREEN_WIDTH 124 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET -1
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define DHTPIN 2 // Digital pin connected to the DHT sensor

// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Wire.begin();
display.begin(i2c_Address, true);
dht.begin();
delay(2000);
display.clearDisplay();
display.setTextColor(SH110X_WHITE);
}

void loop() {
delay(2000);

//read temperature and humidity
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
}

//clear display
display.clearDisplay();

// display temperature
display.setTextSize(1);
display.setCursor(0,0);
display.print("Temperature: ");
display.setTextSize(2);
display.setCursor(0,10);
display.print(t);
display.print(" ");
display.setTextSize(2);
display.println("C");

// display humidity
display.setTextSize(1);
display.setCursor(0, 35);
display.print("Humidity: ");
display.setTextSize(2);
display.setCursor(0, 45);
display.print(h);
display.println(" %");

display.display();
}
This post was modified 3 months ago by Jonel34

   
ReplyQuote