Initial commit

main
commit c06fbfde4c

5
.gitignore vendored

@ -0,0 +1,5 @@
secrets.py
epd_4in2_test.py
__pycache__/
lib/
img/Font.ttc

@ -0,0 +1,24 @@
## dismyreadme
**Waveshare e-Paper repo: https://github.com/waveshare/e-Paper**
.gitignored files:
\- **secrets.py** - file containing two variables: octoprint & apikey. octoprint should be your octoprint server's IP address or domain name and apikey is your octoprint api key. Minimum permissions: guest.
\- **epd\_4in2\_test.py** - the demo file from waveshare, available on their github page.
\- **\_\_pycache\_\_/** - aint nobody got time for compiled python binaries.
\- **lib/** - library files from waveshare, available on their github page.
\- **img/Font.ttc** - font file provided by waveshare, available on their github page.
**ePaper Pins:**
Raspberry Pi
EPAPER 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

@ -0,0 +1,56 @@
https://www.waveshare.com/wiki/3inch_e-Paper_Module_(G)_Manual#Working_With_Raspberry_Pi
Install BCM2835
#Open the Raspberry Pi terminal and run the following command
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz
tar zxvf bcm2835-1.71.tar.gz
cd bcm2835-1.71/
sudo ./configure && sudo make && sudo make check && sudo make install
# For more information, please refer to the official website: http://www.airspayce.com/mikem/bcm2835/
Install WiringPi (Optional)
#Open the Raspberry Pi terminal and run the following command:
sudo apt-get install wiringpi
#For Raspberry Pi systems after May 2019 (earlier than before, you may not need to execute), you may need to upgrade:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
#Run gpio -v and version 2.52 will appear. If it does not appear, the installation is wrong.
#Bullseye branch system use the following command:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
./build
gpio -v
# Run gpio -v and version 2.60 will appear. If it does not appear, it means that there is an installation error.
Install the function library
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
Download the demo via GitHub (You can skip this step if you have downloaded it.)
git clone https://github.com/waveshare/e-Paper.git
cd e-Paper/RaspberryPi_JetsonNano/
# Raspberry Pi
# EPAPER 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

@ -0,0 +1,104 @@
#!/usr/bin/python3
# -*- coding:utf-8 -*-
# secrets.py:
# octoprint="https://your.octoprint.ip.address.or.domain.name"
# apikey="your-octoprint-api-key"
from secrets import *
pluginpath="plugin/DisplayLayerProgress/values"
fullurl=f"{octoprint}/{pluginpath}?apikey={apikey}"
# CODED FOR WAVESHARE 4.2" 400x300 B&W ePaper Display
# Requires the DisplayLayerProgress plugin
# https://github.com/OllisGit/OctoPrint-DisplayLayerProgress
import sys
import os
import json
import requests
imgdir = "/home/pi/epaper/img"#os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'img')#dontask
libdir = "/home/pi/epaper/lib"#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 epd4in2
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
# https://stackoverflow.com/a/32282390
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
logging.basicConfig(level=logging.DEBUG)
def getData():
jsondata=requests.get(fullurl, verify=False).json()
jobdata={
"file":jsondata["currentFilename"],
"layer":jsondata["layer"]["current"],
"layers":jsondata["layer"]["total"],
"lastlayertime":jsondata["layer"]["lastLayerDuration"],
"percent":jsondata["print"]["progress"],
"eta":jsondata["print"]["timeLeft"],
"remaining":jsondata["print"]["timeLeftInSeconds"] }
return jobdata
print(getData())
sys.exit(0)
try:
logging.info("Octopi print monitor starting...")
epd = epd4in2.EPD()
logging.info("init and Clear")
epd.init()
epd.Clear()
font18 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 18)
font24 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 24)
font35 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 35)
# Drawing on the Horizontal image
logging.info("1.Drawing on the Horizontal image...")
Himage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
draw = ImageDraw.Draw(Himage)
draw.text((10, 0), 'hello world', font = font24, fill = 0)
draw.text((10, 20), '4.2inch e-Paper', font = font24, fill = 0)
draw.text((150, 0), u'微雪电子', font = font24, fill = 0)
draw.line((20, 50, 70, 100), fill = 0)
draw.line((70, 50, 20, 100), fill = 0)
draw.rectangle((20, 50, 70, 100), outline = 0)
draw.line((165, 50, 165, 100), fill = 0)
draw.line((140, 75, 190, 75), fill = 0)
draw.arc((140, 50, 190, 100), 0, 360, fill = 0)
draw.rectangle((80, 50, 130, 100), fill = 0)
draw.chord((200, 50, 250, 100), 0, 360, fill = 0)
epd.display(epd.getbuffer(Himage))
time.sleep(2)
# logging.info("3.read bmp file")
# Himage = Image.open(os.path.join(imgdir, '4in2.bmp'))
# epd.display(epd.getbuffer(Himage))
# time.sleep(2)
# logging.info("4.read bmp file on window")
# Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
# bmp = Image.open(os.path.join(imgdir, '100x100.bmp'))
# Himage2.paste(bmp, (50,10))
# epd.display(epd.getbuffer(Himage2))
# time.sleep(2)
epd.Clear()
logging.info("Goto Sleep...")
epd.sleep()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd4in2.epdconfig.module_exit()
exit()
Loading…
Cancel
Save