OLED 1.12" SPi - text size

I’ve got OLED 1.12" and BME280 in a breakout garden on a Pi3a.

All good, with the BME280 temp reading on the OLED.

But, it’s such tiny text, how on earth do you get a larger size displayed?
I tried changing SINCLAIR_FONT to LCD_FONT, but no change. I can’t see where you change text size.

And how do you prevent it from scrolling?

Thanks!

On my Pi 400, I have two of the SPI Color LCD Breakouts.
In my PY file I have the following.

from PIL import ImageFont
from fonts.ttf import RobotoMedium as UserFont

# Fonts
font_sm = ImageFont.truetype(UserFont, 35)
font_md = ImageFont.truetype(UserFont, 50)
font_lg = ImageFont.truetype(UserFont, 55)

then I do a
draw.text((40, 120), ("CPU Usage"), font=font_sm, fill=colour)

Fonts installed OK

show_message(device, str(t), fill="white", font=font_lg)

Gives me an error: TypeError: ‘FreeTypeFont’ object is not subscriptable
(and also with font small and font medium)

It may help to know that the script is launched from terminal like this:

python3 all-values-3.py --display sh1106 --height 128 --rotate 2 --interface spi --gpio-data-command 9 --spi-device 1

This is above my skill level I’m afraid. The code I posted above isn’t my creation. Just something I new I had on hand, and had used. I don’t know what that error message means.

This is the full file that I’m using on my Pi 400, dual color SPI LCD’s.

#!/usr/bin/env python3

import os
import sys
import time
import datetime
import ST7789
import psutil

from trackball import TrackBall
trackball = TrackBall(interrupt_pin=4)

from os import popen

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from fonts.ttf import RobotoMedium as UserFont

# Fonts
font_sm = ImageFont.truetype(UserFont, 35)
font_md = ImageFont.truetype(UserFont, 50)
font_lg = ImageFont.truetype(UserFont, 55)

# Initialise the left LCD
disp_left = ST7789.ST7789(
    port=0,
    cs=0,
    dc=9,
    #backlight=19,
    rotation=90,
    spi_speed_hz=80 * 1000 * 1000,
)

disp_left.begin()

# Initialise the right LCD
disp_right = ST7789.ST7789(
    port=0,
    cs=1,
    dc=9,
    #backlight=19,
    rotation=90,
    spi_speed_hz=80 * 1000 * 1000,
)

disp_right.begin()

WIDTH = 240
HEIGHT = 240
img = Image.new('RGB', (WIDTH, HEIGHT), color=(255, 0, 0))
draw = ImageDraw.Draw(img)

def get_cpu_temp():
    with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
        temp = f.read()
        temp = int(temp) / 1000.0
    return temp

cpu_temps = [get_cpu_temp()] * 5
colour = (255, 255, 255)

while True:
    
    img = Image.new('RGB', (WIDTH, HEIGHT), color=(255, 0, 0))
    draw = ImageDraw.Draw(img)

    now = datetime.datetime.now()
    date_string = now.strftime("%b %-d")
    draw.text((60, 15), date_string, font=font_sm, fill=colour)
        
    time_string = now.strftime("%-I:%M%p")
    draw.text((20, 60), time_string, font=font_md, fill=colour)
    
    draw.text((40, 120), ("CPU Temp"), font=font_sm, fill=colour)
    cpu_temp = get_cpu_temp()
    temp_string = f"{cpu_temp:.0f}°C"       
    draw.text((60, 160), temp_string, font=font_lg, fill=colour)
        
    disp_left.display(img)
    
    img = Image.new('RGB', (WIDTH, HEIGHT), color=(255, 0, 0))
    draw = ImageDraw.Draw(img)
    
    draw.text((40, 15), ("CPU Speed"), font=font_sm, fill=colour)
    str=popen("vcgencmd measure_clock arm").read()
    str = str[str.find("=")+1:-7]
    freq_string = f"{str}mhz"       
    draw.text((5, 55), freq_string, font=font_lg, fill=colour)
    
    draw.text((40, 120), ("CPU Usage"), font=font_sm, fill=colour)
    str = psutil.cpu_percent()
    usage_string = f"{str}%"       
    draw.text((55, 160), usage_string, font=font_lg, fill=colour)
    
    
    disp_right.display(img) 
    
    trackball.set_rgbw(255, 70, 0, 0)
    
    time.sleep(1)
'''
 sudp pip3 install st7789
 sudo pip3 install fonts
 sudo pip3 install font-roboto
 run crontab -e
 add
 @reboot python3 /home/pi/pi-info.py  
'''    
    

Thanks, but sadly yours is just too different to mine.
Hopefully someone with the same (monochrome 1.12" OLED SPI) device will come along and be able to help. :-/

The only OLED I have in use, is an i2c variant, and using Micro Python (Pimoroni Pico Graphics).

This one is on a Pi 3a via breakout garden

My .py. All good except the output being too small and scrolling away!

#!/usr/bin/env python

###  python3 all-values-3.py --display sh1106 --height 128 --rotate 2 --interface spi --gpio-data-command 9 --spi-device 1 


import time
import datetime

try:
    from smbus2 import SMBus
except ImportError:
    from smbus import SMBus
from bme280 import BME280

import sys
import time

from demo_opts import get_device
from luma.core.legacy import show_message   ### Where is luma.core.legacy ?
from luma.core.legacy.font import proportional, tolerant, LCD_FONT, ATARI_FONT



# Initialise the BME280
bus = SMBus(1)
bme280 = BME280(i2c_dev=bus)
temperature = bme280.get_temperature()
print("Initial junk reading, ignore: " + str(temperature))
print("Short pause to stabalise sensor....")
time.sleep(0.5)
print("OK! Here we go.")
print(" ")



while True:
    now = datetime.datetime.now()
    timestamp = str(now.strftime("%Y%m%d  %H-%M-%S "))    
    temperature = bme280.get_temperature()  
    t = "{:0.2f} C".format(temperature)  
    #print (t)
    pressure = bme280.get_pressure()
    humidity = bme280.get_humidity()
    device = get_device()
    #print(device)
    show_message(device, str(t), fill="white", font=proportional(LCD_FONT)) #### Bigger font! & Stop scrolling! ####

    print((str(now.strftime("%d-%b %H-%M-%S ") +" Dungeon temperature: " + '{:05.2f}*C {:05.2f}hPa {:05.2f}%'.format(temperature, pressure, humidity))))
    time.sleep(10)   ### Slow this down when working properly!


# Launch from terminal with
# pi@pi-3a-tester:~/luma.examples/examples $ python3 all-values-3.py 
# --display sh1106 
# --height 128 
# --rotate 2 
# --interface spi 
# --gpio-data-command 9 
# --spi-device 1

I have a ton of Breakout Garden stuff on the go here, Pi and Pico. I only just recently tried an OLED. I went i2c because it made it easier to hook it up to my Inventor 2040W. If SPI had been an option I would have went SPI Color LCD.

I don’t have anything on hand to try your code on, or I would.