Linux - Embedded & Single-board computerThis forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bakebit OLED display was originally included in Friendly ARM Linux distro for NANO Pi. That is distro of Ubuntu/Debian 14.04 without X related functionality because this board does not contain GPU.
I try to print on display non-ASCII characters, included in TTF fonts provided by Bakebit. Based on included samples I wrote such code in Python2.7:
Code:
#!/usr/bin/env python
#-*- coding: utf-8 -*- # Added for UTF-8 support
#
import bakebit_128_64_oled as oled
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import RPi.GPIO as GPIO
import time
import sys
import subprocess
import threading
import os
import socket
reload(sys) # Added for UTF-8 support
sys.setdefaultencoding('utf-8') # Added for UTF-8 support
global width
width=128
global height
height=64
# Reset OLED display
GPIO.setmode(GPIO.BOARD)
GPIO.setup(37, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.OUT)
GPIO.output(24, True)
time.sleep(0.1)
GPIO.output(24, False)
time.sleep(0.1)
GPIO.output(24, True)
time.sleep(0.2)
#
# End RESET display
#
oled.init() #initialze SEEED OLED display
oled.setNormalDisplay() #Set display to normal mode (i.e non-inverse mode)
oled.setHorizontalMode()
global image
image = Image.new('1', (width, height))
global draw
draw = ImageDraw.Draw(image)
global fontb24
fontb24 = ImageFont.truetype('DejaVuSansMono-Bold.ttf', 24);
global font14
font14 = ImageFont.truetype('DejaVuSansMono.ttf', 14);
global smartFont
smartFont = ImageFont.truetype('DejaVuSansMono-Bold.ttf', 10);
global fontb14
fontb14 = ImageFont.truetype('DejaVuSansMono-Bold.ttf', 14);
global font11
font11 = ImageFont.truetype('DejaVuSansMono.ttf', 11);
draw.rectangle((0,0,width,height), outline=0, fill=0)
oled.drawImage(image)
draw.text((10, 0), "START SYSTEMU", font=fontb14, fill=255)
draw.text((23, 18), "AUTOMATYKI", font=fontb14, fill=255)
draw.text((0, 40), "SKRZYPOWA", font=fontb24, fill=255)
oled.drawImage(image)
time.sleep(5)
draw.rectangle((0,0,width,height), outline=0, fill=0)
oled.drawImage(image)
This code works OK. But if I change any letter to other, included in DejaVuSansMono but non-ASCII, random characters are display. If I print to console instead OLED, all characters are presented correctly. What I should change to get it working with full DejaVuSansMono character set?
Note, that I added all necessary commands to get python 2.7 working with UTF-8.
Last edited by mackowiakp; 10-17-2019 at 11:54 AM.
TTF fonts are X fonts; If you don't have X, you're on keyboard fonts which are in /usr/share/kbd/consolefonts, and are psf.gz & psfu.gz There's a selection of stuff there in /usr/share/kbd/ and it may be possible to cobble together a unicode font, & keymap to suit you, but it would be system wide, unless you set it up otherwise. I've just done it in X to get some maths stuff like ≤≥÷ºπ≠±Δ going on an X keyboard.
I'd look for a unicode mapping of character to code, and you can fairly quickly hack something up.
Maybe, but all these things feed into a GPU, which you apparently haven't got…
Without a gpu, I would need a much better understanding of your hardware and display before I could say if what you want is even possible. TTF offers scalable fonts giving varying sized characters. Simpler displays are inclined to have a maximum character size and a number of lines defined. You're more or less stuck with the font sizes they include. Have fun, and I wish you luck.
It is not GPU absence or UBUNTU related problem. Its related to python 2.7 I think. If I login to RPi over SSH and print text containing my language specific characters to console instead OLED display, all characters are printed correctly (using python 2.7 code). Of course it is possible to enter such characters from CLI (via SSH console), according to LOCALE. So keyboard mapping works OK.
OLED 0,96 inch display is connected to RPi over I2C interface. Such display has very limited resolution x=64, y=128 pixels.
To print anything on OLED, it is necessary import such library:
convert TTF to bitmap/pixel form, 14 pixels size in height, necessary - in fact - to draw a picture not characters . So letters are - in fact - part of bitmap picture.
Another library call is:
Stands for: draw bit mapped letters "START SYSTEMU" starting form pixels x=10 y=0, using TTF, bit mapped converted fonts 14 pixels height.
I think now its more clear.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.