您好,登錄后才能下訂單哦!
小編給大家分享一下如何使用樹莓源驅動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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。