樹莓派4驅動7針12864


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,自行安裝


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM