E-paper for Arduino Use
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