An example to display some text and graphics on a Waveshare 2.7" ePaper display tri-colour. From Kanjia 2.13" code.
main.cpp@0:fc1642aade4a, 2019-12-06 (annotated)
- Committer:
- mdroberts1243
- Date:
- Fri Dec 06 23:31:49 2019 +0000
- Revision:
- 0:fc1642aade4a
First commit. Adapted from Kanjia 2.13" example. May have an issue with an x offset (8 pixel border on Rotate 90 degrees mode)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mdroberts1243 | 0:fc1642aade4a | 1 | /* |
mdroberts1243 | 0:fc1642aade4a | 2 | * e-Paper control program |
mdroberts1243 | 0:fc1642aade4a | 3 | * MODIFIED by Mark Roberts for the Waveshare 2.7inch Pi Hat |
mdroberts1243 | 0:fc1642aade4a | 4 | * Tested on Nucleo L432KC with pins as defined below... |
mdroberts1243 | 0:fc1642aade4a | 5 | * https://www.waveshare.com/wiki/2.7inch_e-Paper_HAT?spm=a2g0o.detail.1000023.17.1e014701V7d4HU&file=2.7inch_e-Paper_HAT |
mdroberts1243 | 0:fc1642aade4a | 6 | * |
mdroberts1243 | 0:fc1642aade4a | 7 | * Copyright (c) 2019 Kenji Arai / JH1PJL |
mdroberts1243 | 0:fc1642aade4a | 8 | * http://www.page.sannet.ne.jp/kenjia/index.html |
mdroberts1243 | 0:fc1642aade4a | 9 | * http://mbed.org/users/kenjiArai/ |
mdroberts1243 | 0:fc1642aade4a | 10 | * Created: April 27th, 2019 |
mdroberts1243 | 0:fc1642aade4a | 11 | * Revised: June 29th, 2019 |
mdroberts1243 | 0:fc1642aade4a | 12 | * |
mdroberts1243 | 0:fc1642aade4a | 13 | * Tested on Nucleo-F446RE with mbed-os5.12.2 |
mdroberts1243 | 0:fc1642aade4a | 14 | * |
mdroberts1243 | 0:fc1642aade4a | 15 | * Refrence software |
mdroberts1243 | 0:fc1642aade4a | 16 | * https://github.com/waveshare/e-Paper |
mdroberts1243 | 0:fc1642aade4a | 17 | * https://os.mbed.com/users/imachooon/code/epd1in54/ |
mdroberts1243 | 0:fc1642aade4a | 18 | * Thanks imamura-san |
mdroberts1243 | 0:fc1642aade4a | 19 | * |
mdroberts1243 | 0:fc1642aade4a | 20 | * Technical documents |
mdroberts1243 | 0:fc1642aade4a | 21 | * https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT_(B) |
mdroberts1243 | 0:fc1642aade4a | 22 | * |
mdroberts1243 | 0:fc1642aade4a | 23 | * Product |
mdroberts1243 | 0:fc1642aade4a | 24 | * http://akizukidenshi.com/catalog/g/gP-13757/ |
mdroberts1243 | 0:fc1642aade4a | 25 | * https://www.waveshare.com/2.13inch-e-paper-hat-b.htm |
mdroberts1243 | 0:fc1642aade4a | 26 | */ |
mdroberts1243 | 0:fc1642aade4a | 27 | |
mdroberts1243 | 0:fc1642aade4a | 28 | // Include -------------------------------------------------------------------- |
mdroberts1243 | 0:fc1642aade4a | 29 | #include "mbed.h" |
mdroberts1243 | 0:fc1642aade4a | 30 | #include "epd2in7b.h" |
mdroberts1243 | 0:fc1642aade4a | 31 | #include "epdpaint.h" |
mdroberts1243 | 0:fc1642aade4a | 32 | |
mdroberts1243 | 0:fc1642aade4a | 33 | // Definition ----------------------------------------------------------------- |
mdroberts1243 | 0:fc1642aade4a | 34 | #define COLORED 0 |
mdroberts1243 | 0:fc1642aade4a | 35 | #define UNCOLORED 1 |
mdroberts1243 | 0:fc1642aade4a | 36 | |
mdroberts1243 | 0:fc1642aade4a | 37 | // Constructor ---------------------------------------------------------------- |
mdroberts1243 | 0:fc1642aade4a | 38 | // 3.3V, GND, DIN, , CLK, CS, DC, RST, BUSY, <- 2.13inch e-Paper pin |
mdroberts1243 | 0:fc1642aade4a | 39 | // mosi, miso, sclk, cs, dc, rst, busy, pwr |
mdroberts1243 | 0:fc1642aade4a | 40 | Epd epd = Epd( PB_5, NC, PB_3, PA_11, PA_0, PA_12, PA_1, NC); // modified for NUCLEO_L432KC |
mdroberts1243 | 0:fc1642aade4a | 41 | |
mdroberts1243 | 0:fc1642aade4a | 42 | Serial pc(USBTX, USBRX); |
mdroberts1243 | 0:fc1642aade4a | 43 | Timer t; |
mdroberts1243 | 0:fc1642aade4a | 44 | static int timeSet = 0; |
mdroberts1243 | 0:fc1642aade4a | 45 | |
mdroberts1243 | 0:fc1642aade4a | 46 | // RAM ------------------------------------------------------------------------ |
mdroberts1243 | 0:fc1642aade4a | 47 | uint8_t image[EPD_VERT*(EPD_HORIZ/8 + 1)]; |
mdroberts1243 | 0:fc1642aade4a | 48 | |
mdroberts1243 | 0:fc1642aade4a | 49 | // ROM / Constant data -------------------------------------------------------- |
mdroberts1243 | 0:fc1642aade4a | 50 | |
mdroberts1243 | 0:fc1642aade4a | 51 | // Function prototypes -------------------------------------------------------- |
mdroberts1243 | 0:fc1642aade4a | 52 | extern void time_enter_mode(void); |
mdroberts1243 | 0:fc1642aade4a | 53 | |
mdroberts1243 | 0:fc1642aade4a | 54 | //------------------------------------------------------------------------------ |
mdroberts1243 | 0:fc1642aade4a | 55 | // Control Program |
mdroberts1243 | 0:fc1642aade4a | 56 | //------------------------------------------------------------------------------ |
mdroberts1243 | 0:fc1642aade4a | 57 | int main() |
mdroberts1243 | 0:fc1642aade4a | 58 | { |
mdroberts1243 | 0:fc1642aade4a | 59 | time_t seconds; |
mdroberts1243 | 0:fc1642aade4a | 60 | char buf[32]; |
mdroberts1243 | 0:fc1642aade4a | 61 | |
mdroberts1243 | 0:fc1642aade4a | 62 | t.reset(); |
mdroberts1243 | 0:fc1642aade4a | 63 | t.start(); |
mdroberts1243 | 0:fc1642aade4a | 64 | /* |
mdroberts1243 | 0:fc1642aade4a | 65 | if (timeSet == 0) { // if time not set then go to time enter mode |
mdroberts1243 | 0:fc1642aade4a | 66 | time_enter_mode(); |
mdroberts1243 | 0:fc1642aade4a | 67 | timeSet = 1; |
mdroberts1243 | 0:fc1642aade4a | 68 | } |
mdroberts1243 | 0:fc1642aade4a | 69 | */ |
mdroberts1243 | 0:fc1642aade4a | 70 | seconds = time(NULL); // read current time |
mdroberts1243 | 0:fc1642aade4a | 71 | if (epd.Init() != 0) { // initialize e-Paper control program |
mdroberts1243 | 0:fc1642aade4a | 72 | printf("e-Paper init failed"); |
mdroberts1243 | 0:fc1642aade4a | 73 | return -1; |
mdroberts1243 | 0:fc1642aade4a | 74 | } |
mdroberts1243 | 0:fc1642aade4a | 75 | epd.ClearFrame(); |
mdroberts1243 | 0:fc1642aade4a | 76 | printf("Clear Frame completed\r\n"); |
mdroberts1243 | 0:fc1642aade4a | 77 | ThisThread::sleep_for(200); |
mdroberts1243 | 0:fc1642aade4a | 78 | Paint paint(image, EPD_HORIZ, EPD_VERT); |
mdroberts1243 | 0:fc1642aade4a | 79 | paint.Clear(UNCOLORED); |
mdroberts1243 | 0:fc1642aade4a | 80 | printf("Clear uncolored 1 complete\r\n"); |
mdroberts1243 | 0:fc1642aade4a | 81 | |
mdroberts1243 | 0:fc1642aade4a | 82 | paint.SetRotate(ROTATE_90); |
mdroberts1243 | 0:fc1642aade4a | 83 | paint.DrawStringAt(0, 4, "12345678901234567890123456789", |
mdroberts1243 | 0:fc1642aade4a | 84 | &Font8, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 85 | paint.DrawStringAt(0, 16, "12345678901234567890123456789", |
mdroberts1243 | 0:fc1642aade4a | 86 | &Font12, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 87 | paint.DrawStringAt(0, 32, "12345678901234567890123", |
mdroberts1243 | 0:fc1642aade4a | 88 | &Font16, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 89 | paint.DrawStringAt(0, 54, "123456789012345678", |
mdroberts1243 | 0:fc1642aade4a | 90 | &Font20, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 91 | paint.DrawStringAt(0, 80, "123456789012345", |
mdroberts1243 | 0:fc1642aade4a | 92 | &Font24, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 93 | paint.DrawStringAt(0, 110, "Waveshare 2.7 e-Paper WBR", |
mdroberts1243 | 0:fc1642aade4a | 94 | &Font12, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 95 | paint.DrawStringAt(0, 124, " tested on Nucleo-L432KC", |
mdroberts1243 | 0:fc1642aade4a | 96 | &Font12, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 97 | paint.DrawStringAt(0, 138, " by mdroberts1243 ", |
mdroberts1243 | 0:fc1642aade4a | 98 | &Font12, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 99 | strftime(buf, 30, "'%y-%m-%d %H:%M", localtime(&seconds)); |
mdroberts1243 | 0:fc1642aade4a | 100 | paint.DrawStringAt(0, 160, buf, &Font16, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 101 | printf("Text paint buffer rendered\r\n"); |
mdroberts1243 | 0:fc1642aade4a | 102 | |
mdroberts1243 | 0:fc1642aade4a | 103 | epd.SetPartialWindowBlack(paint.GetImage(), 0, 8, |
mdroberts1243 | 0:fc1642aade4a | 104 | paint.GetWidth(), paint.GetHeight()); |
mdroberts1243 | 0:fc1642aade4a | 105 | printf("SetPartialWindowBlack\r\n"); |
mdroberts1243 | 0:fc1642aade4a | 106 | |
mdroberts1243 | 0:fc1642aade4a | 107 | paint.Clear(UNCOLORED); |
mdroberts1243 | 0:fc1642aade4a | 108 | printf("Clear uncolored 2 complete\r\n"); |
mdroberts1243 | 0:fc1642aade4a | 109 | paint.SetRotate(ROTATE_90); |
mdroberts1243 | 0:fc1642aade4a | 110 | paint.DrawFilledRectangle(0, 150, 250, 156, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 111 | printf("Filled rectangle\r\n"); |
mdroberts1243 | 0:fc1642aade4a | 112 | paint.DrawFilledCircle(244, 150, 18, COLORED); |
mdroberts1243 | 0:fc1642aade4a | 113 | printf("Filled circle\r\n"); |
mdroberts1243 | 0:fc1642aade4a | 114 | epd.SetPartialWindowRed(paint.GetImage(), 0, 8, |
mdroberts1243 | 0:fc1642aade4a | 115 | paint.GetWidth(), paint.GetHeight()); |
mdroberts1243 | 0:fc1642aade4a | 116 | printf("SetPartialWindowRed\r\n"); |
mdroberts1243 | 0:fc1642aade4a | 117 | |
mdroberts1243 | 0:fc1642aade4a | 118 | epd.DisplayFrame(); |
mdroberts1243 | 0:fc1642aade4a | 119 | printf("DisplayFrame\r\n"); |
mdroberts1243 | 0:fc1642aade4a | 120 | |
mdroberts1243 | 0:fc1642aade4a | 121 | epd.Sleep(); |
mdroberts1243 | 0:fc1642aade4a | 122 | |
mdroberts1243 | 0:fc1642aade4a | 123 | strftime(buf, 30, " %B %d,'%y, %H:%M:%S", localtime(&seconds)); |
mdroberts1243 | 0:fc1642aade4a | 124 | pc.puts(buf); |
mdroberts1243 | 0:fc1642aade4a | 125 | pc.printf(" Display + Refresh time = %5.1f Sec\r\n", t.read()); |
mdroberts1243 | 0:fc1642aade4a | 126 | ThisThread::sleep_for((1000 * 60 * 1) - t.read_ms()); // sleep 1 minute |
mdroberts1243 | 0:fc1642aade4a | 127 | system_reset(); // restart |
mdroberts1243 | 0:fc1642aade4a | 128 | } |