Display-o-tron - scroll / wrap text


I’m trying to use my dothat as a display for song info from volumio (using mpd, mpd-python)

It’s gone ok so far but have some issues with the formatting of the text on the dothat and not sure what to do so wondering if anyone has any advice.

at the moment i use the 3 lines of the display for:-


the problem is if any of these go above the character limit for the row then they wrap onto the next line.

i’ve had a look at the code for scrolling text at this link for the dothat breakout:-


That works scrolling the text but scrolls the wrapped text, it doesn’t keep it on a single line.

I have started to look at the MenuOption on the dothat github page but work has got in the way so will go back to later, not entirely sure if this will let me do what I aim to though!?

any advice / help will be much appreciated. obviously dealing with a bit of an amateur here :)


You can sort-of bodge it if you’re dealing directly with Display-o-Tron and not using the whole Menu system.

Imagine the phrase “This Is Some Scrolling Text”

The trick is to use the listy nature of text strings to:

  1. Pad your text string so it doesn’t join at the wrap point like this: “extThis Is Some Scrolling T”
  2. Rotate the text you’re displaying so the first letter is removed and plonked onto the end
  3. Snip the text you’re displaying to a maximum of 16 characters long

So you start with (using show_text as a stand-in for whatever you’re calling to display text on the display):

>>> text = "This Is Some Scrolling Text"  # Our starting phrase
>>> text = text + "    "                  # Add some spaces for padding
>>> text[:16]                             # Grab only the first 16 letters
"This Is Some Scr"
>>> text = text[1:] + text[0]             # Rotate the board!

>>> text                                  # Let's see what that did...
'his Is Some Scrolling Text    T'

>>> text[:16]                             # Okay so grab the first 16 chars again
'his Is Some Scro'

>>> text = text[1:] + text[0]             #  We be scrollin'

>>> text                                  # How does it look now?
'is Is Some Scrolling Text    Th'

>>> text[:16]                             # And the first 16 chars?
'is Is Some Scrol'

Hopefully you can see what I’m getting at here! Using this pattern, and a little looping you should be able to whip up a function to scroll text.

There are, no doubt, better ways to accomplish this that don’t involve mutating your original text string :D

thank you very much for replying, I had seen similar examples online but none that broke it down so I could see what each line was doing! Much appreciated.

Using that i have managed to butcher together something that works but I have another question… :)

For looping I am using a For loops and I have 3 of them (title, artist, album) - 1 on each line. Is there a way to have these working at the same time? At the moment each one loops perfectly but artist waits until title has finished, etc.

I have managed to sort of get it working using itertools and chaining. This has them all scrolling at the same time but it uses the longest iteration which means if the artist is only 7 characters long and the title is 17 i get 10 characters of the final letter repeated on the artist line!

I’m probably making it harder than it needs to be but any further guidance would be appreciated!

My solution would probably be the simple one- pad the Title, Artist and Album with whitespace so that they’re all the same length. Then bung a bit of extra whitespace on for good measure.

First you’ll want to get the longest string, and its length:

>>> artist = "Bob The Builder"
>>> title = "Constructing a Dystopian Universe"
>>> album = "Happy Building Times"
>>> max((artist, title, album), key=len)
'Constructing a Dystopian Universe'
>>> len(max((artist, title, album), key=len))

And then pad them to the same length:

>>> longest = len(max((artist, title, album), key=len))
>>> artist.ljust(longest, " ")
'Bob The Builder                  '
>>> title.ljust(longest, " ")
'Constructing a Dystopian Universe'
>>> album.ljust(longest, " ")
'Happy Building Times             '

Finally pad them all with a bit of extra whitespace to stop a hard-wrap, then the shorter ones will scroll off the screen toward the end.

hey thanks for this, sorry it’s taken so long to reply and say thanks, moved house and I’ve just started to get my toys out to starts tinkering again :)

can’t believe it’s been 4 months!

1 Like

I’m in the process of doing the same- it really can sink a lot of time!

1 Like

can’t it just!

now back to my pi, DOTHat, volumio and scrolling this text :D