溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何使用樹莓源驅(qū)動(dòng)128*128彩屏SSD1351

發(fā)布時(shí)間:2021-12-29 17:58:23 來源:億速云 閱讀:150 作者:小新 欄目:互聯(lián)網(wǎng)科技

小編給大家分享一下如何使用樹莓源驅(qū)動(dòng)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庫的則按下面對(duì)應(yīng)的Python3版本修改上面的命令進(jìn)行安裝。

pip ? pip3
python ? python3
python-dev ? python3-dev
python-pip ? python3-pip

如果安裝Luma.oled庫時(shí)出現(xiàn)紅字錯(cuò)誤,請(qǐng)繼續(xù)執(zhí)行命令重試,那是因?yàn)榫W(wǎng)絡(luò)問題下載一個(gè)叫Pillow的庫不成功。

2 連接顯示屏和Pi

按照如下配置進(jìn)行端口的連接,樹莓源的端口信息可以到如下網(wǎng)址查看https://pinout.xyz/pinout/spi
如何使用樹莓源驅(qū)動(dòng)128*128彩屏SSD1351

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, 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

主要是導(dǎo)入ssd1351,并將device調(diào)整為ssd1351. 顯示效果如下:

如何使用樹莓源驅(qū)動(dòng)128*128彩屏SSD1351

以上是“如何使用樹莓源驅(qū)動(dòng)128*128彩屏SSD1351”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI