Difference between revisions of "E-paper for Arduino Use"
(创建页面,内容为“==Arduino使用例程== 例程均在Arduino uno上进行了测试,如果需要是其他型号的Arduino需要自己确定连接的管脚是否正确。<br /> ===…”) |
|||
Line 1: | Line 1: | ||
− | == | + | ==Working with Arduino== |
− | + | The demo code provide are bassed on Arduino UNO. If you want to use other Arduino board, you may need to change the connection even porting the codes yourself.<br /> | |
− | === | + | ===Hardware connection=== |
{|border=1; style="width:700px;" align="center" | {|border=1; style="width:700px;" align="center" | ||
− | |+Arduino | + | |+ Connect to Arduino UNO |
|-style="background:#2D6FDF; color:white;" align="center" | |-style="background:#2D6FDF; color:white;" align="center" | ||
|e-Paper||Arduino | |e-Paper||Arduino | ||
Line 23: | Line 23: | ||
|BUSY||D7 | |BUSY||D7 | ||
|} | |} | ||
− | === | + | ===Install Arduino IDE=== |
− | * | + | *Go to [https://www.arduino.cc/en/Main/Software arduino IDE], and download the IDE<br /> |
− | * | + | *Install it according to the guide of Arduino website.<br /> |
− | + | *Open the IDE software after installing.<br /> | |
− | * | ||
− | |||
− | |||
− | == | + | ==Run examples== |
− | * | + | *Download the deme codes and unzip it. Open the Arduino examples (~/Arduino/…) <br /> |
− | * | + | *Open 2.13inch 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 /> | |
− | == | + | ==Code Description== |
− | === | + | ===Files=== |
− | + | Use 2.13inch e-Paper as example, open the folder of epd2in13 v2<br /> | |
[[file:e-paper_arduino_ide_codeDescription1.png]]<br /> | [[file:e-paper_arduino_ide_codeDescription1.png]]<br /> | ||
− | + | epd2in13.ino:The project file <br /> | |
− | epd2in13. | + | epd2in13.cpp(.h):EPD driver of e-Paper<br /> |
− | epd2in13.cpp(.h): | + | epdif.cpp(.h): Hardware interface, functions for GPIO and SPI ;<br /> |
− | epdif.cpp(.h): | ||
font8.cpp、font12.cpp、font16.cpp、font20.cpp、font24.cpp、fonts.h:为不同大小字符的模;<br /> | font8.cpp、font12.cpp、font16.cpp、font20.cpp、font24.cpp、fonts.h:为不同大小字符的模;<br /> | ||
− | imagedata.cpp(.h) | + | imagedata.cpp(.h):Image data, which is pre-coverted data for display directly.<br /> |
− | + | The codes are include three parts: Bottom hardware interface, middle EPD driver and application functions.程;<br /> | |
− | === | + | ===Bottom hardware interface=== |
− | + | hardware interfaces are defined in epdif.cpp(.h) file<br /> | |
− | ; | + | ;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 /> | |
− | ; | + | ;Read GPIO |
<pre> | <pre> | ||
int DigitalRead(int pin) | int DigitalRead(int pin) | ||
</pre> | </pre> | ||
− | + | The parameter is GPIO, and return value is level<br /> | |
− | ; | + | ;Delay |
<pre> | <pre> | ||
DelayMs(unsigned int delaytime) | DelayMs(unsigned int delaytime) | ||
</pre> | </pre> | ||
− | + | Delay time, unit is ms<br /> | |
− | ; | + | ;SPI transmit data |
<pre> | <pre> | ||
SpiTransfer(unsigned char data) | SpiTransfer(unsigned char data) | ||
</pre> | </pre> | ||
− | + | Type of parameter is char<br /> | |
− | ; | + | ;Hardware initailze |
<pre> | <pre> | ||
int IfInit(void) | int IfInit(void) | ||
</pre> | </pre> | ||
− | + | The initialize function of SPI, input/ouptu are packaged here。<br /> | |
− | === | + | ===Middle EPD driver=== |
− | ; | + | ;Instantiate e-Paper class |
− | + | The Arduino codes is based on C++, should instantiate 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. |
*2.13inch e-Paper,2.9inch e-Paper | *2.13inch e-Paper,2.9inch e-Paper | ||
<pre> | <pre> | ||
− | epd.Init(lut_full_update); // | + | epd.Init(lut_full_update); //Fully update |
− | epd.Init(lut_partial_update); // | + | epd.Init(lut_partial_update); //Partial update |
</pre> | </pre> | ||
Line 101: | Line 97: | ||
</pre> | </pre> | ||
− | ; | + | ;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 /> | |
<pre> | <pre> | ||
epd.ClearFrameMemory(0xFF); | epd.ClearFrameMemory(0xFF); | ||
− | epd.DisplayFrame();// | + | epd.DisplayFrame();//Display it |
</pre> | </pre> | ||
− | ; | + | ;Transmit one frame of image and display |
<pre> | <pre> | ||
void Display(const unsigned char* frame_buffer); | void Display(const unsigned char* frame_buffer); | ||
− | void DisplayFrame(const unsigned char* frame_buffer_black, const unsigned char* frame_buffer_red); // | + | void DisplayFrame(const unsigned char* frame_buffer_black, const unsigned char* frame_buffer_red); //Three color e-Paper |
</pre> | </pre> | ||
− | ; | + | ;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 ghost problem.<br /> | |
− | === | + | ===Application functions=== |
− | + | The drawing functions are defined in this part.<br /> | |
− | + | The coordination of the image buffer:<br /> | |
[[file:e-paper_arduino_pic1.png|300px]] | [[file:e-paper_arduino_pic1.png|300px]] | ||
− | + | The functions are defined in epdpaint.h file<br /> | |
[[file:e-paper_arduino_ide_codeDescription2.png]]<br /> | [[file:e-paper_arduino_ide_codeDescription2.png]]<br /> | ||
− | |||
− | ; | + | ;Initailze image buffer |
<pre> | <pre> | ||
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 /> | |
<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 | ||
</pre> | </pre> | ||
− | + | The second and third parameters are set to 0, you can re-configure them with functions below:<br /> | |
− | ; | + | ;Set the width, height, rotate degree. |
<pre> | <pre> | ||
− | int GetWidth(void); // | + | int GetWidth(void); //Get the width |
− | void SetWidth(int width);// | + | void SetWidth(int width);//Set the width |
− | int GetHeight(void);// | + | int GetHeight(void);//Get the height |
− | void SetHeight(int height);// | + | void SetHeight(int height);//Set the height |
− | int GetRotate(void);// | + | int GetRotate(void);//Get the degree |
− | void SetRotate(int rotate);// | + | void SetRotate(int rotate);//Set the rotate degree |
</pre> | </pre> | ||
− | ; | + | ;Get the image data |
<pre> | <pre> | ||
unsigned char* GetImage(void); | unsigned char* GetImage(void); | ||
</pre> | </pre> | ||
− | ; | + | ;Draw circle |
<pre> | <pre> | ||
void DrawPixel(int x, int y, int colored); | void DrawPixel(int x, int y, int colored); | ||
</pre> | </pre> | ||
− | + | Coordination(x,y) | |
− | ; | + | ;Draw characater |
<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 /> | |
− | ; | + | ;Draw string |
<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 /> | |
− | ; | + | ;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 /> | |
− | ; | + | ;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> | |
− | ; | + | ;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> | |
− | ; | + | ;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 > | |
− | ; | + | ;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 > | |
− | ; | + | ;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 > | |
− | ; | + | ;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 > |
Latest revision as of 15:39, 8 June 2020
Contents
Working with Arduino
The demo code provide are bassed on Arduino UNO. If you want to use other Arduino board, you may need to change the connection even porting the codes yourself.
Hardware connection
e-Paper | Arduino |
Vcc | 5V |
GND | GND |
DIN | D11 |
CLK | D13 |
CS | D10 |
DC | D9 |
RST | D8 |
BUSY | D7 |
Install Arduino IDE
- Go to arduino IDE, and download the IDE
- Install it according to the guide of Arduino website.
- Open the IDE software after installing.
Run examples
- Download the deme codes and unzip it. Open the Arduino examples (~/Arduino/…)
- Open 2.13inch project
- Open the project and set the board to Arduino UNO
- Select the correct COM port
- Build and upload the codes to board
【Note】Because the flash of Arduino UNO is small, we recommend you use MEGA2560 if you use the big size e-Paper
Code Description
Files
Use 2.13inch e-Paper as example, open the folder of epd2in13 v2
epd2in13.ino:The project file
epd2in13.cpp(.h):EPD driver of e-Paper
epdif.cpp(.h): Hardware interface, functions for GPIO and SPI ;
font8.cpp、font12.cpp、font16.cpp、font20.cpp、font24.cpp、fonts.h:为不同大小字符的模;
imagedata.cpp(.h):Image data, which is pre-coverted data for display directly.
The codes are include three parts: Bottom hardware interface, middle EPD driver and application functions.程;
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 second parameter is level
- Read GPIO
int DigitalRead(int pin)
The parameter is GPIO, and return value is level
- Delay
DelayMs(unsigned int delaytime)
Delay time, unit is ms
- SPI transmit data
SpiTransfer(unsigned char data)
Type of parameter is char
- Hardware initailze
int IfInit(void)
The initialize function of SPI, input/ouptu are packaged here。
Middle EPD driver
- Instantiate e-Paper class
The Arduino codes is based on C++, should instantiate 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 of project, the operation is divided to two part, 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 enter sleep mode. The consumption of the e-Paper will be reduced. However, you still need to update the display periodically to avoid ghost problem.
Application functions
The drawing functions are defined in this part.
The coordination of the image buffer:
The functions are defined in epdpaint.h file
- Initailze image buffer
Paint(unsigned char* image, int width, int height);
The first parameter is 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, rotate 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 characater
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, color is colored.
- Draw string
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 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 end point;
- Draw cross line
void DrawHorizontalLine(int x, int y, int width, int colored);
Set(x0,y0)as start points,draw a line, the widht is width, and color is colored</ br>
- Draw a vertical line
void DrawVerticalLine(int x, int y, int height, int colored);
Use(x0,y0) as start point, draw a vertical line, width is height and color is colored./ br>
- Draw a empty rectangle
void DrawRectangle(int x0, int y0, int x1, int y1, int colored);
User(x0,y0) as start point,(x1,y1)is end point, draw a rectangel, 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 start point, (x1,y1) is end point, draw a rectange, filled it with color: colored
- Draw an empty circle
void DrawCircle(int x, int y, int radius, int colored);
Use (x,y)as center,draw a empty circle with radius, color is colored
- Draw a full circle
void DrawFilledCircle(int x, int y, int radius, int colored);
Use (x,y)as center, draw a circle, radius is radius, filled with color: colored