标签:utf-8 rar nes pes dev create text inf fill
1接线
GND | 任意一个0v |
VCC | 任意一个5v/3.3v |
D0(SCLK) | 23号物理接口 |
D1(MOSI) | 19号物理接口 |
RST | 11号物理接口 |
DC(数据与命令选择) | 13号物理接口 |
CS(SPI 片选) | 24号物理接口 |
2,代码
#!/usr/bin/python/ # coding: utf-8 import time import Adafruit_GPIO.SPI as SPI import Adafruit_SSD1306 import PIL.Image import PIL.ImageDraw import PIL.ImageFont # Raspberry Pi pin configuration: RST = 17 # Note the following are only used with SPI: DC = 27 SPI_PORT = 0 SPI_DEVICE = 0 # 128x64 display with hardware SPI: disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000)) # Initialize library. disp.begin() # Clear display. disp.clear() disp.display() # Create blank image for drawing. Make sure to create image with mode # ‘1‘ for 1-bit color. width = disp.width height = disp.height image = PIL.Image.new(‘1‘,(width, height)) # Get drawing object to draw on image. draw = PIL.ImageDraw.Draw(image) # Draw a black filled box to clear the image. draw.rectangle((0,0,width,height), outline=0, fill=0) # Draw some shapes. First define some constants to allow easy # resizing of shapes. padding = 1 top = padding x = padding # Load default font. font = PIL.ImageFont.load_default() # Alternatively load a TTF font. Some other nice fonts to try: # http://www.dafont.com/bitmap.php #font = ImageFont.truetype(‘Minecraftia.ttf‘, 8) Write two lines of # text. draw.text((x, top), ‘This is first line‘, font=font, fill=255) draw.text((x, top+10), ‘This is second line‘, font=font, fill=255) draw.text((x, top+20), ‘This is third line‘, font=font, fill=255) draw.text((x, top+30), ‘This is fourth line‘, font=font, fill=255) draw.text((x, top+40), ‘This is fifth line‘, font=font, fill=255) draw.text((x, top+50), ‘This is last line‘, font=font, fill=255) # Display image. disp.image(image) disp.display()
若遇到没有module,自行安装
标签:utf-8 rar nes pes dev create text inf fill
原文地址:https://www.cnblogs.com/go4mi/p/11610475.html