一、硬件连接
树莓派 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()
三、测试结果