树莓派:两个OELD屏幕驱动(tca9548a)

一、硬件连接


树莓派                         tca9548a I2C扩展板
SDA1--------------------------->    SDA
SCL1--------------------------->    SCL

 

两个OLED屏幕的SAD和SCL分别接在  tca9548a的SD2、SC2 和 SD3、SC3  (可以任意)

 

二、程序

from Adafruit_GPIO import I2C
import Adafruit_SSD1306

from PIL import ImageDraw
from PIL import Image
from PIL import ImageFont

# tca9548a 驱动函数
tca = I2C.get_i2c_device(address=0x70)


def tca_select(channel):
    """Select an individual channel."""
    if channel > 7:
        return
    tca.writeRaw8(1 << channel)


def tca_set(mask):
    """Select one or more channels.
           chan =   76543210
           mask = 0b00000000
    """
    if mask > 0xff:
        return
    tca.writeRaw8(mask)

#############################################################################

font = ImageFont.truetype('/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf',23)

# 选择通道2的OLED屏幕
tca_select(2)
disp_1 = Adafruit_SSD1306.SSD1306_128_64(rst=24)
disp_1.begin()
disp_1.clear()
disp_1.display()

width = disp_1.width
height = disp_1.height
imgae = Image.new('1',(width,height))

draw = ImageDraw.Draw(imgae)

draw.text((0,25),"hello world", font=font, fill=255)

disp_1.image(imgae)
disp_1.display()

##############################################################
# 选择通道3的OLED屏幕
tca_select(3)
disp_2 = Adafruit_SSD1306.SSD1306_128_64(rst=24)
disp_2.begin()
disp_2.clear()
disp_2.display()


# 自己制作一张图片,图片大小必须是 128*64素数,最后转换成二值图片
imgae = Image.open("/home/pi/Desktop/ssh_test/TCA9548_multi_OLED/pai.png").convert('1')


draw = ImageDraw.Draw(imgae)

disp_2.image(imgae)
disp_2.display()

 

三、测试结果

 

树莓派LCD驱动/2.8/3.2/3.5/3.97/4.3/5/7等! You can focus on the following GitHub web site, for the latest lcd drivers: https://github.com/goodtft/LCD-show =============================================================================================================== "LCD-show-170315.tar.gz" just for Raspbian (Release date:2017-03-02) or later, DO NOT use it for the Raspbian version before 2017-03-02. ================================================================================================================ "LCD-show-160701.tar.gz" support Raspbian version before Raspbian-2017-02-16,such as(2017-02-16,2017-01-11, 2016-11-25,2016-09-23,2016-05-27,2016-05-10,2016-03-18,or earlier). And This Driver also tesed on "kali-2.1.2" ,"ubuntu-mate-16.04-beta2" ================================================================================================================ How to Install: 1.)Step1, Install Raspbian official mirror a)Download Raspbian official mirror: https://www.raspberrypi.org/downloads/ b)Use“SDFormatter.exe”to Format your TF Card c)Use“Win32DiskImager.exe” Burning mirror to TF Card 2.) Step2, Clone my repo onto your pi git clone https://github.com/goodtft/LCD-show.git chmod -R 755 LCD-show cd LCD-show/ 3.)Step3, According to your LCD's type, excute: In case of 2.8" LCD sudo ./LCD28-show In case of 3.2" LCD sudo ./LCD32-show In case of 3.5" LCD sudo ./LCD35-show In case of 3.97" LCD sudo ./LCD397-show In case of 4.3" LCD sudo ./LCD43-show In case of 5" LCD sudo ./LCD5-show In case of 7inch(B)-800X480 RPI LCD sudo ./LCD7B-show In case of 7inch(C)-1024X600 RPI LCD sudo ./LCD7C-show If you need to switch back to the traditional HDMI display sudo ./LCD-hdmi Wait a few minutes,the system will restart automaticall , enjoy with your LCD.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值