Difference between revisions of "Template:Arduino Guides for SPI e-Paper"

From Waveshare Wiki
Jump to: navigation, search
 
(30 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
=User Guides of Arduino=
 
=User Guides of Arduino=
----
 
 
==Hardware connection==
 
==Hardware connection==
 
The demo codes provided are based on Arduino UNO. If you want to use another Arduino board, you may need to change the connection and port the codes by yourself.<br />
 
The demo codes provided are based on Arduino UNO. If you want to use another Arduino board, you may need to change the connection and port the codes by yourself.<br />
 
'''The RAM of Arduino UNO is too small to realize drawing function of e-Paper. In this case, for most of the e-Paper, we only make the image display function and save the image to flash. <br />
 
'''The RAM of Arduino UNO is too small to realize drawing function of e-Paper. In this case, for most of the e-Paper, we only make the image display function and save the image to flash. <br />
We recommend you to use [[E-Paper Shield]] if you use Arduino UNO. The seven-color e-Paper is not compatible with the e-Paper shield, please note it.'''<br />
+
We recommend you to use [[https://www.waveshare.com/e-paper-shield.htm E-Paper Shield]] if you use Arduino UNO. The seven-color e-Paper is not compatible with the e-Paper shield, please note it.'''<br />
 
{|border=1; style="width:700px;" align="center"
 
{|border=1; style="width:700px;" align="center"
|+ Connect to Arduino UNO
+
|+Arduino Corresponding Pins
|-style="background:#2D6FDF; color:white;" align="center"
+
|-style="background:green; color:white;" align="center"
|e-Paper||Arduino
+
|e-Paper||Arduino UNO || Mega2560
 
|-align="center"
 
|-align="center"
|Vcc||5V
+
|Vcc||5V||5V
 
|-align="center"
 
|-align="center"
|GND||GND
+
|GND||GND||GND
 
|-align="center"
 
|-align="center"
|DIN||D11
+
|DIN||D11||D51
 
|-align="center"
 
|-align="center"
|CLK||D13
+
|CLK||D13||D52
 
|-align="center"
 
|-align="center"
|CS||D10
+
|CS||D10||D10
 
|-align="center"
 
|-align="center"
|DC||D9
+
|DC||D9||D9
 
|-align="center"
 
|-align="center"
|RST||D8
+
|RST||D8||D8
 
|-align="center"
 
|-align="center"
|BUSY||D7
+
|BUSY||D7||D7
 
|}
 
|}
: [[File:E-paper_driver_hat_to_arduino_connet.png|center|700px]]
+
: [[File:E-paper_driver_hat_to_arduino_connet.png|center|500px]]
  
 
==Install Arduino IDE==
 
==Install Arduino IDE==
Line 32: Line 31:
  
 
==Run the Program==
 
==Run the Program==
[https://{{SERVERNAME}}/w/upload/3/39/E-Paper_code.7z Download the program] on the product encyclopedia interface, and then unzip it. Arduino programs are located at ~/Arduino/…
+
[https://github.com/waveshare/e-Paper Download the program] on the product encyclopedia interface, and then unzip it. Arduino programs are located at ~/Arduino/…<br/>
 
+
[[File:run the program.png]]<br/>
==Examples==
+
Please select the corresponding program to open according to the ink screen model<br/>
*Download the deme codes and unzip it. Open the Arduino examples (~/Arduino/…) <br />
+
[[File:epd1n02d.png]]<br/>
*Open a project, for example, open the opd1in54.ino project<br />
 
*Open the project and set the board to Arduino  UNO<br />
 
*Select the correct COM port<br />
 
*Build and upload the codes to board<br />
 
【Note】Because the flash of Arduino UNO is small, we recommend you use MEGA2560 if you use the big size e-Paper<br />
 
  
 
==='''Supporting types'''===
 
==='''Supporting types'''===
;1.02inch(128×80):
+
;1.02inch(128 × 80):
epd_1in02y:Example for 1.02inch e-Paper/1.02inch e-Paper Module
+
EPD_1in02d_test():Example for 1.02inch e-Paper/1.02inch e-Paper.
 
+
;1.54inch(1.54inch e-paper c:152 × 152,others:200 × 200):
;1.54inch(1.54inch e-paper c:152×152,others:200×200):
+
epd1in54: Example for 1.54inch e-paper V1(Balck/<font color="#DCDCDC">White</font>): This version is stopped production which can be bought before 2019-11-22;<br />
epd_1in54: Example for 1.54inch e-paper V1(Balck/White): This version is stopped production which can be bought before 2019-11-22;<br />
+
epd1in54_V2: Example for 1.54inch e-paper V2(Balck/<font color="#DCDCDC">White</font>): This is the current version that can be bought now (2020-07-29). The e-Paper has V2 sticker on the backside. <br />
epd_1in54_V2: Example for 1.54inch e-paper V2(Balck/White): This is the current version which can be bought now (2020-07-29). The e-Paper has V2 sticker on the backside. <br />
+
epd1in54b: Example for 1.54inch e-paper B(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>). It is currently out of production.<br />
epd_1in54b: Example for 1.54inch e-paper B(Black/White/Red);<br />
+
epd1in54b_V2: Example for 1.54inch e-Paper B V2 (Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>). The purchase date later than November 2019 is the V2 version, the current shipping version has the V2 logo on the back;<br />
epd_1in54b_V2: Example for 1.54inch e-paper B V2(Black/White/Red);<br />
+
epd1in54c: Example for 1.54inch e-paper C(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>); <br />
epd_1in54c: Example for 1.54inch e-paper C(Black/White/Red);br />
+
;1.64inch(168 × 168):
 
+
EPD_1in64g_test(): Example for 1.64inch e-paper G (Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>/<font color="#FFD700">Yellow</font>)<br/>
;2.7inch(264×176):
+
;2.7inch(264 × 176):
epd_2in7: Example for 2.7inch e-paper(Black/White);<br />
+
epd2in7: Example for 2.7inch e-paper(Black/<font color="#DCDCDC">White</font>);<br />
epd_2in7b: Example for 2.7inch e-paper B(Black.White/Red);<br />
+
epd2in7b: Example for 2.7inch e-paper B(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>);<br />
epd_2in7b_V2: Example for 2.7inch e-paper B V2(Black.White/Red);<br />
+
epd2in7b_V2: Example for 2.7inch e-paper B V2(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>);<br />
 
 
;2.9inch(296×128):
 
epd_2in9: Example for 2.9inch e-paper(Black/White);<br />
 
epd_2in9_V2: Example for 2.9inch e-paper V2(Black/White);<br />
 
epd_2in9bc: Example for 2.9inch e-paper B(Balck/White/Red) and 2.9inch e-paper C(Black/White/Yellow);<br />
 
epd_2in9b_V3: Example for 2.9inch e-paper B V3(Balck/White/Red;<br />
 
epd_2in9d: Example for 2.9inch e-paper D(Black/White);
 
 
 
;2.13inch(2.13inch e-Paper:250×122,others:212×104):
 
epd_2in13: Example for 2.13inch e-paper V1(Black/White), this version is stopped production and it can be bought before 019-05-15;<br />
 
epd_2in13_V2y: Example for 2.13inch e-paper V2(Black/White) This is the current version with sticker V2 on the backside (2020-07-29);<br />
 
epd_2in13bc: Example for 2.13inch e-paper B(Black/White/Red)and 2.13inch e-paper C(Black/White/Yellow);<br />
 
epd_2in13b_V3: Example for 2.13inch e-paper B V3(Black/White/Red)<br />
 
epd_2in13d: Example for 2.13inch e-paper D(Black/White);<br />
 
 
 
;2.66inch (152 x 296):
 
epd_2in66: Example for 2.66inch e-Paper (Black/White); <br />
 
epd_2in66b: Example for 2.66inch e-Paoer (Black/White/Red);<br />
 
 
 
;3.7inch (280 x 480):
 
epd_3in7: Example for 3.7inch e-Paper (Black/White); <br />
 
 
 
;4.01inch (640x400):
 
epd_4in01f: Example for 4.01inch e-Paper (Seven-color);<br />
 
  
;4.2inch(400×300):
+
;2.9inch (296 × 128):
epd_4in2: Example for 4.2inch e-paper(Black/White);<br />
+
epd2in9: Example for 2.9inch e-paper (Black/<font color="#DCDCDC">White</font>), this version is stopped production.<br />
epd_4in2bc: Example for 4.2inch e-paper B(Black/White/Red);<br />
+
epd2in9_V2: Example for 2.9inch e-paper V2(Black/<font color="#DCDCDC">White</font>); The purchase date is later than December 2020 is the V2 version, the current shipping version has the V2 logo on the back;<br />
epd_4in2b_V2: Example for 4.2inch e-paper B V2(Black/White/Red);<br />
+
epd2in9bc: Example for 2.9inch e-paper B(Balck/<font color="#DCDCDC">White</font>/Red) and 2.9inch e-paper C(Black/<font color="#DCDCDC">White</font>/<font color="#FFD700">Yellow</font>);<br />
 +
epd2in9b_V3: Example for 2.9inch e-paper B V3 (Balck/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>); Purchase date later than July 2020 is the V3 version, the current shipping version has the V3 logo on the back;<br />
 +
epd2in9d: Example for 2.9inch e-paper D(Black/<font color="#DCDCDC">White</font>).
  
;5.65inch (600x448):
+
;2.13inch(2.13inch e-Paper:250 × 122,others:212 × 104):
epd_5in65f: Example for 5.65inch e-Paper F (Seven-color);
+
epd2in13: Example for 2.13inch e-paper V1(Black/<font color="#DCDCDC">White</font>), this version is stopped production and it can be bought before 019-05-15;<br />
 +
epd2in13_V2: Example for 2.13inch e-paper V2(Black/<font color="#DCDCDC">White</font>) This is the current version with sticker V2 on the backside (2020-07-29);<br />
  
;5.83inch(600×448):
+
epd2in13_V3: Example for 2.13inch e-paper V3(Black/<font color="#DCDCDC">White</font>) This is the current version with sticker V3 on the backside (2020-07-29);<br />
epd_5in83: Example for 5.83inch e-paper(Black/White);<br />
+
epd2in13bc:Example for 2.13inch e-paper B(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>)and 2.13inch e-paper C(Blackj/<font color="#DCDCDC">White</font>/Yellow);<br />
epd_5in83_V2: Example for 5.83inch e-paper V2(Black/White);<br />
+
epd2in13b_V3:Example for 2.13inch e-paper B V3(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>)Purchase date later than April 2020 is the V3 version, the current shipping version has the V3 logo on the back;<br/>
epd_5in83bc: Example for 5.83inch e-paper B(Black/White/Red)and 5.83inch e-paper C(Black/White/Yellow);<br />
+
epd2in13d: Example for 2.13inch e-paper D(Black/<font color="#DCDCDC">White</font>);<br />
epd_5in83b_V2: Example for 5.83inch e-paper B V2(Black/White/Red)<br />
 
  
;7.5inch(V1:640×384, V2:800×480):
+
;2.66inch (152 × 296):
epd_7in5: Example for 7.5inch e-paper(Black/White), this version is stopped production and it can be bought before 2019-12-07;<br />
+
epd2in66: Example for 2.66inch e-Paper (Black/<font color="#DCDCDC">White</font>);<br />
epd_7in5_V2: Example for 7.5inch e-paper V2(Black/White), This is the current version with V2 sticker on the backside (2020-07-29)<br />  
+
epd2in66b: Example for 2.66inch e-Paper B (Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>); <br />
epd_7in5bc: Example for 7.5inch e-paper B(Black/White/Red)and 7.5inch e-paper C(Black/White/Yellow),7.5inch e-paper B V1 version is stopped production and it can be bought before 2019-12-07;<br />
 
epd_7in5b_V2: Example for 7.5inch e-paper B V2(Black/White/Red); This is the current version with V2 sticker on the backside. (2020-07-29);<br />
 
  
;7.5inch (HD 880 x 528):
+
;3inch (400 × 168):
epd_7in5_HD: Example for 7.5inch e-Paper HD (Black/White); <br />
+
EPD_3in0g_test(): Example for 3inch e-Paper G(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>/<font color="#FFD700">Yellow</font>); <br />
epd_7in5b_HD: Example for 7.5inch e-Paper B HD (Black/White/Red); <br />
+
;3.52inch (360 × 240):
 +
EPD_3in52_test(): Example for 3.52inch e-Paper (Black/<font color="#DCDCDC">White</font>); <br />
 +
;3.7inch (280 × 480):
 +
epd3in7: Example for 3.7inch e-Paper(Black/<font color="#DCDCDC">White</font>); <br />
 +
;4.01inch (640 × 400):
 +
epd4in01f: Example for the 4.01inch e-Paper HAT (F) (Black/<font color="#DCDCDC">White</font>/<font color="#008000">Green</font>/<font color="#0000FF">Blue</font>/<font color="#FF0000">Red</font>/<font color="#FFD700">Yellow</font>/<font color="#FFCC00">Orange</font>);<br />
 +
;4.2inch(400 × 300):
 +
epd4in2: Example for 4.2inch e-paper(Black/<font color="#DCDCDC">White</font>);<br />
 +
epd4in2bc: Example for 4.2inch e-paper B(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>);<br />
 +
epd4in2b_V2: Example for 4.2inch e-paper B V2(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>). The purchase date is later than November 2020, it is the V2 version, and the current shipping version has the V2 logo on the back;<br />
 +
;5.65inch (600 × 448):
 +
epd5in65: Example for for 5.65inch e-Paper F (Black/<font color="#DCDCDC">White</font>/<font color="#008000">Green</font>/<font color="#0000FF">Blue</font>/<font color="#FF0000">Red</font>/<font color="#FFD700">Yellow</font>/<font color="#FFCC00">Orange</font>);
 +
;5.83inch(600 × 448):
 +
epd5in83: Example for 5.83inch e-paper(Black/<font color="#DCDCDC">White</font>), It is currently out of production.<br />
 +
epd5in83_V2: Example for 5.83inch e-paper V2(Black/<font color="#DCDCDC">White</font>), The purchase date is later than December 2020 is the V2 version, the current shipping version, with the V2 logo on the back.<br />
 +
epd5in83bc: Example for 5.83inch e-paper B(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>)and 5.83inch e-paper C(Black/<font color="#DCDCDC">White</font>/<font color="#FFD700">Yellow</font>);<br />
 +
epd5in83b_V2: Example for 5.83inch e-paper B V2(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>). The purchase date is later than August 2020 for the V2 version, the current shipping version, with the V2 logo on the back<br />
 +
;7.5inch(V1:640 × 384, V2:800 × 480):
 +
epd7in5: Example for 7.5inch e-paper(Black/<font color="#DCDCDC">White</font>). The purchase date is earlier than 2019-12-07 as the V1 version, which is currently discontinued.<br />
 +
epd7in5_V2: For example for 7.5inch e-paper B(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>)and 7.5inch e-paper C(Black/<font color="#DCDCDC">White</font>/<font color="#FFD700">Yellow</font>), The purchase date later than 2019-12-07 is the V2 version, and the current shipping version has the V2 logo on the back;<br />
 +
epd7in5bc: Example for 7.5inch e-paper V2(Black/<font color="#DCDCDC">White</font>). The purchase date of 7.5inch e-paper B is earlier than 2019-12-07, which is the V1 version, which is currently discontinued, and 7.5inch e-paper C is normally available.<br/>
 +
epd7in5b_V2: Example for 7.5inch e-paper B V2(Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>); The purchase date is later than 2019-12-07 is the V2 version, with the V2 logo on the back; the purchase date is later than March 2021 is the V3 version, the current 7.5inch e-paper B shipping version, with the V3 logo on the back, the same use this program;<br />
 +
;7.3inch (400 × 168):
 +
epd_7in3g_test.py: Example for 7inch3 e-paper G (Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>/<font color="#FFD700">Yellow</font>).
 +
;7.5inch (880 × 528):
 +
epd7in5_HD: Example for 7.5inch e-Paper HD (Black/<font color="#DCDCDC">White</font>); <br />
 +
epd7in5b_HD: Example for 7.5inch e-Paper B HD (Black/<font color="#DCDCDC">White</font>/<font color="#FF0000">Red</font>); <br />
 +
<font backgound=white; color=#DD1223>*Note: The above time is for reference only, please refer to the screen logo for the specific version.</font><br />
 +
For example, 1.54inch e-Paper Module. Open the epd1in54 folder and run the epd1in54.ino file.<br />
 +
Open the program, select the development board model Arduino UNO<br />
 +
[[File:arduino15.png]]<br/>
 +
Select the corresponding COM port<br/>
 +
[[File:arduino25.png]]<br/>
 +
Then click compile and download<br/>
 +
[[File:arduino27.png]]<br/>
 +
Since the flash of arduino UNO is very small, several large-size screens use MEGA2560 for better results:<<br/>
 +
[[File:arduino29.png]]<br/>
  
 
==Code Description==
 
==Code Description==
==='''Files'''===
+
===Files===
Use 2.13inch e-Paper as example, open the folder of epd2in13 v2<br />
+
Take the 1.54-inch ink screen controlled by Arduino UNO as an example, open the epd1in54 directory:<br />
[[file:e-paper_arduino_ide_codeDescription1.png]]<br />
+
[[File:program-docu.png]]<br/>
epd2in13.ino:The project file <br />
+
in which:<br/>
epd2in13.cpp(.h):EPD driver of e-Paper<br />
+
epd1in54.ino: open with Arduino IDE.<br/>
epdif.cpp(.h): Hardware interface, functions for GPIO and SPI ;<br />
+
epd1in54.cpp(.h): is the driver of the ink screen.<br/>
font8.cpp、font12.cpp、font16.cpp、font20.cpp、font24.cpp、fonts.h: fonts which has<br />
+
epdif.cpp(.h): is the hardware interface definition, which encapsulates the read and writes pin levels, SPI data transmission, and pin initialization.<br/>
imagedata.cpp(.h):Image data, which is pre-coverted data for display directly.<br />
+
font8.cpp, font12.cpp, font16.cpp, font20.cpp, font24.cpp, fonts.h: are the models of characters of different sizes.<br/>
The codes are include three parts: Bottom hardware interface, middle EPD driver and application functions.<br />
+
imagedata.cpp(.h): is the image data, which can convert the 2-bit depth BMP image into an array through Img2Lcd (downloadable in the development data).<br/>
 +
The program is divided into the bottom hardware interface, the middle layer ink screen driver, and the upper layer application.<br/>
  
==='''Bottom Hardware Interface'''===
+
===Bottom Hardware Interface===
hardware interfaces are defined in epdif.cpp(.h) file<br />
+
hardware interfaces are defined in epdif.cpp(.h) file.<br />
;Write GPIO
+
*''' Write GPIO'''
 
<pre>
 
<pre>
 
void DigitalWrite(int pin, int value)
 
void DigitalWrite(int pin, int value)
 
</pre>
 
</pre>
The first parameter is GPIO, and second parameter is level<br />
+
The first parameter is GPIO, and the second parameter is level.<br />
;Read GPIO
+
*''' Read GPIO'''
 
<pre>
 
<pre>
 
int DigitalRead(int pin)
 
int DigitalRead(int pin)
 
</pre>
 
</pre>
The  parameter is GPIO, and return value is level<br />
+
The  parameter is GPIO, and the return value is level.<br />
  
;Delay  
+
*'''Delay'''
 
<pre>
 
<pre>
 
DelayMs(unsigned int delaytime)
 
DelayMs(unsigned int delaytime)
 
</pre>
 
</pre>
Delay time, unit is ms<br />
+
Delay time, the unit is ms.<br />
  
;SPI transmit data
+
*'''SPI transmit data'''
 
<pre>
 
<pre>
 
SpiTransfer(unsigned char data)
 
SpiTransfer(unsigned char data)
 
</pre>
 
</pre>
Type of parameter is char<br />
+
The type of parameter is char.<br />
  
;Hardware initailze
+
*''' Hardware initialize'''
 
<pre>
 
<pre>
 
int IfInit(void)
 
int IfInit(void)
 
</pre>
 
</pre>
The initialize function of SPI, input/ouptu are packaged here。<br />
+
The initialize function of SPI, input/output is packaged here.<br />
  
==='''Middle EPD driver'''===
+
===Middle EPD driver===
;Instantiate e-Paper class
+
*'''Instantiate e-Paper class'''
The Arduino codes are based on C++, should instantiate e-Paper class is necessary.
+
The Arduino codes are based on C++, should instantiate the e-Paper class is necessary.
 
<pre>
 
<pre>
 
Epd epd;
 
Epd epd;
 
</pre>
 
</pre>
  
; Initialize e-Paper, it should be used to initialize e-Paper or wakeup e-Paper from sleep mode.
+
*''' Initialize e-Paper, it should be used to initialize e-Paper or wakeup e-Paper from sleep mode.
*2.13inch e-Paper,2.9inch e-Paper
+
*2.13inch e-Paper,2.9inch e-Paper'''
 
<pre>
 
<pre>
 
epd.Init(lut_full_update); //Fully update
 
epd.Init(lut_full_update); //Fully update
Line 167: Line 174:
 
</pre>
 
</pre>
  
;Clear, clear the e-Paper to white
+
*''' Clear, clear the e-Paper to white'''
 
<pre>
 
<pre>
 
epd.clear();
 
epd.clear();
 
</pre>
 
</pre>
In some of project, the operation is divided to two part, they work in the same way<br />
+
In some projects, the operation is divided into two parts, they work in the same way.<br />
 
<pre>
 
<pre>
 
epd.ClearFrameMemory(0xFF);  
 
epd.ClearFrameMemory(0xFF);  
Line 177: Line 184:
 
</pre>
 
</pre>
  
;Transmit one frame of image and display
+
*''' Transmit one frame of image and display'''
 
<pre>
 
<pre>
 
void Display(const unsigned char* frame_buffer);
 
void Display(const unsigned char* frame_buffer);
Line 183: Line 190:
 
</pre>
 
</pre>
  
; Sleep
+
*'''Sleep'''
 
<pre>
 
<pre>
 
epd.Sleep();
 
epd.Sleep();
 
</pre>
 
</pre>
Set the e-Paper enter sleep mode. The consumption of the e-Paper will be reduced. However, you still need to update the display periodically to avoid a ghost problem.<br />
+
Set the e-Paper to enter sleep mode. The consumption of e-Paper will be reduced. However, you still need to update the display periodically to avoid a ghost problem.<br />
  
 
==='''Application functions'''===
 
==='''Application functions'''===
Line 201: Line 208:
 
Paint(unsigned char* image, int width, int height);
 
Paint(unsigned char* image, int width, int height);
 
</pre>
 
</pre>
The first parameter is image buffer, the second one is the width of the picture, and the third one is the height.<br />
+
The first parameter is the image buffer, the second one is the width of the picture, and the third one is the height.<br />
 
<pre>
 
<pre>
 
Paint paint(image, 0, 0);    // width should be the multiple of 8
 
Paint paint(image, 0, 0);    // width should be the multiple of 8
Line 207: Line 214:
 
The second and third parameters are set to 0, you can re-configure them with functions below:<br />
 
The second and third parameters are set to 0, you can re-configure them with functions below:<br />
  
;Set the width, height, rotate degree.
+
; Set the width, height, and rotation degree.
 
<pre>
 
<pre>
 
int  GetWidth(void); //Get the width
 
int  GetWidth(void); //Get the width
Line 217: Line 224:
 
</pre>
 
</pre>
  
;Get the image data
+
; Get the image data
 
<pre>
 
<pre>
 
unsigned char* GetImage(void);
 
unsigned char* GetImage(void);
 
</pre>
 
</pre>
  
;Draw circle
+
; Draw circle
 
<pre>
 
<pre>
 
void DrawPixel(int x, int y, int colored);
 
void DrawPixel(int x, int y, int colored);
Line 228: Line 235:
 
Coordination(x,y)
 
Coordination(x,y)
  
;Draw characater
+
; Draw character
 
<pre>
 
<pre>
 
void DrawCharAt(int x, int y, char ascii_char, sFONT* font, int colored);
 
void DrawCharAt(int x, int y, char ascii_char, sFONT* font, int colored);
 
</pre>
 
</pre>
Set(x,y)as the start point, draw characters ascii_char, set the fonts as font, color is colored.<br />
+
Set(x,y)as the start point, draw characters ascii_char, set the fonts as font, and color is colored.<br />
  
;Draw string
+
; Drawstring
 
<pre>
 
<pre>
 
void DrawStringAt(int x, int y, const char* text, sFONT* font, int colored);
 
void DrawStringAt(int x, int y, const char* text, sFONT* font, int colored);
 
</pre>
 
</pre>
Set(x,y)as the start point, draw the string text, font is font,color is colored<br />
+
Set(x,y)as the start point, draw the string text, font is a font, color is colored<br />
  
;Draw line
+
; Draw line
 
<pre>
 
<pre>
 
void DrawLine(int x0, int y0, int x1, int y1, int colored);
 
void DrawLine(int x0, int y0, int x1, int y1, int colored);
 
</pre>
 
</pre>
Use (x0,y0)as start point, (x1,y1) as end point;<br />
+
Use (x0,y0)as start point, (x1,y1) as endpoint;<br />
  
;Draw cross line:
+
; Draw cross line:
 
<pre>
 
<pre>
 
void DrawHorizontalLine(int x, int y, int width, int colored);
 
void DrawHorizontalLine(int x, int y, int width, int colored);
 
</pre>
 
</pre>
Set(x0,y0)as start points,draw a line, the widht is width, and color is colored</ br>
+
Set(x0,y0)as start points, draw a line, the width is width, and the color is colored</ br>
  
;Draw a vertical line
+
; Draw a vertical line
 
<pre>
 
<pre>
 
void DrawVerticalLine(int x, int y, int height, int colored);
 
void DrawVerticalLine(int x, int y, int height, int colored);
 
</pre>
 
</pre>
Use(x0,y0) as start point, draw a vertical line, width is height and color is colored./ br>
+
Use(x0,y0) as a start point, draw a vertical line, width is height, and the color is colored./ br>
  
;Draw a empty rectangle
+
; Draw a empty rectangle
 
<pre>
 
<pre>
 
void DrawRectangle(int x0, int y0, int x1, int y1, int colored);
 
void DrawRectangle(int x0, int y0, int x1, int y1, int colored);
 
</pre>
 
</pre>
User(x0,y0) as start point,(x1,y1)is end point, draw a rectangel, color of edges are colored.<br >
+
User(x0,y0) as a start point,(x1,y1) as an end point, draw a rectangle, color of edges are colored.<br >
  
;Draw a full rectangle
+
; Draw a full rectangle
 
<pre>
 
<pre>
 
void DrawFilledRectangle(int x0, int y0, int x1, int y1, int colored);
 
void DrawFilledRectangle(int x0, int y0, int x1, int y1, int colored);
 
</pre>
 
</pre>
Use(x0,y0)as start point, (x1,y1) is end point, draw a rectange, filled it with color: colored<br >
+
Use(x0,y0)as a start point, (x1,y1) as an end point, draw a rectangle, fill it with color: colored<br >
  
;Draw an empty circle
+
; Draw an empty circle
 
<pre>
 
<pre>
 
void DrawCircle(int x, int y, int radius, int colored);
 
void DrawCircle(int x, int y, int radius, int colored);
 
</pre>
 
</pre>
Use (x,y)as center,draw a empty circle with radius, color is colored<br >
+
Use (x,y)as the center, and draw an empty circle with a radius, color is colored<br >
  
;Draw a full circle
+
; Draw a full circle
 
<pre>
 
<pre>
 
void DrawFilledCircle(int x, int y, int radius, int colored);
 
void DrawFilledCircle(int x, int y, int radius, int colored);
 
</pre>
 
</pre>
Use (x,y)as center, draw a circle, radius is radius, filled with color: colored<br >
+
Use (x,y)as the center, and draw a solid circle with a radius, filled with color: colored.<br >

Latest revision as of 09:03, 2 June 2023

User Guides of Arduino

Hardware connection

The demo codes provided are based on Arduino UNO. If you want to use another Arduino board, you may need to change the connection and port the codes by yourself.
The RAM of Arduino UNO is too small to realize drawing function of e-Paper. In this case, for most of the e-Paper, we only make the image display function and save the image to flash.
We recommend you to use [E-Paper Shield] if you use Arduino UNO. The seven-color e-Paper is not compatible with the e-Paper shield, please note it.

Arduino Corresponding Pins
e-Paper Arduino UNO Mega2560
Vcc 5V 5V
GND GND GND
DIN D11 D51
CLK D13 D52
CS D10 D10
DC D9 D9
RST D8 D8
BUSY D7 D7
E-paper driver hat to arduino connet.png

Install Arduino IDE

arduino IDE Install Guide

Run the Program

Download the program on the product encyclopedia interface, and then unzip it. Arduino programs are located at ~/Arduino/…
Run the program.png
Please select the corresponding program to open according to the ink screen model
Epd1n02d.png

Supporting types

1.02inch(128 × 80):

EPD_1in02d_test():Example for 1.02inch e-Paper/1.02inch e-Paper.

1.54inch(1.54inch e-paper c:152 × 152,others:200 × 200):

epd1in54: Example for 1.54inch e-paper V1(Balck/White): This version is stopped production which can be bought before 2019-11-22;
epd1in54_V2: Example for 1.54inch e-paper V2(Balck/White): This is the current version that can be bought now (2020-07-29). The e-Paper has V2 sticker on the backside.
epd1in54b: Example for 1.54inch e-paper B(Black/White/Red). It is currently out of production.
epd1in54b_V2: Example for 1.54inch e-Paper B V2 (Black/White/Red). The purchase date later than November 2019 is the V2 version, the current shipping version has the V2 logo on the back;
epd1in54c: Example for 1.54inch e-paper C(Black/White/Red);

1.64inch(168 × 168)

EPD_1in64g_test(): Example for 1.64inch e-paper G (Black/White/Red/Yellow)

2.7inch(264 × 176)

epd2in7: Example for 2.7inch e-paper(Black/White);
epd2in7b: Example for 2.7inch e-paper B(Black/White/Red);
epd2in7b_V2: Example for 2.7inch e-paper B V2(Black/White/Red);

2.9inch (296 × 128)

epd2in9: Example for 2.9inch e-paper (Black/White), this version is stopped production.
epd2in9_V2: Example for 2.9inch e-paper V2(Black/White); The purchase date is later than December 2020 is the V2 version, the current shipping version has the V2 logo on the back;
epd2in9bc: Example for 2.9inch e-paper B(Balck/White/Red) and 2.9inch e-paper C(Black/White/Yellow);
epd2in9b_V3: Example for 2.9inch e-paper B V3 (Balck/White/Red); Purchase date later than July 2020 is the V3 version, the current shipping version has the V3 logo on the back;
epd2in9d: Example for 2.9inch e-paper D(Black/White).

2.13inch(2.13inch e-Paper:250 × 122,others:212 × 104):

epd2in13: Example for 2.13inch e-paper V1(Black/White), this version is stopped production and it can be bought before 019-05-15;
epd2in13_V2: Example for 2.13inch e-paper V2(Black/White) This is the current version with sticker V2 on the backside (2020-07-29);

epd2in13_V3: Example for 2.13inch e-paper V3(Black/White) This is the current version with sticker V3 on the backside (2020-07-29);
epd2in13bc:Example for 2.13inch e-paper B(Black/White/Red)and 2.13inch e-paper C(Blackj/White/Yellow);
epd2in13b_V3:Example for 2.13inch e-paper B V3(Black/White/Red)Purchase date later than April 2020 is the V3 version, the current shipping version has the V3 logo on the back;
epd2in13d: Example for 2.13inch e-paper D(Black/White);

2.66inch (152 × 296)

epd2in66: Example for 2.66inch e-Paper (Black/White);
epd2in66b: Example for 2.66inch e-Paper B (Black/White/Red);

3inch (400 × 168)

EPD_3in0g_test(): Example for 3inch e-Paper G(Black/White/Red/Yellow);

3.52inch (360 × 240)

EPD_3in52_test(): Example for 3.52inch e-Paper (Black/White);

3.7inch (280 × 480)

epd3in7: Example for 3.7inch e-Paper(Black/White);

4.01inch (640 × 400)

epd4in01f: Example for the 4.01inch e-Paper HAT (F) (Black/White/Green/Blue/Red/Yellow/Orange);

4.2inch(400 × 300)

epd4in2: Example for 4.2inch e-paper(Black/White);
epd4in2bc: Example for 4.2inch e-paper B(Black/White/Red);
epd4in2b_V2: Example for 4.2inch e-paper B V2(Black/White/Red). The purchase date is later than November 2020, it is the V2 version, and the current shipping version has the V2 logo on the back;

5.65inch (600 × 448)

epd5in65: Example for for 5.65inch e-Paper F (Black/White/Green/Blue/Red/Yellow/Orange);

5.83inch(600 × 448):

epd5in83: Example for 5.83inch e-paper(Black/White), It is currently out of production.
epd5in83_V2: Example for 5.83inch e-paper V2(Black/White), The purchase date is later than December 2020 is the V2 version, the current shipping version, with the V2 logo on the back.
epd5in83bc: Example for 5.83inch e-paper B(Black/White/Red)and 5.83inch e-paper C(Black/White/Yellow);
epd5in83b_V2: Example for 5.83inch e-paper B V2(Black/White/Red). The purchase date is later than August 2020 for the V2 version, the current shipping version, with the V2 logo on the back

7.5inch(V1:640 × 384, V2:800 × 480):

epd7in5: Example for 7.5inch e-paper(Black/White). The purchase date is earlier than 2019-12-07 as the V1 version, which is currently discontinued.
epd7in5_V2: For example for 7.5inch e-paper B(Black/White/Red)and 7.5inch e-paper C(Black/White/Yellow), The purchase date later than 2019-12-07 is the V2 version, and the current shipping version has the V2 logo on the back;
epd7in5bc: Example for 7.5inch e-paper V2(Black/White). The purchase date of 7.5inch e-paper B is earlier than 2019-12-07, which is the V1 version, which is currently discontinued, and 7.5inch e-paper C is normally available.
epd7in5b_V2: Example for 7.5inch e-paper B V2(Black/White/Red); The purchase date is later than 2019-12-07 is the V2 version, with the V2 logo on the back; the purchase date is later than March 2021 is the V3 version, the current 7.5inch e-paper B shipping version, with the V3 logo on the back, the same use this program;

7.3inch (400 × 168)

epd_7in3g_test.py: Example for 7inch3 e-paper G (Black/White/Red/Yellow).

7.5inch (880 × 528)

epd7in5_HD: Example for 7.5inch e-Paper HD (Black/White);
epd7in5b_HD: Example for 7.5inch e-Paper B HD (Black/White/Red);
*Note: The above time is for reference only, please refer to the screen logo for the specific version.
For example, 1.54inch e-Paper Module. Open the epd1in54 folder and run the epd1in54.ino file.
Open the program, select the development board model Arduino UNO
Arduino15.png
Select the corresponding COM port
Arduino25.png
Then click compile and download
Arduino27.png
Since the flash of arduino UNO is very small, several large-size screens use MEGA2560 for better results:<
Arduino29.png

Code Description

Files

Take the 1.54-inch ink screen controlled by Arduino UNO as an example, open the epd1in54 directory:
Program-docu.png
in which:
epd1in54.ino: open with Arduino IDE.
epd1in54.cpp(.h): is the driver of the ink screen.
epdif.cpp(.h): is the hardware interface definition, which encapsulates the read and writes pin levels, SPI data transmission, and pin initialization.
font8.cpp, font12.cpp, font16.cpp, font20.cpp, font24.cpp, fonts.h: are the models of characters of different sizes.
imagedata.cpp(.h): is the image data, which can convert the 2-bit depth BMP image into an array through Img2Lcd (downloadable in the development data).
The program is divided into the bottom hardware interface, the middle layer ink screen driver, and the upper layer application.

Bottom Hardware Interface

hardware interfaces are defined in epdif.cpp(.h) file.

  • Write GPIO
void DigitalWrite(int pin, int value)

The first parameter is GPIO, and the second parameter is level.

  • Read GPIO
int DigitalRead(int pin)

The parameter is GPIO, and the return value is level.

  • Delay
DelayMs(unsigned int delaytime)

Delay time, the unit is ms.

  • SPI transmit data
SpiTransfer(unsigned char data)

The type of parameter is char.

  • Hardware initialize
int IfInit(void)

The initialize function of SPI, input/output is packaged here.

Middle EPD driver

  • Instantiate e-Paper class

The Arduino codes are based on C++, should instantiate the e-Paper class is necessary.

Epd epd;
  • Initialize e-Paper, it should be used to initialize e-Paper or wakeup e-Paper from sleep mode.
  • 2.13inch e-Paper,2.9inch e-Paper
epd.Init(lut_full_update); //Fully update
epd.Init(lut_partial_update); //Partial update
  • 4.2inch e-Paper
epd.Init();
  • Clear, clear the e-Paper to white
epd.clear();

In some projects, the operation is divided into two parts, they work in the same way.

epd.ClearFrameMemory(0xFF); 
epd.DisplayFrame();//Display it
  • Transmit one frame of image and display
void Display(const unsigned char* frame_buffer);
void DisplayFrame(const unsigned char* frame_buffer_black, const unsigned char* frame_buffer_red); //Three color e-Paper
  • Sleep
epd.Sleep();

Set the e-Paper to enter sleep mode. The consumption of e-Paper will be reduced. However, you still need to update the display periodically to avoid a ghost problem.

Application functions

The drawing functions are defined in this part.
The coordination of the image buffer:
E-paper arduino pic1.png

The functions are defined in epdpaint.h file
E-paper arduino ide codeDescription2.png

Initailze image buffer
Paint(unsigned char* image, int width, int height);

The first parameter is the image buffer, the second one is the width of the picture, and the third one is the height.

Paint paint(image, 0, 0);    // width should be the multiple of 8

The second and third parameters are set to 0, you can re-configure them with functions below:

Set the width, height, and rotation degree.
int  GetWidth(void); //Get the width
void SetWidth(int width);//Set the width
int  GetHeight(void);//Get the height
void SetHeight(int height);//Set the height
int  GetRotate(void);//Get the degree
void SetRotate(int rotate);//Set the rotate degree
Get the image data
unsigned char* GetImage(void);
Draw circle
void DrawPixel(int x, int y, int colored);

Coordination(x,y)

Draw character
void DrawCharAt(int x, int y, char ascii_char, sFONT* font, int colored);

Set(x,y)as the start point, draw characters ascii_char, set the fonts as font, and color is colored.

Drawstring
void DrawStringAt(int x, int y, const char* text, sFONT* font, int colored);

Set(x,y)as the start point, draw the string text, font is a font, color is colored

Draw line
void DrawLine(int x0, int y0, int x1, int y1, int colored);

Use (x0,y0)as start point, (x1,y1) as endpoint;

Draw cross line
void DrawHorizontalLine(int x, int y, int width, int colored);

Set(x0,y0)as start points, draw a line, the width is width, and the color is colored</ br>

Draw a vertical line
void DrawVerticalLine(int x, int y, int height, int colored);

Use(x0,y0) as a start point, draw a vertical line, width is height, and the color is colored./ br>

Draw a empty rectangle
void DrawRectangle(int x0, int y0, int x1, int y1, int colored);

User(x0,y0) as a start point,(x1,y1) as an end point, draw a rectangle, color of edges are colored.

Draw a full rectangle
void DrawFilledRectangle(int x0, int y0, int x1, int y1, int colored);

Use(x0,y0)as a start point, (x1,y1) as an end point, draw a rectangle, fill it with color: colored

Draw an empty circle
void DrawCircle(int x, int y, int radius, int colored);

Use (x,y)as the center, and draw an empty circle with a radius, color is colored

Draw a full circle
void DrawFilledCircle(int x, int y, int radius, int colored);

Use (x,y)as the center, and draw a solid circle with a radius, filled with color: colored.