树莓派4驱动7针12864

Posted go4mi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了树莓派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,自行安装

以上是关于树莓派4驱动7针12864的主要内容,如果未能解决你的问题,请参考以下文章

树莓派基于Linux内核驱动开发详解

树莓派进阶之路 (016) - 通过595驱动4位LED显示系统时间

python代码实现树莓派3b+驱动步进电机

Python驱动树莓派SPI接口

树莓派安装TPLINK_WN725n v2网卡驱动

树莓派400 ubuntu 20.10找不到无线网卡