Page 1 of 1

Bakebit and UTF (non ASCII) characters

Posted: Thu Oct 17, 2019 4:35 pm
by mackowiakp
Bakebit OLED display was originally included in Friendly ARM Linux distro for NANO Pi.
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: Select all

#!/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
global height

# Reset OLED display
GPIO.setup(37, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.OUT)
GPIO.output(24, True)
GPIO.output(24, False)
GPIO.output(24, True)
# End RESET display
oled.init()  #initialze SEEED OLED display
oled.setNormalDisplay()      #Set display to normal mode (i.e non-inverse mode)

global image
image ='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)
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)
draw.rectangle((0,0,width,height), outline=0, fill=0)

This code works OK. But if I change any letter to other non-ASCII but included in DejaVuSansMono, 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.