PIL库不适用于SSD1306屏幕

时间:2019-04-26 15:19:38

标签: raspberry-pi python-imaging-library adafruit

PIL librarie不适用于ssd1306屏幕。我尝试显示一些文本,当我想刷新它时,新文本写在前一个文本上方。

我正在使用PIL,它是PILLOW的一个分支

目前,我只想在i2c中获取一个字节并将其写入屏幕上

提前谢谢!

我尝试使用以下方法:https://pillow.readthedocs.io/en/3.1.x/reference/Image.html 例如,我尝试绘制一个矩形: 矩形= ImageDraw.Draw.rectangle([40,50,50,60],白色,黑色) 但是lib并不知道“矩形” ...

import smbus
import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306

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

RST = 0

#Creation of a display object. We don't need to put its i2c addr
#because it's known and static
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

#Remplacer 0 par 1 si nouveau Raspberry
bus = smbus.SMBus(1)
address = 0x27

disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

bus = smbus.SMBus(1)
address = 0x27

disp.begin()
disp.clear()
disp.display()

width = disp.width
height = disp.height
image = Image.new('1', (width, height))
rect_image = Image.new('1', (width, height))

#Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
rectangle = ImageDraw.Draw.rectangle([40, 50, 50, 60], WHITE, BLACK)
#Select the font
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 20)

#Draw some text 
draw.text((0,0), 'Master fader', font=font, fill=255)
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 22)
draw.text((50,40), '50%', font=font, fill=255)

#Actualise l'affichage - Update display
disp.image(image)
disp.display()
disp.clear();

#Send datas
while 1:
    reponse = bus.read_byte(address)

        print "ADC value :", reponse

        disp.image(rect_image)

        disp.display()

        draw.text((50,40), str(reponse) + " %", font=font, fill=255)

        disp.image(image)

        disp.display()

当我尝试运行代码时:

回溯(最近通话最近):   在第34行的文件“ i2c_attiny_send_and_receive_with_screen.py”     矩形= ImageDraw.Draw.rectangle([40,50,50,60],白色,黑色) AttributeError:“函数”对象没有属性“矩形”

0 个答案:

没有答案