LinuxQuestions.org
Review your favorite Linux distribution.
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, 12:51 PM   #1
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 198

Rep: Reputation: 5
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 12:54 PM.
 
Old 10-22-2019, 12:27 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 10,658

Rep: Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182
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, 01:44 PM   #3
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 198

Original Poster
Rep: Reputation: 5
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, 06:03 AM   #4
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 10,658

Rep: Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182
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, 04:27 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,793
Blog Entries: 9

Rep: Reputation: 3491Reputation: 3491Reputation: 3491Reputation: 3491Reputation: 3491Reputation: 3491Reputation: 3491Reputation: 3491Reputation: 3491Reputation: 3491Reputation: 3491
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, 01:08 AM   #6
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 198

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 04:38 AM
Rant about non ascii characters disappearing when using the non advanced editor Didier Spaier LQ Suggestions & Feedback 1 02-08-2016 01:36 PM
redirecting video output to OLED display ravi_chobey Linux - Embedded & Single-board computer 1 12-27-2009 11:06 AM
LXer: Linux barcode scanner uses OLED display LXer Syndicated Linux News 0 11-14-2008 07:10 PM
display in hex + perl + non ASCII characters kshkid Programming 4 02-06-2007 05:48 PM

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

All times are GMT -5. The time now is 01:25 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration