How to scroll text on a 0.66 inch 64x64 OLED?
How to Scroll Text on a 0.66 Inch 64x64 OLED
To scroll text on a 0.66 inch 64x64 OLED, you need to use hardware scrolling commands built into the SSD1306 driver chip, which is the standard controller for these displays. The display itself has a resolution of 64 pixels horizontally and 64 pixels vertically, with a pixel pitch of 0.21mm and an active area of 13.5mm by 13.5mm. The SSD1306 supports both horizontal and vertical scrolling through dedicated commands in its command set, which is documented in the datasheet (version 1.1, revision 2013). For example, sending the command 0x26 enables continuous horizontal scrolling to the right, while 0x27 scrolls to the left. You must set the start page, end page, and frame rate via the 0x2A command, which defines the scrolling interval in terms of frames. The frame rate depends on the oscillator frequency, which is typically around 4.8 MHz for the internal RC oscillator, giving a frame rate of about 100 Hz. So, if you set the scrolling interval to 2 frames, the text moves every 20 milliseconds. This is a hardware-level feature, meaning the scrolling happens automatically without CPU intervention after the command is sent, which is crucial for low-power applications like wearable devices or small embedded systems.
The 0.66 inch 64x64 oled display uses a 4-wire SPI interface by default, with a maximum clock speed of 10 MHz, though many implementations run at 1-2 MHz to reduce noise. The SPI pins include CS (chip select), DC (data/command), RES (reset), and SCLK (serial clock) along with MOSI (master out slave in). The SSD1306 has a 128x64 pixel RAM buffer internally, but the display only shows a 64x64 window. This means you can use the remaining 64 columns for off-screen buffering, which is handy for scrolling text. For example, you can write a line of text that spans 128 pixels (like 16 characters at 8x8 font size) and then shift the display area horizontally using the 0x21 command for column address range. The column address range is set from 0 to 63 for the visible area, but you can write to columns 0 to 127 in the RAM. To scroll, you increment the starting column address by 1 pixel each frame, creating a smooth scroll effect. This method requires software control, meaning you update the column address in a loop, but it gives you full control over the scroll speed and direction.
For vertical scrolling, the SSD1306 supports vertical scroll with page granularity. The display has 8 pages, each 8 pixels tall (since 64 pixels / 8 = 8 pages). You can use the 0x29 command for vertical scroll area, which defines the top and bottom fixed rows, and the 0x2A command for the scrolling speed. The vertical scroll offset is set in page units, so text moves in 8-pixel increments. This is less smooth than horizontal scrolling, but it works for simple marquee effects. If you need smooth vertical scrolling, you must use software scrolling by shifting the content in the RAM buffer. For example, you can copy the entire 64x64 buffer to a new location offset by 1 pixel vertically, then update the display. This takes about 2 milliseconds per frame at 10 MHz SPI, which is fast enough for 30 fps scrolling. The power consumption during scrolling is about 10-15 mA for the OLED itself, plus the microcontroller's current, which is typically 5-10 mA for an ARM Cortex-M0 running at 48 MHz.
Font rendering is a key factor. The 64x64 resolution limits you to small fonts. A common choice is the 5x7 pixel font, which gives 8 characters per row (since 64 / 8 = 8, but with 1 pixel spacing, you get 7 characters). For a 6x8 font, you get 8 characters per row as well. If you use a 8x8 font, you get 7 characters per row (64 / 9 = 7.1). The total number of rows is 8 for 8-pixel tall fonts, or 9 for 7-pixel tall fonts with 1 pixel spacing. So, a full screen of text can hold 56 to 72 characters. To scroll text, you typically use a single line of text that is longer than the screen width. For example, a 32-character message in 5x7 font requires 32 * 6 = 192 pixels (including 1 pixel spacing). This is three times the screen width, so you need to scroll it horizontally. The scroll speed is defined by the delay between shifts. A common value is 50 milliseconds per pixel, which gives a smooth scroll at 20 pixels per second. This means a 192-pixel message takes 9.6 seconds to scroll across the screen.
Data formatting is critical for performance. The SSD1306 expects data in column-major order, meaning each byte represents 8 vertical pixels in a column. For a 64x64 display, you send 64 bytes per page, and 8 pages total, so 512 bytes for a full frame. To scroll text, you need to update only the changed columns. For example, if you scroll 1 pixel to the left, you only need to rewrite the new column that appears on the right edge, which is 8 bytes (one column per page). This reduces SPI traffic from 512 bytes to 8 bytes per frame, which is a 64x improvement. This is especially important for battery-powered devices, as SPI transactions consume power. The SSD1306 also supports partial display updates via the 0x21 and 0x22 commands for column and page address ranges. You can set the column range to just the new column, and the page range to all 8 pages, reducing the data transfer to 8 bytes. This technique is used in many commercial products like smartwatches and fitness trackers.
Hardware scrolling has limitations. The SSD1306's built-in scrolling only works in one direction at a time, and it cannot stop at a specific point. It loops continuously until you send a stop command (0x2E). This is fine for marquee text, but not for text that needs to stop at the end. For stop-and-start scrolling, you need software control. Another limitation is that the scrolling speed is fixed by the frame rate and the interval setting. The interval can be set from 2 to 7 frames, giving speeds from 50 to 14 pixels per second at 100 fps. This is a narrow range. If you need slower scrolling, you must use software scrolling with a delay loop. For example, a delay of 100 milliseconds per pixel gives 10 pixels per second, which is readable for most users.
Power considerations are important for portable devices. The OLED display consumes about 10 mA at full brightness, which is 100% duty cycle. The SSD1306 supports contrast control via the 0x81 command, which sets the current drive level from 0 to 255. At 50% contrast (value 128), the current drops to about 5 mA. Scrolling text can be done at lower contrast because the motion attracts attention. In practice, a contrast value of 100 (about 40%) is sufficient for indoor use, drawing 4 mA. The microcontroller's power during scrolling depends on the SPI frequency. At 1 MHz SPI, the CPU is busy for about 1 millisecond per frame, which at 30 fps gives 30 ms of active time per second, or 3% duty cycle. This means the average current for the microcontroller is about 0.3 mA at 10 mA active current. Total system power is around 5 mA, which allows a 200 mAh battery to last 40 hours of continuous scrolling.
Temperature and environmental factors affect scrolling performance. The SSD1306 operates from -40°C to +85°C, but the OLED panel's brightness drops at low temperatures. At -20°C, the brightness is about 50% of the room temperature value, so you may need to increase contrast. The scrolling speed is unaffected because it's driven by the digital logic. However, the oscillator frequency can drift by up to 10% over temperature, which changes the frame rate and thus the scroll speed. For precise timing, use an external clock source, like a crystal oscillator, instead of the internal RC oscillator. The SSD1306 supports external clock input on the CLK pin, which can be driven by a 32.768 kHz crystal for low-power operation. This gives a frame rate of about 100 Hz, which is stable over temperature.
Software implementation varies by platform. On Arduino, the Adafruit SSD1306 library provides a scrollText() function that uses hardware scrolling. The library sets the scroll parameters via the 0x2A command and starts scrolling with 0x2F. The code is about 50 lines. On STM32, you can use the HAL library to send SPI commands directly. The initialization sequence for the SSD1306 includes setting the display to off (0xAE), setting the multiplex ratio to 63 (0xA8, 0x3F), setting the display offset to 0 (0xD3, 0x00), setting the start line to 0 (0x40), setting the segment re-map to column 127 (0xA1), setting the COM pins hardware configuration (0xDA, 0x12), setting the contrast (0x81, 0xCF), setting the pre-charge period (0xD9, 0xF1), setting the VCOMH deselect level (0xDB, 0x40), setting the display to on (0xAF), and then clearing the display. This sequence takes about 100 milliseconds at 1 MHz SPI. After initialization, you can start scrolling.
For custom scrolling effects, you can combine hardware and software techniques. For example, you can use hardware scrolling to move the text horizontally, and then use software to update the text content every few seconds. This creates a ticker-tape effect. The text content is stored in a circular buffer, and you update the display RAM when the scroll reaches the end of the current text. The buffer size is 128 bytes for a 128-column wide text line (since 128 columns * 8 pages = 1024 bits, but the SSD1306's RAM is organized as 128 columns * 64 rows, so 1024 bytes total). For a 64x64 display, you only use the first 64 columns, so the buffer is 512 bytes. The remaining 512 bytes can be used for off-screen text. This allows you to have two lines of text that scroll in sequence. The update rate is 30 fps, which is smooth for human eyes.
Reliability is a concern for long-term scrolling. The OLED panel has a lifetime of about 10,000 hours at full brightness, which is about 1.1 years of continuous use. At lower brightness, the lifetime increases to 20,000 hours or more. Scrolling text does not cause burn-in because the pixels are constantly changing. However, if the same text is displayed for long periods, the static parts (like the background) can cause burn-in. To avoid this, use a screensaver that shifts the entire display by a few pixels every hour. This is common in industrial applications. The SSD1306 supports a display offset command (0xD3) that shifts the display vertically, which can be used for this purpose.
Cost is another factor. The 0.66 inch 64x64 oled display typically costs between $3 and $5 in single quantities, and less than $2 in volume. The SSD1306 driver is integrated into the display module, so no external driver is needed. The total BOM for a scrolling text project includes the display, a microcontroller (like an STM32F030 at $0.50), a 10 µF capacitor for decoupling ($0.05), and a few resistors for the SPI pull-ups ($0.10). Total cost is under $6. This makes it suitable for high-volume products like smart badges, wearable name tags, and small IoT devices. The display's power consumption is low enough to run on a coin cell battery for weeks. For example, a CR2032 battery has 225 mAh capacity. At 5 mA average current, the device runs for 45 hours. If you use a 1000 mAh LiPo battery, it runs for 200 hours, or 8 days continuously.
Testing scrolling performance requires an oscilloscope to measure SPI timing. The typical SPI waveform shows a 10 MHz clock with 8-bit data packets. The CS line goes low for 8 clock cycles, then high. The DC line is low for commands and high for data. The scrolling command sequence is: send 0x2E (stop scrolling), send 0x2A (set scroll parameters) with 5 bytes (direction, start page, end page, frame interval, dummy byte), send 0x2F (start scrolling). The total time for this sequence is about 10 microseconds at 10 MHz. The display then starts scrolling automatically. The scroll speed is determined by the frame interval. For example, with interval 2, the text moves one pixel every 2 frames, or 20 ms at 100 fps. This gives a speed of 50 pixels per second. To measure this, you can use a photodiode to detect the light change from a pixel edge. The photodiode output shows a square wave with a period of 20 ms, confirming the speed.
Alternative approaches include using a GPU for scrolling, but this is overkill for a 64x64 display. The SSD1306's built-in scrolling is sufficient for most applications. For more complex effects like diagonal scrolling, you need to use software. This involves copying the RAM buffer to a new location with an offset in both x and y. The copy operation takes about 2 milliseconds for a 512-byte buffer at 10 MHz SPI. This is fast enough for 30 fps diagonal scrolling. The diagonal speed is sqrt(2) times slower than horizontal or vertical scrolling because both axes move simultaneously. For example, if you scroll 1 pixel horizontally and 1 pixel vertically per frame, the effective speed is 1.4 pixels per frame, or 140 pixels per second at 100 fps. This is too fast for readable text, so you need to reduce the frame rate or increase the delay. A delay of 50 ms per frame gives 20 pixels per second, which is readable.
User interface design is important for scrolling text. The text should be centered vertically and horizontally on the screen. For a 5x7 font, the text height is 7 pixels, so you can center it by starting at page 3 (since 8 pages total, and text takes 1 page, so start at page 3.5, but pages are integer, so start at page 3 or 4). The text width should be less than 64 pixels for the initial display. If the text is longer, it scrolls into view. The scroll direction should be indicated by an arrow or a fade effect. For example, you can fade the first character by reducing its contrast gradually. This is done by writing the character with a lower contrast value (like 0x81 with value 64) for the first column. This creates a smooth entry effect. The same technique can be used for the exit effect. The fade takes about 10 frames, or 100 ms at 100 fps. This is a common technique in professional displays.
Compatibility with different microcontrollers is straightforward. The SSD1306 uses standard SPI, so it works with any MCU that has an SPI peripheral. On Arduino, you use the SPI library. On Raspberry Pi, you use the spidev driver. On ESP32, you use the SPI library with the VSPI bus. The display's logic level is 3.3V, but it is 5V tolerant on the SPI pins. This means you can connect it directly to a 5V Arduino without level shifters. However, the OLED's maximum voltage is 3.3V for the power supply, so you need a 3.3V regulator if using a 5V source. The display's current draw is low enough that a linear regulator like the AMS1117-3.3 works fine. The regulator's dropout voltage is 1.1V, so it works with a 4.5V input minimum. For battery operation, use a low-dropout regulator like the MCP1700, which has a dropout of 0.1V at 10 mA.
Debugging scrolling issues is common. The most frequent problem is that the display shows garbage after scrolling. This is usually because the column address range is not set correctly. The SSD1306's default column address range is 0 to 127, but the display only shows 0 to 63. If you write data to columns 64 to 127, it is stored in RAM but not displayed. When you scroll, the display shifts the RAM window, so columns 64 to 127 become visible. This can show old data. To fix this, clear the entire RAM before scrolling. Use the 0x21 command to set the column range to 0 to 127, then write 0x00 to all 128 columns. This takes 1024 bytes of SPI data, which is about 1 millisecond at 10 MHz. Another issue is that the scroll direction is reversed. The SSD1306's horizontal scroll direction is controlled by the 0x26 or 0x27 command. If you send 0x26, it scrolls right. If you send 0x27, it scrolls left. But the display's segment mapping also affects direction. The default segment mapping is column 0 to SEG0, which is the leftmost pixel. If you use the 0xA1 command (segment re-map), the mapping is reversed, so scrolling right becomes scrolling left. Always check the segment mapping before configuring scrolling.
Performance optimization involves reducing SPI transactions. The SSD1306 supports a burst mode where you send multiple bytes without toggling the CS line. This reduces overhead. For example, to clear the display, you send 1024 bytes in one burst. The CS line is held low for the entire transaction. This takes about 820 microseconds at 10 MHz. In contrast, sending 1024 separate 1-byte transactions with CS toggling takes about 10 milliseconds, due to the overhead of toggling CS. The burst mode is enabled by default in the SSD1306. Another optimization is to use DMA for SPI transfers. On STM32, the DMA controller can transfer data without CPU intervention. This allows the CPU to sleep or do other tasks while the display updates. The DMA transfer rate is up to 10 MHz, so a full frame