def page1():  # function "page number 1"
    IP = executCMD("hostname -I | cut -d\' \' -f1 | head --bytes -1"
                   )  # IP address banging command
    Disk = executCMD("df -h | awk '$NF==\"/\"{printf \"%s\", $5}'"
                     )  # disk bump command (busy)
    Temperature = executCMD(
        "cat /sys/class/thermal/thermal_zone0/temp | cut -c 1-2"
    )  # CPU temperature bump command

    with canvas(device) as draw:
        draw.text((1, 0), strftime('%H:%M:%S'), font=font_ra,
                  fill=255)  # output time (Hour: Minute: Second)
        draw.text((71, 0), strftime('%d.%m.%y'), font=font_ra,
                  fill=255)  # output date (Number: Month: Year)
        draw.text((1, 15), ("lan :"), font=font_ra10,
                  fill=255)  # output of the word "lan"
        draw.text((30, 15), str(IP), font=font_ra10,
                  fill=255)  # output IP address
        draw.text((1, 28), ("cpu : "), font=font_ra10,
                  fill=255)  # output of the word "cpu"
        draw.text((33, 28), str(Temperature), font=font_ra10,
                  fill=255)  # CPU temperature output
        draw.text((46, 28), chr(176) + "C", font=font_ra10,
                  fill=255)  # degree icon"
        draw.text((63, 28), ("hdd :"), font=font_ra10,
                  fill=255)  # output word "hdd"
        draw.text((94, 28), str(Disk), font=font_ra10,
                  fill=255)  # output percent disk usage
        draw.line((0, 43, 128, 43), fill="white")  # just line
        draw.text((0, 42),
                  unicode("Люблю Юленьку!", 'utf-8'),
                  font=font_ra16,
                  fill=255)  # so that the wife does not grumble :)
def page2():  # function "page number 2"
    temperature, pressure, humidity = bme280.readBME280All(
    )  # weather sensor initialization
    IP = executCMD("hostname -I | cut -d\' \' -f1 | head --bytes -1"
                   )  # IP address banging command

    with canvas(device) as draw:
        draw.text((0, 0), ("MSK"), font=font_ra,
                  fill=255)  # output of the word "MSK"
        draw.text((40, 0), strftime('%H : %M : %S'), font=font_ra,
                  fill=255)  # output time (Hour: Minute: Second)
        draw.text((0, 16), unicode("Дата", 'utf-8'), font=font_ra,
                  fill=255)  # output of the word "Date"
        draw.text((40, 16), strftime('%d . %m . %y'), font=font_ra,
                  fill=255)  # output date (Number: Month: Year)
        draw.text((0, 33), unichr(61931), font=font2, fill=255)  # Wi fi icon
        draw.text((40, 33), str(IP), font=font_ra,
                  fill=255)  # output IP address
        draw.text((0, 50), str(int(humidity)) + "%", font=font_ra,
                  fill=255)  # moisture output
        draw.text((30, 50),
                  str(int((pressure) * 0.750062)) + "mm",
                  font=font_ra,
                  fill=255)  # pressure output in mm
        draw.text((80, 50),
                  str(int(temperature)) + unichr(176),
                  font=font_ra,
                  fill=255)  # temperature output + degree icon
def page3():  # function "page number 3"
    with canvas(device) as draw:
        draw.text((0, 0),
                  unicode("Широта: " + format(agps_thread.data_stream.lat)[:7],
                          'utf-8'),
                  font=font_ra,
                  fill=255)  # Latitude values (lat) (RUS simbol)
        draw.text(
            (0, 16),
            unicode("Долгота: " + format(agps_thread.data_stream.lon)[:7],
                    'utf-8'),
            font=font_ra,
            fill=255)  # Longitude values (lon) (RUS simbol)
        draw.text(
            (0, 33),
            unicode("Скорость: " + format(agps_thread.data_stream.speed)[:3],
                    'utf-8'),
            font=font_ra,
            fill=255)  # Speed values (RUS simbol)
        draw.text((0, 50),
                  str("Course: ") +
                  (format(agps_thread.data_stream.track)[:3]) + unichr(176),
                  font=font_ra,
                  fill=255)  # Course values
Example #4
0
import lcd_driver2
from render import canvas
from PIL import ImageFont
from time import sleep

device = ssd1306(port=1, address=0x3C)  # for RPi rev 2 port(smbus) = 1
font = ImageFont.load_default()

with canvas(device) as draw:
    draw.text((10, 0), "*** Hello World ***", font=font, fill=255)
    draw.text((20, 30), "Hello World! :)", font=font, fill=255)

sleep(3)  # Wait 3 seconds.
device.command(0xAE)  # Display OFF.
sleep(1)  # Wait 1 second.
device.command(0xAF)  # Display ON.
sleep(1)
device.command(0xAE)
sleep(1)
device.command(0xAF)