With the campaign coming to a close at the end of the week, we’ve realized we have yet to cover a fundamental use-case: writing text to the display on the Omega2 Dash!
But before we dive in, there’s still time for more backers to join us over the next couple of days before the campaign closes! If you know anybody who would get a kick out of the Omega2 Dash, send them a link to our campaign page.
In the Omega2 Dash Linux operating system, the Linux framebuffer is connected to the
/dev/tty1 virtual terminal device. So anything written to this virtual terminal, will actually show up on the screen!
It’s as easy as piping your program output to
/dev/tty1, and seeing it displayed on the screen.
Try it out:
echo "Hello world, it's the Omega2 Dash" > /dev/tty1
To clear the screen:
clear > /dev/tty1
But that’s not all, using ANSI escape characters we can add color!
echo -e "\033[94mWow\033[0m! So \033[92mmuch\033[0m \033[91mroom\033[0m for \033[4mactivities\033[0m" > /dev/tty1
Looking at the command it might seem confusing but it’s straightforward when it’s broken down.
\033acts as an escape character
[94msets the color to bright blue
Wowis the text
\033escape character and
[0mto reset the text formatting to default
Taking this one step further, we can incorporate ANSI escape characters in our scripts and programs.
For example, check out this Python program that loops through the available colors:
import sys for i in range(0, 14): for j in range(0, 16): code = str(i * 16 + j) sys.stdout.write(u"\033[38;5;" + code + "m " + code.ljust(4)) print(u"\033[0m")
Run it on your Omega2 Dash and pipe the output to
python3 color.py > /dev/tty1
We’ve also put together a little Python script that makes it easy to color your text with functions like
term.blue(), and so on.
python3 colorMessage.py > /dev/tty1
Grab the source code from Github.