Como programar um display OLED com Arduino

How to program an OLED display with Arduino

Sensors are used to convert a physical quantity, such as light intensity or temperature, into an electrical one. There are several types of sensors that can be easily used with an Arduino board, which is an advantage.

For example, any analog or digital sensor interacts easily with the Arduino, as the board offers analog and digital inputs. Analog sensors collect readings over a range of values ​​and digital sensors read whether a signal is active (high or low).

Potentiometer, joystick and temperature sensors are examples of analog sensors. The IR proximity, vibration and flame or smoke sensors are digital. All of these sensors can connect directly to the Arduino, displaying their values ​​on a serial monitor. Displays such as LCD or 7-segment LED can be used to present the value of a sensor.

OLED — or organic light-emitting diode — is another display option and serves as an alternative to LCD. Where an LCD is passive, the OLED is active (meaning it contains amplifiers). It's also small, bright, and extremely lightweight, so it's commonly used in handheld or pocket-sized devices.

OLED allows for many display options, including text, digits, shapes, and images. Here we will learn how to display the value of a sensor, starting with display basics and how to interface the OLED with an Arduino board.

The OLED display used in this project is approximately 1 x 1” in dimension (commonly called a 1-inch display). It has an integrated video controller, the SSD1306.

Features include:

1. 128×64 pixels
2. High contrast
3. I2C communication protocol
4. Dual color (blue and yellow)
5. No backlight required
6. Active type display

One of the advantages of this type of display is that its pixels only consume energy when they are turned on. This means that OLED consumes less power compared to most other displays.

As shown in the diagram above, the display has four pins. Only two – the SDA and SCL pins – are required for the interface. For this project, the VCC pin receives 5 Volts of power supply.

The display works on the I2C communication protocol, a single-ended serial communication bus, which uses only two pins here: the SDA and the SCL. (That's why it's known as TWI or two-wire interface).

The host microcontroller must use the I2C protocol to display the value, whether as a text message, digits, a shape (such as a circle or square), an image. It can even display basic animations. To do this with Arduino you will need to use the Adafruit library.

Just install these two libraries from Adafruit:

  • Adafruit_ssd1306.h
  • Adafruit_GFX.h

These two libraries provide full control of the OLED sensor display. Let's review the circuit diagram below.

The circuit

Circuit Connections
As shown in the diagram above, the circuit is constructed using three components:

1. The Arduino NANO board
2. An OLED display
3. One potentiometer (POT)

  • PT has three terminals. Connect the two final terminals to the +5V and GND pins of the Arduino. The middle pin is a slider, which connects to the Arduino's A0 analog input pin.
  • The OLED has four interface pins: VCC, GND, SDA and SCL. Connect the VCC and GND pins to the +5 V and GND pins on the Arduino. This supplies power to the display. Then connect the SDA and SCL pins to the Arduino pins A4 (SDA) and A5 (SCL) for data communication.
  • The Arduino board requires a USB power supply (from a computer). The integrated voltage regulator chip provides a 5V supply to the POT and the OLED display.

Circuit operation

  • The POT receives a +5 V power supply. Depending on how far its knob is turned, it provides 0 to 5 V analog output voltage via the center slider terminal.
  • This analog voltage output is then fed into the Arduino analog input pin A0. The Arduino reads the input and provides a corresponding digital output number between 0 and 1023. The digital output is displayed on the OLED display as “POT Value”.
  • Then, the Arduino once again converts the digital value (between 0 and 1023) into an analog voltage between 0 and 5 V as follows:

Digital value Analog voltage
1023 5V
XX × (5/1023)

  • The Arduino presents the analog voltage on the display as “ip voltage”.
  • Ultimately, analog and digital values ​​are displayed on the OLED.

Software
The Arduino board (ATMega328) performs the following tasks, serving the software below:

1. Reads the POT's analog voltage input and converts it to a digital value
2. Converts the digital value to an analog voltage
3. Displays analog and digital values ​​on OLED display

This program was written in C/C++ language using Arduino IDE software. It is compiled and loaded using the same software.

Code

The YouTube video link for this project:

Conteúdo Relacionado

Computação Quântica e Novas Linguagens: Explorando o Futuro da Tecnologia
A computação quântica está prestes a transformar radicalmente a maneira...
Bash vs. Perl: Linguagens de Scripting e Processamento de Texto
Em um mundo cada vez mais automatizado, a escolha da...
AutoIt vs. AutoHotkey: Ferramentas Poderosas para Automação de Tarefas no Windows
Neste mundo digital em constante evolução, a necessidade de automatizar...
Ascensão da IA Colaborativa: Unindo Forças para um Futuro Mais Inteligente
Em 2025, a colaboração entre humanos e inteligência artificial (IA)...
F# vs. Scala: Programação Funcional e Orientada a Objetos
A escolha da linguagem de programação certa pode fazer uma...
Q# vs. Qiskit: Diferenças no Desenvolvimento de Computação Quântica
A computação quântica tem sido um campo em rápida evolução,...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.