Skip to content

How to display text on a 1.54 inch 128x64 OLED screen?

aPor adminEditores Jovens Online

To display text on a 1.54 inch 128x64 OLED screen, you need to interface it with a microcontroller like an Arduino or ESP32 using SPI or I2C communication, then write data to the display buffer using a graphics library such as Adafruit_SSD1306 or U8g2. The screen itself is a monochrome OLED panel with a resolution of 128 pixels horizontally and 64 pixels vertically, each pixel individually addressable, and it uses a SSD1306 or SH1106 driver IC. For text rendering, you typically load a font bitmap into the microcontroller’s memory, then map each character to a 5x7 or 6x8 pixel grid, writing the pixel data to the display’s RAM. The 1.54 inch 128x64 oled display operates at 3.3V logic levels, draws about 20mA during full-on operation, and has a contrast ratio of over 2000:1, making text highly readable even in direct sunlight. The SPI interface uses four pins: MOSI, SCK, CS, and DC, plus a RESET pin, running at up to 10MHz clock speed, which gives you a full frame refresh rate of about 30Hz. If you use I2C, you only need SDA and SCL, but the maximum data rate is 400kHz, so text updates are slower. The display’s active area is 35.04mm x 17.52mm, with each pixel measuring 0.274mm x 0.274mm, so at a typical viewing distance of 30cm, you can easily read 8-point fonts. The built-in OLED pixels are self-emissive, meaning no backlight is needed, and the screen has a viewing angle of 160 degrees both horizontally and vertically. The driver IC contains a 128x64 bit SRAM buffer, where each bit corresponds to one pixel: a 1 turns the pixel on (emitting white or blue light depending on the panel), and a 0 turns it off. To display text, you write character bitmaps into this buffer, then send the entire buffer to the IC via a command like “Set Display Start Line” or “Set Column Address Range.” The SSD1306 supports page addressing mode, where the 64 rows are divided into 8 pages of 8 rows each, so you can write a string by setting the page and column, then sending 128 bytes of data per page. For example, to display “Hello World” at the top-left corner, you set the column start to 0, page start to 0, then send the font data for each character sequentially. The font data is stored as a byte array, where each byte represents a vertical column of 8 pixels: for a 5x7 font, each character takes 5 bytes (plus one byte of spacing). You can use the Adafruit library which includes a 5x7 font by default, or you can define custom fonts using the U8g2 library, which supports over 1000 fonts including proportional and fixed-width types. The U8g2 library uses a framebuffer or direct page buffer approach: with a full framebuffer, you allocate 1024 bytes (128x64/8) in RAM, draw all text and graphics, then flush to the display; with a page buffer, you only allocate 128 bytes for one page, but you must redraw the entire page each time the display refreshes. For a 1.54 inch 128x64 OLED, the page buffer method is more memory-efficient for microcontrollers with limited RAM, like the Arduino Uno with only 2KB of SRAM. The display’s refresh rate is configurable via the “Set Display Clock Divide Ratio” command, which sets the internal oscillator frequency: a typical value is 0x80 for a 128Hz frame rate, but you can increase it to 0xF0 for 256Hz to reduce flicker when scrolling text. The contrast is controlled by the “Set Contrast Control” command, which takes a value from 0x00 (off) to 0xFF (full brightness). For text legibility, a contrast setting of 0x7F works well in indoor lighting, while 0xCF is better outdoors. The display also supports a pre-charge period and charge pump voltage settings: the default charge pump voltage is 0x14 (7.5V), but you can increase it to 0x1A (9V) for brighter pixels, though this draws more current. When displaying text, you must account for the OLED’s burn-in behavior: if you keep static text for hours, the pixels degrade faster, so you should implement a screen saver that shifts the display content by a few pixels every few minutes. The SSD1306 includes a “Display Start Line” register that can be used to scroll the entire screen vertically by changing the start line address, which is a simple way to implement smooth scrolling without rewriting the buffer. For horizontal scrolling, you can use the “Horizontal Scroll Setup” command, which automatically shifts the content left or right at a rate set by the “Set Scroll Interval” command—options are 2, 3, 4, 5, 25, 64, 128, or 256 frames per step. This hardware scrolling feature is useful for displaying long text strings like “This is a 1.54 inch 128x64 OLED display” without needing a full buffer update. The display’s power consumption varies with the number of lit pixels: at 50% pixel on (typical text), it draws about 15mA from a 3.3V supply, which is 49.5mW. If you use the sleep mode (via the “Display Off” command), the current drops to 2µA, making it suitable for battery-powered devices. The operating temperature range is -40°C to +85°C, so it works in outdoor environments. The physical dimensions of the module are 42.0mm x 27.3mm x 2.8mm, with a mounting hole pattern for M2 screws. The interface pins are usually 0.1-inch pitch, compatible with breadboards. When wiring, you must use a level shifter if your microcontroller runs at 5V, because the OLED’s logic pins are not 5V-tolerant. The SPI interface requires a chip select (CS) pin that must be pulled low before sending commands or data. The data/command (DC) pin differentiates between commands (low) and data (high). For example, to initialize the display, you send a sequence of commands: 0xAE (display off), 0xD5 (set display clock divide ratio), 0x80 (default), 0xA8 (set multiplex ratio), 0x3F (64 rows), 0xD3 (set display offset), 0x00 (no offset), 0x40 (set start line to 0), 0x8D (enable charge pump), 0x14 (enable), 0x20 (set memory addressing mode), 0x00 (horizontal), 0xA1 (set segment remap, column 127 mapped to SEG0), 0xC8 (COM output scan direction, remapped mode), 0xDA (set COM pins hardware configuration), 0x12 (alternative pin configuration), 0x81 (set contrast), 0xCF (high contrast), 0xD9 (set pre-charge period), 0xF1 (phase 1: 15 clocks, phase 2: 1 clock), 0xDB (set VCOMH deselect level), 0x40 (0.77x VCC), 0xA4 (display on, resume to RAM content), 0xA6 (normal display, not inverted), 0xAF (display on). After initialization, you can write text by setting the cursor position and sending font data. For example, to write the character ‘A’ at column 0, page 0, you send the byte array {0x7C, 0x12, 0x11, 0x12, 0x7C} if using a 5x7 font. The first byte 0x7C (binary 01111100) represents the top 8 pixels of the first column: bits 2-6 are on, which forms the top of the ‘A’. The next bytes form the middle and bottom. You must repeat this for each character, incrementing the column address by 6 (5 for the character plus 1 for spacing). The U8g2 library simplifies this: you call u8g2.setFont(u8g2_font_5x7_tf), then u8g2.drawStr(0, 8, “Hello World”), and u8g2.sendBuffer(). The library handles the page buffer management and font bitmaps. For larger fonts, like 12x16, you need more memory: each character takes 24 bytes (12 columns x 2 pages), so a 20-character string requires 480 bytes of font data plus the buffer. The display’s pixel pitch is 0.274mm, so a 12x16 font is about 3.3mm tall, which is readable at 1 meter. You can also use the display to show text in multiple languages by storing Unicode bitmaps, but the SSD1306 only supports 8-bit data, so you need to pre-render the glyphs. The display’s SPI speed can be pushed to 20MHz on some microcontrollers, but the typical limit is 10MHz due to the SSD1306’s internal timing. At 10MHz, writing a full 1024-byte buffer takes 0.819ms (1024 bytes x 8 bits / 10MHz), plus command overhead, so you can update the display at over 1000Hz theoretically, but the pixel response time is about 10µs, so the practical limit is around 100Hz for smooth animation. For text scrolling, you can use the hardware scrolling feature: send 0x26 (right horizontal scroll) or 0x27 (left horizontal scroll), then set the start page, end page, and scroll speed. For example, to scroll the entire screen left at 5 frames per step, send 0x27, 0x00 (dummy byte), 0x00 (start page), 0x07 (end page), 0x05 (scroll speed), 0x00 (dummy), 0xFF (dummy), then 0x2F (activate scroll). The display will automatically shift the content left by one pixel every 5 frames, which at 30fps gives a smooth scroll of 6 pixels per second. You can stop scrolling with 0x2E. This hardware method does not require buffer updates, so the microcontroller can sleep or do other tasks. The display’s memory is organized as 128 columns by 8 pages, each page being 8 rows. When you use horizontal addressing mode, the column address increments automatically after each byte, wrapping to the next page after column 127. This is efficient for writing a single line of text across the screen. For vertical addressing mode, the page address increments first, which is useful for writing tall characters. The display also supports a “Charge Pump” that generates the 7.5V to 9V required for the OLED pixels. The charge pump has a built-in capacitor, and you must not connect an external voltage. The display’s lifetime is rated at 50,000 hours to half brightness at 25°C, but this decreases with higher temperature and brightness. For text displays, you can reduce the contrast to 0x3F to extend lifetime. The display has a built-in DC-DC converter that operates at 600kHz, and you can hear a faint whine if the frequency is in the audible range. The module usually includes a 10µF capacitor on the VCC pin to filter noise. When you write text, you must ensure the font data is stored in PROGMEM (program memory) on AVR microcontrollers to avoid filling SRAM. For example, const unsigned char font[] PROGMEM = {0x7C, 0x12, 0x11, 0x12, 0x7C}; then use pgm_read_byte() to access it. The U8g2 library automatically handles this. The display’s SPI interface can be shared with other SPI devices, but you must use separate CS pins. The maximum number of SPI devices on a single bus is limited by the capacitive load, but for a typical setup, you can run two or three displays. The display’s driving voltage is 3.3V, but the logic pins are 3.3V only, so do not connect 5V directly. The display’s current consumption is 20mA with all pixels on, but with typical text (about 10% pixels on), it’s around 5mA. The screen’s active area is 35.04mm x 17.52mm, which is about 1.38 inches x 0.69 inches. The aspect ratio is 2:1, so text lines are short. For a 5x7 font, you can fit about 21 characters per line (128 pixels / 6 pixels per character), and 8 lines (64 rows / 8 rows per line). That gives you 168 characters total, which is enough for a short paragraph. For a 8x16 font, you get 16 characters per line and 4 lines, total 64 characters. The display’s viewing angle is 160 degrees, so text is readable from the side. The display module usually has a 0.1-inch pitch 4-pin header for SPI (GND, VCC, SCL, SDA, plus optional CS, DC, RESET). Some modules have a 7-pin header for full SPI. The I2C version uses a 4-pin header (GND, VCC, SCL, SDA) with a fixed address of 0x3C or 0x3D. The display’s resolution is 128x64, which is a common size for text and simple graphics. The pixel density is 93 PPI (pixels per inch), which is lower than a smartphone but adequate for a small display. The display’s response time is under 10µs, so there is no ghosting when scrolling text. The display’s brightness is typically 100 cd/m² at full contrast, which is comparable to a dim LED. The display’s contrast ratio is 2000:1, so black pixels are truly off. The display’s color is white or blue depending on the panel. The blue panels have a slightly higher efficiency. The display’s thickness is 2.8mm, so it can be mounted in thin enclosures. The display’s weight is about 5 grams. The display’s interface is compatible with 3.3V logic, and you can use a voltage divider for 5V to 3.3V conversion. The display’s SPI bus speed is limited by the length of the wires: for wires longer than 10cm, you should use a 100Ω series resistor on the clock line to reduce ringing. The display’s initialization sequence is standardized, but some modules require a different multiplex ratio or offset. For example, some 1.54 inch modules use a 64-row multiplex, but others use 48 rows. You should check the datasheet. The display’s command set includes 0x21 (set column address range) and 0x22 (set page address range), which allow you to write to a specific rectangular area without rewriting the entire buffer. This is useful for updating a single character without flicker. For example, to update the character at column 30, page 2, you set column start to 30, column end to 35, page start to 2, page end to 2, then send 6 bytes of font data. The display’s internal RAM is not cleared on power-up, so you must initialize the buffer to 0x00. The display’s sleep mode can be entered by sending 0xAE, which disables the charge pump and reduces current to 2µA. To wake up, send 0xAF. The display’s reset pin is active low, and you should hold it low for at least 1µs after power-up. The display’s VCC pin should be connected to 3.3V, and the ground pin to GND. The display’s logic pins are not 5V tolerant, so use a level shifter if your microcontroller is 5V. The display’s typical application is for text readout in portable devices, like a multimeter or a weather station. The display’s SPI interface uses a 4-wire or 7-wire configuration. The 4-wire SPI uses MOSI, SCK, CS, and DC, with RESET tied to VCC. The 7-wire SPI uses all pins. The display’s I2C interface uses a 4-wire configuration with a fixed address. The display’s maximum I2C speed is 400kHz. The display’s text rendering can be optimized by using a double buffer: write to a buffer in RAM, then copy to the display. This avoids tearing. The display’s update rate is limited by the pixel response time, which is 10µs, so you can update individual pixels at 100kHz. The display’s lifetime is 50,000 hours at 25°C, but this drops to 10,000 hours at 85°C. The display’s storage temperature is -40°C to 85°C. The display’s humidity range is 10% to 90% non-condensing. The display’s ESD rating is 2kV for human body model. The display’s soldering profile is 260°C for 10 seconds. The display’s module usually has a PCB with a 0.1-inch pitch header. The display’s viewing angle is 160 degrees, so text is readable from the side. The display’s contrast is adjustable via software. The display’s power consumption is 20mA max. The display’s resolution is 128x64. The display’s pixel size is 0.274mm. The display’s active area is 35.04mm x 17.52mm. The display’s module size is 42.0mm x 27.3mm x 2.8mm. The display’s weight is 5g. The display’s interface is SPI or I2C. The display’s driver IC is SSD1306 or SH1106. The display’s color is white or blue. The display’s brightness is 100 cd/m². The display’s contrast ratio is 2000:1. The display’s response time is 10µs. The display’s operating voltage is 3.3V. The display’s logic voltage is 3.3V. The

Receber vagas no WhatsApp toda semana

312 mil jovens já recebem · gratuita · cancele quando quiser · chega toda segunda-feira.

Quero entrar na lista →