使用树莓源驱动128*128彩屏(SSD1351)

1 安装Luma.oled库

sudo apt-get install python-dev python-pip libfreetype6-dev libjpeg-dev
sudo -H pip install --upgrade pip
sudo apt-get purge python-pip
sudo -H pip install --upgrade luma.oled

:如果你需要安装Python3的Luma.oled库的则按下面对应的Python3版本修改上面的命令进行安装。

pip ⇒ pip3
python ⇒ python3
python-dev ⇒ python3-dev
python-pip ⇒ python3-pip

如果安装Luma.oled库时出现红字错误,请继续执行命令重试,那是因为网络问题下载一个叫Pillow的库不成功。

2 连接显示屏和Pi

按照如下配置进行端口的连接,树莓源的端口信息可以到如下网址查看https://pinout.xyz/pinout/spi

3 修改代码

下载luma的示例代码https://github.com/rm-hull/luma.examples

我们以animated_gif.py为例,原始代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-18 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK

"""
Displays an animated gif.
"""

import os.path
from demo_opts import get_device
from PIL import Image, ImageSequence
from luma.core.sprite_system import framerate_regulator


def main():
    regulator = framerate_regulator(fps=10)
    img_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
        'images', 'banana.gif'))
    banana = Image.open(img_path)
    size = [min(*device.size)] * 2
    posn = ((device.width - size[0]) // 2, device.height - size[1])

    while True:
        for frame in ImageSequence.Iterator(banana):
            with regulator:
                background = Image.new("RGB", device.size, "white")
                background.paste(frame.resize(size, resample=Image.LANCZOS), posn)
                device.display(background.convert(device.mode))


if __name__ == "__main__":
    try:
        device = get_device()
        main()
    except KeyboardInterrupt:
        pass

修改后的代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-18 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK

"""
Displays an animated gif.
"""

import time
import os.path
from demo_opts import get_device
from PIL import Image, ImageSequence
from luma.core.sprite_system import framerate_regulator

from luma.core.interface.serial import i2c, spi
from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106, ssd1351

def main():
    regulator = framerate_regulator(fps=20)
    img_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
        'images', 'bq.gif'))
    banana = Image.open(img_path)
    #size = [min(*device.size)] * 2
    #posn = ((device.width - size[0]) // 2, device.height - size[1])
    size = [128, 128] 
    posn = (0, 0)

    while True:
        for frame in ImageSequence.Iterator(banana):
            with regulator:
                background = Image.new("RGB", device.size, "white")
                background.paste(frame.resize(size, resample=Image.LANCZOS), posn)
                device.display(background.convert(device.mode))
                time.sleep(0.05)


if __name__ == "__main__":
    try:
        #serial = i2c(port=1,address=0x3c) 
        serial = spi(device=0,port=0,bus_speed_hz=32000000)
        device = ssd1351(serial)
        #device = ssd1306(serial)
        main()
    except KeyboardInterrupt:
        pass

主要是导入ssd1351,并将device调整为ssd1351. 显示效果如下:

转载于:https://my.oschina.net/hechunc/blog/3020111

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值