zkarcher / FancyEPD

Display fancy graphics on ePaper.
MIT License
48 stars 8 forks source link

ESP32 compatibility #18

Open hulkco opened 6 years ago

hulkco commented 6 years ago

I'm trying, using the library with the ESP32 DevKit, using the sample program, everything is fine, except the images, which tend to move aside, leaving a ghost trail. `#include

include

include "FancyEPD.h"

include "FancyEPD_Demo_images.h"

define DELAY_BETWEEN_IMAGES_MS (6 * 1000)

define DO_ROTATION (true)

// initialize epaper with pin numbers for cs, dc, rs, bs, d0, d1 for software SPI //EPD215 epaper( 17, 16, 15, 14, 13, 11 ); // Pins for project: github.com/pdp7/kicad-teensy-epaper //FancyEPD epd(k_epd_model_E2215CS062, 17, 16, 14, 15, 13, 11); // software SPI //FancyEPD epd(k_epd_model_E2215CS062, 17, 16, 14, 15); // hardware SPI

//ESP12 Pinout //FancyEPD epd(k_epd_model_E2215CS062, 15, 2, 5, 4, 14, 13);

//ESP32 Pinout // initialize epaper with pin numbers for cs, dc, rs, bs, d0, d1 for software SPI FancyEPD epd(k_epd_model_E2215CS062, 18, 19, 21, 22,23,5);

void setup() { bool success = epd.init();

if (!success) {
    // Panic and freak out
    return;
}

}

void loop() { /* if (DO_ROTATION) epd.setRotation(0); drawCircles(); drawLabel("Update:\n builtin_refresh"); epd.setBorderColor(0x00); // white epd.updateScreen(k_update_builtin_refresh); delay(DELAY_BETWEEN_IMAGES_MS);

if (DO_ROTATION) epd.setRotation(1);
drawTriangles();
drawLabel("Update:\n  quick_refresh");
epd.updateScreen(k_update_quick_refresh);
delay(DELAY_BETWEEN_IMAGES_MS);

if (DO_ROTATION) epd.setRotation(2);
drawCircles();
drawLabel("Update:\n   no_blink");
epd.updateScreen(k_update_no_blink);
delay(DELAY_BETWEEN_IMAGES_MS);

if (DO_ROTATION) epd.setRotation(3);
drawTriangles();
drawLabel("Update:\n    partial");
epd.updateScreen(k_update_partial);
delay(DELAY_BETWEEN_IMAGES_MS);

/ //Arduino_ESP32 if (DO_ROTATION) epd.setRotation(3); epd.setBorderColor(0xff); // black epd.updateScreenWithImage( Arduino_ESP32, k_image_4bit_monochrome, k_update_no_blink ); delay(DELAY_BETWEEN_IMAGES_MS); / // Angel if (DO_ROTATION) epd.setRotation(0); epd.setBorderColor(0xff); // black epd.updateScreenWithImage(angel_4bit, k_image_4bit_monochrome, k_update_quick_refresh); delay(DELAY_BETWEEN_IMAGES_MS);

// Angel
epd.setBorderColor(0x00);   // white
epd.updateScreenWithImage(angel2_8bit, k_image_8bit_monochrome, k_update_quick_refresh);
delay(DELAY_BETWEEN_IMAGES_MS);

// Doggy
epd.setBorderColor(0x40);   // grey-ish
epd.updateScreenWithImage(doggy_2bit, k_image_2bit_monochrome, k_update_quick_refresh);
delay(DELAY_BETWEEN_IMAGES_MS);

*/
}

void drawCircles() { epd.clearBuffer(); for (uint8_t i = 0; i < 5; i++) { uint8_t radius = random(1, 80); epd.drawCircle(random(epd.width()), random(epd.height()), radius, 0xff); } }

void drawTriangles() { epd.clearBuffer();

const float TRI = 3.1415926f * (2.0f / 3.0f);

for (uint8_t i = 0; i < 6; i++) {
    int16_t x = random(epd.width());
    int16_t y = random(epd.height());
    int16_t r = random(2, 80);
    float theta = random(0xffffff) * (TRI / 0xffffff);

    for (uint8_t p = 0; p < 3; p++) {
        epd.drawLine(
            x + r * cosf(theta + TRI * p),
            y + r * sinf(theta + TRI * p),
            x + r * cosf(theta + TRI * (p + 1)),
            y + r * sinf(theta + TRI * (p + 1)),
            0xff
        );
    }
}

}

void drawLabel(String str) { // Background box const uint8_t box_height = 20; epd.fillRect(0, 0, epd.width(), box_height, 0x0); epd.drawFastHLine(0, box_height, epd.width(), 0xff);

epd.setCursor(0, 0);
epd.print(str);

} The only thing I modified was to add the pinout for the ESP32: //ESP32 Pinout // initialize epaper with pin numbers for cs, dc, rs, bs, d0(SCK), d1(MOSI) for software SPI FancyEPD epd(k_epd_model_E2215CS062, 17, 16, 5, 19, 18, 23);`

zkarcher commented 6 years ago

I'm not sure what's causing this, but there's a chance that it's fixed: There was a race condition where some data/commands were ignored if the EPD panel was busy during an update. The ESP32 is fast enough to trigger this issue.

This has been fixed on branch feature/compression but not merged into master. (Feel free to try that branch. I need to test this a bit, before doing a pull request.)

I'll update this issue when it's merged into master.