# OLED 1.12" SPi - text size

**URL:** https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485
**Category:** Support
**Created:** [December 11, 2023, 4:34pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485 "2023-12-11T16:34:47Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Richard238](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard238](https://forums.pimoroni.com/u/Richard238)
#### Post date: [December 11, 2023, 4:34pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/1 "2023-12-11T16:34:47Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [December 11, 2023, 6:04pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/2 "2023-12-11T18:04:51Z")

</div>

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

```auto
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)`

---

<div class="post-metadata">

### Author: ![Richard238](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard238](https://forums.pimoroni.com/u/Richard238)
#### Post date: [December 15, 2023, 4:33pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/3 "2023-12-15T16:33:58Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [December 15, 2023, 9:06pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/4 "2023-12-15T21:06:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [December 16, 2023, 10:02am UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/5 "2023-12-16T10:02:09Z")

</div>

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

```auto
#!/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  
'''    
    

```

---

<div class="post-metadata">

### Author: ![Richard238](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard238](https://forums.pimoroni.com/u/Richard238)
#### Post date: [December 16, 2023, 4:26pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/6 "2023-12-16T16:26:02Z")

</div>

> [@alphanumeric](#):
>
> ```auto
> 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)
> 
> ```

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. :-/

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [December 16, 2023, 4:34pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/7 "2023-12-16T16:34:55Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Richard238](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard238](https://forums.pimoroni.com/u/Richard238)
#### Post date: [December 16, 2023, 4:36pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/8 "2023-12-16T16:36:09Z")

</div>

This one is on a Pi 3a via breakout garden

---

<div class="post-metadata">

### Author: ![Richard238](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard238](https://forums.pimoroni.com/u/Richard238)
#### Post date: [December 16, 2023, 4:55pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/9 "2023-12-16T16:55:59Z")

</div>

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

```auto
#!/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

```

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [December 16, 2023, 5:11pm UTC](https://forums.pimoroni.com/t/oled-1-12-spi-text-size/23485/10 "2023-12-16T17:11:05Z")

</div>

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.
