Template: RPi User Guides for 4.2inch e-Paper Cloud
Using Guides for RPI
Install Libraries
#python3 sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-tqdm sudo apt-get install python3-numpy sudo apt-get install python3-progressbar
Download the demo codes
Open a terminal and runthe following commands:
sudo apt-get install p7zip-full sudo wget https://files.waveshare.com/upload/2/2e/Cloud_RPI.7z 7z x Cloud_RPI.7z cd Cloud_RPI
python
- The demo codes can only support python3.
- Please go to the directory of Cloud_RPI and run the command:
#This code is used to climb the picture of the Waveshare website and transmit the image data to the slave device. sudo python3 ./examples/display_WS.py #The codes will draw figures and send the image data to the slave device. sudo python3 ./examples/display_EPD.py
API Description
There are three directories in lib,http_get, tcp_server和waveshare_epd, They are used to climb HTTP pictures, TCP service, and the functions of e-Paper.
tcp_sver.py
Path: Cloud_RPI/lib/tcp_server
Create a tcp_server class in the tcp_sver.py file. You need to inherit the class and refactor the handle function when using.
def handle(self)
Every time a new client is connected, it should call the handle function.
Receive Message
def Get_msg(self)
Command | Return |
---|---|
'$'+Data+'#' | Data |
Send Command
def Send_cmd(self,cmd)
Parameter cmd is the command sent.
Command | |
---|---|
cmd | ‘;’+cmd+'/'+Parity |
Sent data
def Send_data(self,data)
The parameter data is a message transmitted (including address and lenghta nd so on) data.
Command | |
---|---|
data | 0x57+data+ Parity |
Set size
def set_size(self,w,h)
w: The width of the image; h: The height of the image.
Take bicolor e-Paper as an example, 1 bit stands for one pixel, then you get.
Len of data=Width of image(w)*Height of image(h)/8 |
---|
Refer to 4.2inch e-Paper Module
Update function
def flush_buffer(self,DATA)
DATA; The image data. the image data can be get by the getbuffer function.
Parameter | Send times | Length of every frame(len) | Content | DATA(Image data) | Total length of image data/length of singal frame(len) | 1024 Byte(Configurable) | 0x57+4 Byte addr+ 4 Byte len +1 Byte num + len Byte data+Parity |
---|
The length of signal transmission should less than 1100 Byte, or it will cause data loss.
Check voltage of battery
- Get the current voltage.
def check_batter(self)
Power Off Function
- Power off or low power state.
def Shutdown(self)
http_get.py
Path:Cloud_RPI/lib/http_get
- Download picture
def Get_PNG(Url,Name)
This function is used to download the picture from Url and save it to the current directory with Name
epd4in2.py
Path:Cloud_RPI/lib/waveshare_epd
- Convert the picture to image data.
def getbuffer(self, image):
Directory: Cloud_RPI/lib/waveshare_epd
Convert image information to queue
def getbuffer(self, image):