LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This 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


Reply
  Search this Thread
Old 10-17-2019, 11:51 AM   #1
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 9, SH4, Debian
Posts: 367

Rep: Reputation: 8
Nano Pi, no non-ASCII characters on OLED display


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.
 
Old 10-22-2019, 11:27 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,356

Rep: Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332
I think you're on a loser there.

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.
 
Old 10-22-2019, 12:44 PM   #3
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 9, SH4, Debian
Posts: 367

Original Poster
Rep: Reputation: 8
But I think that OLED library import from TTF font file necessary font shape and change it to pixels:

Code:
#-*- coding: utf-8 -*-  # Added for UTF-8 support
#
import bakebit_128_64_oled as oled
from PIL import Image
from PIL import ImageFont
And next:

Code:
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);
It works for me OK on OLED with ASCII characters. The problem I have, how to pass UTF-8 encoded symbols to for example:

Code:
draw.text((10, 0), "START SYSTEMU", font=fontb14, fill=255)
All in python 2.7 of course.
 
Old 10-24-2019, 05:03 AM   #4
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,356

Rep: Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332
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.
 
Old 10-25-2019, 03:27 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
I think I'm beginning to understand the question.
Have a look here, the first askubuntu looks like it has good answers for you.
 
Old 10-26-2019, 12:08 AM   #6
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 9, SH4, Debian
Posts: 367

Original Poster
Rep: Reputation: 8
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:

Code:
import bakebit_128_64_oled as oled
https://github.com/friendlyarm/BakeBit

And there is a command in this library which converts any TTF scalable fonts to bit-mapped form in any size. For example library call:
Code:
fontb14 = ImageFont.truetype('DejaVuSansMono-Bold.ttf', 14);
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:
Code:
draw.text((10, 0), "START SYSTEMU", font=fontb14, fill=255)
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.
 
  


Reply

Tags
nano, python2, raspberry, ubuntu 14.04



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Horseshoe shaped Arduino clone has an OLED display and loads of LEDs LXer Syndicated Linux News 0 11-02-2017 03:38 AM
Rant about non ascii characters disappearing when using the non advanced editor Didier Spaier LQ Suggestions & Feedback 1 02-08-2016 12:36 PM
redirecting video output to OLED display ravi_chobey Linux - Embedded & Single-board computer 1 12-27-2009 10:06 AM
LXer: Linux barcode scanner uses OLED display LXer Syndicated Linux News 0 11-14-2008 06:10 PM
display in hex + perl + non ASCII characters kshkid Programming 4 02-06-2007 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 02:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration