Skip to content

Commit

Permalink
Update the routines of the 2.9inch V2 e-Paper to add a four-grayscale…
Browse files Browse the repository at this point in the history
… display
  • Loading branch information
shhds committed Sep 1, 2023
1 parent 7621f7d commit 8316a45
Show file tree
Hide file tree
Showing 33 changed files with 3,373 additions and 1,212 deletions.
151 changes: 151 additions & 0 deletions Arduino/epd2in9_V2/epd2in9_V2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ unsigned char WS_20_30[159] =
0x22, 0x17, 0x41, 0x0, 0x32, 0x36
};

unsigned char Gray4[159] =
{
0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //VS L0 //2.28s
0x20, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //VS L1
0x28, 0x60, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //VS L2
0x2A, 0x60, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //VS L3
0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //VS L4
0x00, 0x02, 0x00, 0x05, 0x14, 0x00, 0x00, //TP, SR, RP of Group0
0x1E, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x01, //TP, SR, RP of Group1
0x00, 0x02, 0x00, 0x05, 0x14, 0x00, 0x00, //TP, SR, RP of Group2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //TP, SR, RP of Group3
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //TP, SR, RP of Group4
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //TP, SR, RP of Group5
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //TP, SR, RP of Group6
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //TP, SR, RP of Group7
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //TP, SR, RP of Group8
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //TP, SR, RP of Group9
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //TP, SR, RP of Group10
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //TP, SR, RP of Group11
0x24, 0x22, 0x22, 0x22, 0x23, 0x32, 0x00, 0x00, 0x00, //FR, XON
0x22, 0x17, 0x41, 0xAE, 0x32, 0x28, //EOPT VGH VSH1 VSH2 VSL VCOM
};

Epd::~Epd() {
};

Expand Down Expand Up @@ -120,6 +143,40 @@ int Epd::Init() {
return 0;
}

int Epd::Init_4Gray() {
/* this calls the peripheral hardware interface, see epdif */
if (IfInit() != 0) {
return -1;
}

Reset();

/* EPD hardware init start */
WaitUntilIdle();
SendCommand(0x12); //SWRESET
WaitUntilIdle();

SendCommand(0x01); //Driver output control
SendData(0x27);
SendData(0x01);
SendData(0x00);

SendCommand(0x11); //data entry mode
SendData(0x03);

SetMemoryArea(8, 0, width, height-1);

SendCommand(0x3C);
SendData(0x04);

SetMemoryPointer(8, 0);
WaitUntilIdle();

SetLut_by_host(Gray4);
/* EPD hardware init end */
return 0;
}

/**
* @brief: basic function for sending commands
*/
Expand Down Expand Up @@ -331,6 +388,100 @@ void Epd::ClearFrameMemory(unsigned char color) {
for (int i = 0; i < this->width / 8 * this->height; i++) {
SendData(color);
}

SendCommand(0x26);
/* send the color data */
for (int i = 0; i < this->width / 8 * this->height; i++) {
SendData(color);
}
}

void Epd::Display4Gray(const unsigned char *Image)
{
int i,j,k;
unsigned char temp1,temp2,temp3;

SendCommand(0x24);
for(i=0;i<4736;i++)
{
temp3=0;
for(j=0;j<2;j++)
{
temp1 = pgm_read_byte(&Image[i*2+j]);
for(k=0;k<2;k++)
{
temp2 = temp1&0xC0 ;
if(temp2 == 0xC0)
temp3 |= 0x00;//white
else if(temp2 == 0x00)
temp3 |= 0x01; //black
else if(temp2 == 0x80)
temp3 |= 0x01; //gray1
else //0x40
temp3 |= 0x00; //gray2
temp3 <<= 1;

temp1 <<= 2;
temp2 = temp1&0xC0 ;
if(temp2 == 0xC0) //white
temp3 |= 0x00;
else if(temp2 == 0x00) //black
temp3 |= 0x01;
else if(temp2 == 0x80)
temp3 |= 0x01; //gray1
else //0x40
temp3 |= 0x00; //gray2
if(j!=1 || k!=1)
temp3 <<= 1;

temp1 <<= 2;
}

}
SendData(temp3);
}
// new data
SendCommand(0x26);
for(i=0;i<4736;i++)
{
temp3=0;
for(j=0;j<2;j++)
{
temp1 = pgm_read_byte(&Image[i*2+j]);
for(k=0;k<2;k++)
{
temp2 = temp1&0xC0 ;
if(temp2 == 0xC0)
temp3 |= 0x00;//white
else if(temp2 == 0x00)
temp3 |= 0x01; //black
else if(temp2 == 0x80)
temp3 |= 0x00; //gray1
else //0x40
temp3 |= 0x01; //gray2
temp3 <<= 1;

temp1 <<= 2;
temp2 = temp1&0xC0 ;
if(temp2 == 0xC0) //white
temp3 |= 0x00;
else if(temp2 == 0x00) //black
temp3 |= 0x01;
else if(temp2 == 0x80)
temp3 |= 0x00; //gray1
else //0x40
temp3 |= 0x01; //gray2
if(j!=1 || k!=1)
temp3 <<= 1;

temp1 <<= 2;
}

}
SendData(temp3);
}

DisplayFrame();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion Arduino/epd2in9_V2/epd2in9_V2.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Epd : EpdIf {
Epd();
~Epd();
int Init();
int Init_4Gray(void);
void SendCommand(unsigned char command);
void SendData(unsigned char data);
void WaitUntilIdle(void);
Expand All @@ -63,7 +64,8 @@ class Epd : EpdIf {
void SetFrameMemory_Base(const unsigned char* image_buffer);
void ClearFrameMemory(unsigned char color);
void DisplayFrame(void);
void DisplayFrame_Partial(void);
void DisplayFrame_Partial(void);
void Display4Gray(const unsigned char *Image);
void Sleep(void);

private:
Expand Down
66 changes: 49 additions & 17 deletions Arduino/epd2in9_V2/epd2in9_V2.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* @filename : epd2in9_V2-demo.ino
* @brief : 2.9inch e-paper V2 display demo
* @author : Yehui from Waveshare
Expand Down Expand Up @@ -43,6 +43,7 @@ Paint paint(image, 0, 0); // width should be the multiple of 8
Epd epd;
unsigned long time_start_ms;
unsigned long time_now_s;
char time_string[] = {'0', '0', ':', '0', '0', '\0'};

void setup() {
// put your setup code here, to run once:
Expand All @@ -51,7 +52,8 @@ void setup() {
Serial.print("e-Paper init failed");
return;
}


#if 1
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();

Expand Down Expand Up @@ -91,7 +93,9 @@ void setup() {
epd.DisplayFrame();

delay(2000);
#endif

#if 1
if (epd.Init() != 0) {
Serial.print("e-Paper init failed ");
return;
Expand All @@ -105,27 +109,55 @@ void setup() {
*/
epd.SetFrameMemory_Base(IMAGE_DATA);
epd.DisplayFrame();
#endif

#if 0
Serial.print("show 4-gray image\r\n");
if (epd.Init_4Gray() != 0) {
Serial.print("e-Paper init failed ");
return;
}
epd.Display4Gray(IMAGE_DATA_4Gray);
#endif

#if 0
if (epd.Init() != 0) {
Serial.print("e-Paper init failed");
return;
}

epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();

time_start_ms = millis();

// put your main code here, to run repeatedly:

for(;;){
time_now_s = (millis() - time_start_ms) / 1000;
time_string[0] = time_now_s / 60 / 10 + '0';
time_string[1] = time_now_s / 60 % 10 + '0';
time_string[3] = time_now_s % 60 / 10 + '0';
time_string[4] = time_now_s % 60 % 10 + '0';

paint.SetWidth(32);
paint.SetHeight(96);
paint.SetRotate(ROTATE_90);

paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 4, time_string, &Font24, COLORED);
epd.SetFrameMemory_Partial(paint.GetImage(), 80, 72, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame_Partial();
}
#endif

/* Deep sleep */
Serial.print("sleep...");
epd.Sleep();
}

void loop() {
// put your main code here, to run repeatedly:
time_now_s = (millis() - time_start_ms) / 1000;
char time_string[] = {'0', '0', ':', '0', '0', '\0'};
time_string[0] = time_now_s / 60 / 10 + '0';
time_string[1] = time_now_s / 60 % 10 + '0';
time_string[3] = time_now_s % 60 / 10 + '0';
time_string[4] = time_now_s % 60 % 10 + '0';

paint.SetWidth(32);
paint.SetHeight(96);
paint.SetRotate(ROTATE_90);

paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 4, time_string, &Font24, COLORED);
epd.SetFrameMemory_Partial(paint.GetImage(), 80, 72, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame_Partial();

// delay(300);
}
2 changes: 1 addition & 1 deletion Arduino/epd2in9_V2/epdif.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define RST_PIN 8
#define DC_PIN 9
#define CS_PIN 10
#define BUSY_PIN 7
#define BUSY_PIN 7

class EpdIf {
public:
Expand Down
Loading

0 comments on commit 8316a45

Please sign in to comment.