• Worldwide Shipping

  • 24/7 Customer Support

  • FAQ
  • Worldwide Shipping

  • 24/7 Customer Support

  • FAQ

HUM: OLED 128x64

You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect the module with Croduino and the basic code. Everything else is left to your imagination.

INTRODUCTION

In this tutorial, we will get acquainted with a very small, but an interesting module that finds its application in all the projects where it is necessary to show some data from the sensor. It is about an OLED 0.96“ display, whose size makes it easily applicable in every project because it does not take up too much space and it provides an excellent contrast due to the different work principle than that of the LCD display.


Module characteristics:
• Operating voltage: 3.3V or 5 V
• Consumption: 30 mA (depends on the number of turned on pixels)
• Communication: I2C or SPI
• Pixel color: White
• Display size: 0.96“

HOW DOES IT WORK?

The display consists of 128 * 64 individual pixels that are controlled by the SSD1306 controller that turns each pixel on or off, depending on how we set it. As we have the pixels that turn on or off, they provide lighting and the display does not require backlighting like the LCD display, so the consumption of the OLED display is much lower than that of the LCD. For the same reason, the contrast is much better and you can clearly read even smaller characters from the display, despite the display's small dimensions. The SSD1306 controller can receive data in 2 ways: via SPI or I2C communication, depending on how we choose. On the back of the display, it is indicated which pins we need to connect briefly in order to have SPI or I2C communication. For the controller's power supply, we use a 3.3V voltage and that is why a voltage regulator is implemented on the board. The controller can also generate the voltage it uses for power supply (7-9V) to the voltage necessary for power supplying the display itself, i.e. pixels. Since our module is calibrated to a 5-3.3V power supply, we have to make the controller produce a higher voltage for the display to work, in the program.

HOW TO CONNECT IT?

The module is connected easily because it uses I2C or SPI communication. If we use I2C communication, to the A4 pin we connect the SDA (D1) module pin, and to the pin A5 on the  Croduino, we connect the SCL (D0) module pin. If we use SPI communication, we need 5 communication conductors, and below, it is written which Croduino pin is connected to which pin on the display. As indicated in the characteristics, the module can operate at 5 V or 3.3 V, so it does not matter which voltage we deliver to it, because it has a built-in voltage converter.

SPI komunikacija
Display >>>>>>>>>>>> Croduino
GND >>>>>>>>>>>> GND
VCC >>>>>>>>>>>> 5 V or 3.3 V
D0 >>>>>>>>>>>> D10
D1 >>>>>>>>>>>> D9
RES >>>>>>>>>>>> D13
DC >>>>>>>>>>>>D11
CS >>>>>>>>>>>> D12

ARDUINO CODE

To use the OLED display with Croduino, you need to install the Adafruit_SSD1306 library for work with an OLED display that contains all of the functions we use in the examples. If you do not know how to install the library, check the tutorial in which everything is explained in detail.
In the first example, we will use SPI communication and display the characters sent from the Serial Monitor on the display.

#include <SPI.h> //including the SPI library that allows SPI communication
#include <Adafruit_SSD1306.h> //including the library for work with an OLED display
#define SCREEN_WIDTH 128 //defining the display width, in pixels
#define SCREEN_HEIGHT 64 //defining the display height, in pixels
//declaring the pins to which we connect the oled display for SPI communication (standard Croduino pins for SPI communication)
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
//Our OLED display library constructor, in order to have access to the functions that control the display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
//the string to which we save data from the Serial monitor and then we display it
String buf;
void setup() {
Serial.begin(9600);//starting serial communication(9600 baud)
//Initialization of the OLED display library
// SSD1306_SWITCHCAPVCC = generates the display voltage(7-9 V) from 3.3V voltage that it has from the voltage regulator
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { //0x3C address for the 128x64 display
//if the initialization was not successful, on the Serial monitoru we receive an error message
Serial.println(F("SSD1306 allocation failed"));
for(;;); //infinite loop if the initialization was not successful, for the program to stop the execution
}
}
void loop() {
//checking if there is data on the Serial communication, and if there is, we proceed with the execution of the code
if(Serial.available()){
buf=Serial.readString();//the data we receive from the serial communication is saved to buf variable
//Displaying what we have received on the Serial monitor
Serial.println("This is received");
Serial.println(buf);
display.clearDisplay(); //clear the display
display.setTextSize(1); //set the text size to 1
display.setTextColor(WHITE); //set the text color
display.setCursor(0,0); //set the cursor to the beginning of the first row
display.println(buf); //send the received string to the display
display.display(); //on the display, we print everything we have sent
}
}

The second example uses I2C communication and in it, we will read the temperature from the DHT sensor and display it.

*
#include <Wire.h> //including the wire library that allows I2C communication
#include <Adafruit_SSD1306.h> //including the library for work with an OLED display
#include "DHT.h" //including the DHT air temperature and humidity sensor library
#define SCREEN_WIDTH 128 //defining the display width, in pixels
#define SCREEN_HEIGHT 64 //defining the display height, in pixels
#define DHTPIN 10 // defining the pin to which the DHT sensor data pin is connected
#define DHTTYPE DHT11 //defining the type of DHT sensor(DHT11 or DHT22)
//Our OLED display library constructor, in order to have access to the functions that control the display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
//Konstruktor za DHT senzor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
dht.begin();////Initialization of the DHT sensor library
//Initialization of the OLED display library
// SSD1306_SWITCHCAPVCC = generates the display voltage(7-9 V) from 3.3V voltage that it has from the voltage regulator
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // 0x3C address for the 128x64 display
//if the initialization was not successful, on the Serial monitoru we receive an error message
Serial.println(F("SSD1306 allocation failed"));
for(;;); //infinite loop if the initialization was not successful, for the program to stop the execution
}
}
void loop() {
float temperatura=dht.readTemperature();// to the temperature (temperatura) variable we save the temperature from the DHT11 sensor
float vlaga=dht.readHumidity();// to the humidity (vlaga) variable, we save the humidity from the DHT11 sensor
display.clearDisplay();//function for deleting everything off the display
display.setTextSize(1);//function for setting the text size
display.setTextColor(WHITE);//function for setting the text color (our display can only have one color)
display.setCursor(0,0);//function for setting the cursor (0-127,0-63) to where we want to start printing the text on the display
display.print("Temp: ");//function for displaying the text we submit
display.print(temperatura);//displays the temperature
display.print(" *C");//displaying a space and *C to know that the temperature is measured in degrees Celsius
display.setCursor(0,10);// setting the cursor to the new row and displaying humidity data
display.print("Humidity: ");
display.print(vlaga);
display.println(" %");
display.display();//displaying the whole text that was previously sent to the display buffer
delay(1000);// 1 second pause, so the values do not change constantly
}
Leave a Reply