waveshareteam / e-Paper

1.29k stars 587 forks source link

How do I change the display every X seconds? #277

Open marcinjahn opened 1 year ago

marcinjahn commented 1 year ago

I have the smallest e-ink screen - the 1.02 inches model one. I'm controlling it via an AVR microcontroller, you could say it's Arduino. I want to be able to change the content of the screen every 5 seconds.

Normally, I'd guess I have to do it like this:

Config_Init();
EPD_Init();
EPD_Clear();

_delay_ms(500);

unsigned char image_temp[1280]={0};
Paint paith(image_temp, 80, 128);

while (true)
{
   // update the image_temp..

   EPD_Display(image_temp);

   _delay_ms(5000);
}

It does kinda work, however, the problem is that the EPD_Display takes a looong time to execute. It might take literally minutes to do its job (while sometimes it's just seconds). I also noticed that the screen is white-on-black or black-on-white almost randomly. My text should be black-on-white all the time...

Am I doing something wrong?

marcinjahn commented 1 year ago

I also noticed that the behavior is really quite random. Sometimes the described issue does not happen at all. It runs fast enough, the EPD_Display method executes within seconds, not minutes.

To investigate further, I added some more logs and I see that the code takes the most time to execute at this line: https://github.com/waveshare/e-Paper/blob/master/Arduino/epd1in02d/EPD_1in02d.cpp#L180

It seems that the BUSY pin stays LOW for a long time. Am I doing something wrong or is there something wrong with the display?

marcinjahn commented 1 year ago

I think I found the solution. I modified some of the example functions by adding a small delay here and there between various command/data transfers. The ones that seem to need it are EPD_Display and EPD_TurnOn. Myself I used a 20ms delay between various transfers.

Quite possibly, 20ms is even too much, but for my use case it doesn't really matter. The most important fact is that the screen stops blocking my program for minutes, like it used to do.

The one thing I know for sure is that I will look for alternatives first before buying some WaveShare product in the future ;).