Comment changer la taille ( size ) des caractères sur un afficheur oled: 

 

#
import ssd1306
from machine import Pin,SoftI2C
from time import  sleep_ms,sleep

import urequests
def getLib(name):
    fichier = name+".py"
    get_lib = "http://217.182.207.90/ota1/writer/"+fichier
    reponse = urequests.get(get_lib)
    f = open(fichier,"w")
    f.write(reponse.text)
    f.flush()
    f.close


import utime
import uos
try:
    from writer import Writer, CWriter
except:
    getLib("writer")

try:
    from writer_gui import Label, Meter
except:
    getLib("writer_gui")

# Font
try:
    import freesans20
except:
    getLib("freesans20")

try:
    import courier20 as fixed
except:
    getLib("courier20")

try:
    import font6 as small
except:
    getLib("font6")

try:
    import arial10
except:
    getLib("arial10")

WIDTH=128
HEIGHT=64


# Heltec LoRa 32 with OLED Display
oled_width = 128
oled_height = 64

# OLED reset pin
i2c_rst = Pin(16, Pin.OUT)

#Initialize the OLED display
i2c_rst.value(0)
sleep_ms(5)
i2c_rst.value(1) # must be held high after initialization

# Setup the I2C lines
i2c_scl = Pin(15, Pin.OUT, Pin.PULL_UP)
i2c_sda = Pin(4, Pin.OUT, Pin.PULL_UP)
# Create the bus object
i2c = SoftI2C(scl=i2c_scl, sda=i2c_sda)

# Create the display object
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

def test(ssd):
    rhs = WIDTH -1
    ssd.line(rhs - 20, 0, rhs, 20, 1)
    square_side = 10
    ssd.fill_rect(rhs - square_side, 0, square_side, square_side, 1)

    wri = Writer(ssd, freesans20)
    Writer.set_textpos(ssd, 0, 0)  # verbose = False to suppress console output
    wri.printstring('Sunday\n')
    wri.printstring('12 Aug 2018\n')
    wri.printstring('10.30am')
    ssd.show()
    
test(oled)
sleep(3)

def inverse(ssd):
    rhs = WIDTH -1
    ssd.line(rhs - 20, 0, rhs, 20, 1)
    square_side = 10
    ssd.fill_rect(rhs - square_side, 0, square_side, square_side, 1)

    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, freesans20, verbose=False)
    wri.set_clip(False, False, False)  # Char wrap
    wri.printstring('Sunday\n')
    wri.printstring('12 Aug 2018\n')
    wri.printstring('10.30am', True)  # Inverse text
    ssd.show()

#inverse(oled)
#sleep(3)


def scroll(ssd):
    rhs = WIDTH -1
    ssd.line(rhs - 20, 0, rhs, 20, 1)
    square_side = 10
    ssd.fill_rect(rhs - square_side, 0, square_side, square_side, 1)

    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, freesans20, verbose=False)
    wri.set_clip(False, False, False)  # Char wrap
    wri.printstring('Sunday\n')
    wri.printstring('12 Aug 2018\n')
    wri.printstring('10.30am')
    for x in range(5):
        ssd.show()
        utime.sleep(2)
        wri.printstring('\nCount = {:2d}'.format(x))
    ssd.show()
    utime.sleep(2)
    wri.printstring('\nDone.')
    ssd.show()

#scroll(oled)
#sleep(3)

def rjust(ssd):
    Writer.set_textpos(ssd, 0, 0)  # Previous tests may have altered it
    wri = Writer(ssd, freesans20, verbose=False)
    wri.set_clip(False, False, False)  # Char wrap

    my_str = 'Sunday\n'
    l = wri.stringlen(my_str)
    Writer.set_textpos(ssd, col = WIDTH - l)
    wri.printstring(my_str)

    my_str = '12 Aug 2018\n'
    l = wri.stringlen(my_str)
    Writer.set_textpos(ssd, col = WIDTH - l)
    wri.printstring(my_str)

    my_str = '10.30am'
    l = wri.stringlen(my_str)
    Writer.set_textpos(ssd, col = WIDTH - l)
    wri.printstring(my_str)
    ssd.show()

#rjust(oled)
#sleep(3)

def fonts(ssd):
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, freesans20, verbose=False)
    wri.set_clip(False, False, False)  # Char wrap
    wri_f = Writer(ssd, small, verbose=False)
    wri_f.set_clip(False, False, False)  # Char wrap
    wri_f.printstring('Sunday\n')
    wri.printstring('12 Aug 2018\n')
    wri.printstring('10.30am')
    ssd.show()

fonts(oled)
sleep(3)

def tabs(ssd):
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, fixed, verbose=False)
    wri.set_clip(False, False, False)  # Char wrap
    wri.printstring('1\t2\n')
    wri.printstring('111\t22\n')
    wri.printstring('1111\t1')
    ssd.show()

tabs(oled)
sleep(3)

def wrap(ssd):
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, freesans20, verbose=False)
    wri.set_clip(False, False, True)  # Word wrap
    wri.printstring('the quick    brown fox jumps over')
    ssd.show()


#wrap(oled)
#sleep(3)

 

Source : https://github.com/peterhinch/micropython-font-to-py/blob/master/writer/WRITER.md

 

En poursuivant votre navigation sur mon site, vous acceptez l’utilisation des Cookies et autres traceurs  pour réaliser des statistiques de visites et enregistrer sur votre machine vos activités pédagogiques. En savoir plus.