0

Does anyone know how to wrap and or text using the U8G2 Libary? I know there are other libraries that do this for you, but I'd like to use U8G2.

Thank you!

My code's here for reference. It's not clean, but it works for now.

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Feb 11, 2017 at 11:26
2
  • You have to do it manually. Scrolling is a simple matter of printing substrings and padding with spaces. Wrapping is a simple matter of printing substrings on different lines. Commented Feb 11, 2017 at 12:17
  • The Arduino Uno has very limited amount of memory to implement scrolling and wrapping of text for an LCD driver in general. The sketch has to do this, e.g. calculate line breaks, sub-section of text to be displayed, update when focus changes (i.e. scroll), save text, etc. Your sketch seems to be only a limited amount of text so you should be able to do this calculations, save of state, text box projection, etc. Commented Feb 11, 2017 at 14:23

1 Answer 1

1

You can do something like this:

 void loop(void) {
 u8g2_uint_t x;
 
 u8g2.firstPage();
 do {
 
 // draw the scrolling text at current offset
 x = offset;
 u8g2.setFont(u8g2_font_inb30_mr); // set the target font
 do { // repeated drawing of the scrolling text...
 u8g2.drawUTF8(x, 30, text); // draw the scolling text
 x += width; // add the pixel width of the scrolling text
 } while( x < u8g2.getDisplayWidth() ); // draw again until the complete display is filled
 
 u8g2.setFont(u8g2_font_inb16_mr); // draw the current pixel width
 u8g2.setCursor(0, 58);
 u8g2.print(width); // this value must be lesser than 128 unless U8G2_16BIT is set
 
 } while ( u8g2.nextPage() );
 
 offset-=1; // scroll by one pixel
 if ( (u8g2_uint_t)offset < (u8g2_uint_t)-width ) 
 offset = 0; // start over again
 
 delay(10); // do some small delay
 }

The code is taken from https://github.com.

It is an excellent library, but it is can require a big amount of memory, fit very well on ESP8266 (tried on nodeMCU) / ESP32.

Of course on ESP32 it is faster.

Used for small OLED 0.98" screen.

answered Dec 28, 2017 at 0:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.