千家信息网

如何使用树莓源驱动128*128彩屏SSD1351

发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,小编给大家分享一下如何使用树莓源驱动128*128彩屏SSD1351,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!1 安装
千家信息网最后更新 2025年02月04日如何使用树莓源驱动128*128彩屏SSD1351

小编给大家分享一下如何使用树莓源驱动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.pathfrom demo_opts import get_devicefrom PIL import Image, ImageSequencefrom luma.core.sprite_system import framerate_regulatordef 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 timeimport os.pathfrom demo_opts import get_devicefrom PIL import Image, ImageSequencefrom luma.core.sprite_system import framerate_regulatorfrom luma.core.interface.serial import i2c, spifrom luma.oled.device import ssd1306, ssd1325, ssd1331, sh2106, ssd1351def 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. 显示效果如下:

以上是"如何使用树莓源驱动128*128彩屏SSD1351"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0