小编给大家分享一下如何使用树莓源驱动128*128彩屏SSD1351,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
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的库不成功。
按照如下配置进行端口的连接,树莓源的端口信息可以到如下网址查看https://pinout.xyz/pinout/spi
下载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, sh2106, 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. 显示效果如下:
以上是“如何使用树莓源驱动128*128彩屏SSD1351”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。