♞树莓派之安装墨水屏
2019-09-26-raspbian-buster-lite.img
墨水屏采用的是微雪电子的2.13inch e-Paper HAT型号,是带板黑白版的,支持局部刷新(如下图所示)

硬件连接
| e-Paper | Raspberry Pi | |
| BCM2835编码 | Board物理引脚序号 | |
| VCC | 3.3V | 3.3V |
| GND | GND | GND |
| DIN | MOSI | 19 |
| CLK | SCLK | 23 |
| CS | CE0 | 24 |
| DC | 25 | 22 |
| RST | 17 | 11 |
| BUSY | 24 | 18 |
前期准备工作
#升级系统 sudo apt-get update sudo apt-get upgrade #开启SPI接口 sudo raspi-config 选择Interfacing Options -> SPI -> Yes 开启SPI接口 sudo reboot sudo apt-get install git
安装Python及函数库
sudo apt-get update sudo apt-get install python-pip sudo apt-get install python-pil sudo apt-get install python-numpy sudo pip install RPi.GPIO sudo pip install spidev
sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-numpy sudo pip3 install RPi.GPIO sudo pip3 install spidev
sudo git clone https://github.com/waveshare/e-Paper cd e-Paper/RaspberryPi\&JetsonNano/python/examples sudo python3 epd_2in13_V3_test.py
#exit 0前插入 su pi -c "python3 /home/pi/e-Paper/RaspberryPi\&JetsonNano/python/examples/view_ip.py"
#!/usr/bin/python
# -*- coding:utf-8 -*-
#250*122
import sys
import os
import socket
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
from waveshare_epd import epd2in13_V2
import time,datetime
from PIL import Image,ImageDraw,ImageFont
import traceback
logging.basicConfig(level=logging.DEBUG)
try:
# Drawing on the image
fonta = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 14)
fontb = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
# # partial update
logging.info("1.show IP Address")
epd = epd2in13_V2.EPD()
view_ip_w = Image.new('1', (epd.height, epd.width), 255)
view_ip = ImageDraw.Draw(view_ip_w)
eth0_status=os.popen("ethtool eth0 |grep \"Link detected:\"").readline().split(":")[1].replace("\n"," ").strip()
#print(eth0_status)
if eth0_status == "yes":
#提取IP地址
#s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#s.connect(('1.1.1.1',80))
#ip_address =s.getsockname()[0]
#s.close()
ip_address=os.popen("ifconfig eth0 |grep \"inet \"").readline().strip().split(" ")[1]
else:
ip_address="未联接有线网络"
ff=open("/etc/hostapd/hostapd.conf","rt")
fff=ff.readlines()
wifi_ssid=fff[1].split("=")[1]
wifi_pass=fff[7].split("=")[1]
ff.close()
del fff
start_date="本次开机时间:"+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
view_ip.text((10, 5), u'东港市黑马网络科技有限公司', font = fontb, fill = 0)
view_ip.line([(0,30),(250,30)], fill = 0,width = 2)
view_ip.line([(0,55),(250,55)], fill = 0,width = 1)
view_ip.text((0,35), u"有线访问地址:"+ip_address, font = fonta, fill = 0)
view_ip.text((0,59), u"无线访问地址:192.168.66.1", font = fonta, fill = 0)
view_ip.line([(0,80),(250,80)], fill = 0,width = 2)
view_ip.text((0,82),u'热点',font=fonta,fill=0)
view_ip.line([(35,80),(35,100)], fill = 0,width = 1)
view_ip.line([(125,80),(125,100)],fill=0,width=1)
view_ip.text((40,82),wifi_ssid,font=fonta,fill=0)
view_ip.text((130,82),wifi_pass,font=fonta,fill=0)
view_ip.line([(0,100),(250,100)], fill = 0,width = 2)
view_ip.text((0,104),start_date,font=fonta,fill=0)
epd.init(epd.FULL_UPDATE)
epd.displayPartBaseImage(epd.getbuffer(view_ip_w))
#epd.init(epd.PART_UPDATE)
#epd.displayPartial(epd.getbuffer(view_ip_w))
#epd.display(epd.getbuffer(view_ip_w))
#logging.info("Clear...")
#epd.init(epd.FULL_UPDATE)
#epd.Clear(0xFF)
logging.info("Goto Sleep...")
epd.sleep()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd2in13_V2.epdconfig.module_exit()
exit()
阅读剩余
版权声明:
作者:Mr.x
链接:http://www.x1985.org/?p=672
文章版权归作者所有,未经允许请勿转载。
THE END