Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll long text on OLED display

Tags:

arduino

How to scroll a long text on an 128x64 OLED display
am using Adafruit_SSD1306 driver
This code only displays "This" because the text is too large to fit on the display, but when i scroll the text only "This" is scrolling not the rest of the text

display.setTextSize(5);
display.setTextColor(WHITE);
display.setCursor(0,16);
display.clearDisplay();
display.print("This is a long long text");
display.display();
delay(1); 
display.startscrollleft(0x00, 0x0F);
like image 893
Martin Fossdal Guttesen Avatar asked Sep 02 '25 15:09

Martin Fossdal Guttesen


2 Answers

Scroll and wrap around long text lines on a ssd1306 display:

This code is from YT which does this beautifully. My version below works on a ssd1306 128x64 display. Temporary text strings for demo purpose only. It displays 5 lines, the first is stationary. All the remaining scroll. The next line is text size "2". The others are size "1".

/* https://www.youtube.com/watch?v=sTYPuDMPva8
   Set the appropriate screen size in the Adafruit_SSD1306.h by uncommenting
   one of the two following lines.

   //#define SSD1306_128_64 ///< DEPRECTAED: old way to specify 128x64 screen
   //#define SSD1306_128_32 ///< DEPRECATED: old way to specify 128x32 screen
*/

   #include <Adafruit_GFX.h>
   #include <Adafruit_SSD1306.h>

   Adafruit_SSD1306 display(4);

   char message[]="297M LstWyPt, 345M StPt, rec#89";
   int x, minX;

  void setup(){
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setTextWrap(false);
  x = display.width();
  minX = -12 * strlen(message);  // 12 = 6 pixels/character * text size 2
  }

  void loop(){
       
   display.clearDisplay();
   display.setCursor(0,0);
   display.setTextSize(1);
   display.print("Sat:13  03:56:32  67%");// GPS # Satellites, Time, % Batt chg
   display.setTextSize(2);
   display.setCursor(x,10);
   display.print(message);
   display.setCursor(x,28);
   display.setTextSize(1);
   display.print("Press #1 New StPt, 2 RecWayPt, Cur 32.567, -102.456");
   display.setCursor(x,38);
   display.setTextSize(1);
   display.print("Press #1 New StPt, 2 RecWayPt, Cur 32.567, -102.456");
   display.setCursor(x,48);
   display.setTextSize(1);
   display.print("Press #1 New StPt, 2 RecWayPt, Cur 32.567, -102.456");
   display.display();
   x=x-8; // scroll speed, make more positive to slow down the scroll
   if(x < minX) x= display.width();
}
like image 158
J Doe Avatar answered Sep 05 '25 16:09

J Doe


You can solve this by either:

  1. Continuously redrawing the entire frame buffer, or
  2. Shifting the framebuffer contents left and rendering a column worth of text (just a fraction of a character) on the right.

The SSD1306 chip provides commands to enable both continuous scrolling and 1 pixel scroll. For our purpose of scrolling long text, the continuous scroll is not useful, as we want to scroll exactly one pixel. Therefore, we need to use the 1 pixel scroll command. The commands take the same parameters, except for the first opcode byte. For some reason in the widely circulated (and pretty old) datasheet online, the 1 pixel scroll command is missing, but it is there in HW.

#define CMD_CONTINUOUS_SCROLL_H_RIGHT       0x26
#define CMD_CONTINUOUS_SCROLL_H_LEFT        0x27
#define CMD_ONE_COLUMN_SCROLL_H_RIGHT       0x2C
#define CMD_ONE_COLUMN_SCROLL_H_LEFT        0x2D

Use the latter two.

like image 27
roc1 Avatar answered Sep 05 '25 16:09

roc1