E_paper, E_ink, Screen size 1.54", resolution 200x200, 4 wire spi, Waveshare, Black and White, Kl25Z, 8 wire print connector, supply 3.3 Volt, IL0373 Controller, font size is 8, 12, 16 and 24.

Dependencies:   mbed

Committer:
GerritPathuis
Date:
Thu Mar 29 18:27:28 2018 +0000
Revision:
8:01db118d1694
Parent:
7:25cadf37fd86
Child:
9:9503e1ff98ea
Seems to work

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GerritPathuis 0:665e04c85d8d 1 /**
GerritPathuis 0:665e04c85d8d 2 * @filename : epd1in54-demo.ino
GerritPathuis 0:665e04c85d8d 3 * @brief : 1.54inch e-paper display demo
GerritPathuis 0:665e04c85d8d 4 * @author : Yehui from Waveshare
GerritPathuis 0:665e04c85d8d 5 *
GerritPathuis 0:665e04c85d8d 6 * Copyright (C) Waveshare September 5 2017
GerritPathuis 0:665e04c85d8d 7 *
GerritPathuis 0:665e04c85d8d 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
GerritPathuis 0:665e04c85d8d 9 * of this software and associated documnetation files (the "Software"), to deal
GerritPathuis 0:665e04c85d8d 10 * in the Software without restriction, including without limitation the rights
GerritPathuis 0:665e04c85d8d 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
GerritPathuis 0:665e04c85d8d 12 * copies of the Software, and to permit persons to whom the Software is
GerritPathuis 0:665e04c85d8d 13 * furished to do so, subject to the following conditions:
GerritPathuis 0:665e04c85d8d 14 *
GerritPathuis 0:665e04c85d8d 15 * The above copyright notice and this permission notice shall be included in
GerritPathuis 0:665e04c85d8d 16 * all copies or substantial portions of the Software.
GerritPathuis 0:665e04c85d8d 17 *
GerritPathuis 0:665e04c85d8d 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
GerritPathuis 0:665e04c85d8d 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
GerritPathuis 0:665e04c85d8d 20 * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
GerritPathuis 0:665e04c85d8d 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
GerritPathuis 0:665e04c85d8d 22 * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
GerritPathuis 0:665e04c85d8d 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
GerritPathuis 0:665e04c85d8d 24 * THE SOFTWARE.
GerritPathuis 0:665e04c85d8d 25 */
GerritPathuis 0:665e04c85d8d 26
GerritPathuis 0:665e04c85d8d 27 #include "mbed.h"
GerritPathuis 1:d27a7e06c233 28 #include "epd1in54.h"
GerritPathuis 1:d27a7e06c233 29 #include "epdpaint.h"
GerritPathuis 1:d27a7e06c233 30 #include "epdif.h"
GerritPathuis 0:665e04c85d8d 31 #include "imagedata.h"
GerritPathuis 0:665e04c85d8d 32
GerritPathuis 0:665e04c85d8d 33 #define COLORED 0
GerritPathuis 0:665e04c85d8d 34 #define UNCOLORED 1
GerritPathuis 0:665e04c85d8d 35
GerritPathuis 0:665e04c85d8d 36 Serial pc(USBTX, USBRX, 115200);
GerritPathuis 1:d27a7e06c233 37
GerritPathuis 8:01db118d1694 38 DigitalOut reset_pin(PTA17);
GerritPathuis 6:469fb6b0d26d 39 DigitalOut dc_pin(PTD5);
GerritPathuis 6:469fb6b0d26d 40 DigitalOut cs_pin(PTD0);
GerritPathuis 8:01db118d1694 41 DigitalIn busy_pin(PTA13, PullNone);
GerritPathuis 6:469fb6b0d26d 42 SPI epaper(PTD2,PTD3,PTD1); //MOSI, MISO, CLK
GerritPathuis 8:01db118d1694 43 DigitalOut myled(LED2);
GerritPathuis 0:665e04c85d8d 44
GerritPathuis 1:d27a7e06c233 45
GerritPathuis 0:665e04c85d8d 46 /**
GerritPathuis 0:665e04c85d8d 47 * Due to RAM not enough in Arduino UNO, a frame buffer is not allowed.
GerritPathuis 7:25cadf37fd86 48 * In this case, a smaller image buffer is allocated and you have to
GerritPathuis 0:665e04c85d8d 49 * update a partial display several times.
GerritPathuis 0:665e04c85d8d 50 * 1 byte = 8 pixels, therefore you have to set 8*N pixels at a time.
GerritPathuis 0:665e04c85d8d 51 */
GerritPathuis 0:665e04c85d8d 52 unsigned char image[1024];
GerritPathuis 7:25cadf37fd86 53 Paint paint(image, 0, 0); // width should be the multiple of 8
GerritPathuis 0:665e04c85d8d 54 Epd epd;
GerritPathuis 0:665e04c85d8d 55 unsigned long time_start_ms;
GerritPathuis 0:665e04c85d8d 56 unsigned long time_now_s;
GerritPathuis 0:665e04c85d8d 57
GerritPathuis 7:25cadf37fd86 58 void setup()
GerritPathuis 7:25cadf37fd86 59 {
GerritPathuis 7:25cadf37fd86 60 // put your setup code here, to run once:
GerritPathuis 7:25cadf37fd86 61 if (epd.Init(lut_full_update) != 0) {
GerritPathuis 8:01db118d1694 62 pc.printf("e-Paper init failed !!!");
GerritPathuis 7:25cadf37fd86 63 return;
GerritPathuis 7:25cadf37fd86 64 }
GerritPathuis 7:25cadf37fd86 65
GerritPathuis 7:25cadf37fd86 66 /**
GerritPathuis 7:25cadf37fd86 67 * there are 2 memory areas embedded in the e-paper display
GerritPathuis 7:25cadf37fd86 68 * and once the display is refreshed, the memory area will be auto-toggled,
GerritPathuis 7:25cadf37fd86 69 * i.e. the next action of SetFrameMemory will set the other memory area
GerritPathuis 7:25cadf37fd86 70 * therefore you have to clear the frame memory twice.
GerritPathuis 7:25cadf37fd86 71 */
GerritPathuis 0:665e04c85d8d 72
GerritPathuis 7:25cadf37fd86 73 pc.printf("Display frame 1\n\r");
GerritPathuis 7:25cadf37fd86 74 epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
GerritPathuis 7:25cadf37fd86 75 pc.printf("Display frame 2\n\r");
GerritPathuis 7:25cadf37fd86 76 epd.DisplayFrame();
GerritPathuis 7:25cadf37fd86 77 pc.printf("Display frame 3\n\r");
GerritPathuis 7:25cadf37fd86 78 epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
GerritPathuis 7:25cadf37fd86 79 pc.printf("Display frame 4\n\r");
GerritPathuis 7:25cadf37fd86 80 epd.DisplayFrame();
GerritPathuis 7:25cadf37fd86 81
GerritPathuis 7:25cadf37fd86 82 pc.printf("Rotate 0\n\r");
GerritPathuis 7:25cadf37fd86 83 paint.SetRotate(ROTATE_0);
GerritPathuis 7:25cadf37fd86 84 paint.SetWidth(200);
GerritPathuis 7:25cadf37fd86 85 paint.SetHeight(24);
GerritPathuis 0:665e04c85d8d 86
GerritPathuis 7:25cadf37fd86 87 /* For simplicity, the arguments are explicit numerical coordinates */
GerritPathuis 7:25cadf37fd86 88
GerritPathuis 8:01db118d1694 89 pc.printf("Colored\n\r");
GerritPathuis 7:25cadf37fd86 90 paint.Clear(COLORED);
GerritPathuis 7:25cadf37fd86 91 paint.DrawStringAt(30, 4, "Hello world!", &Font16, UNCOLORED);
GerritPathuis 7:25cadf37fd86 92 epd.SetFrameMemory(paint.GetImage(), 0, 10, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 93
GerritPathuis 7:25cadf37fd86 94 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 95 paint.DrawStringAt(30, 4, "e-Paper Demo", &Font16, COLORED);
GerritPathuis 7:25cadf37fd86 96 epd.SetFrameMemory(paint.GetImage(), 0, 30, paint.GetWidth(), paint.GetHeight());
GerritPathuis 7:25cadf37fd86 97
GerritPathuis 7:25cadf37fd86 98 paint.SetWidth(64);
GerritPathuis 7:25cadf37fd86 99 paint.SetHeight(64);
GerritPathuis 0:665e04c85d8d 100
GerritPathuis 7:25cadf37fd86 101 pc.printf("Rectangle \n\r");
GerritPathuis 7:25cadf37fd86 102 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 103 paint.DrawRectangle(0, 0, 40, 50, COLORED);
GerritPathuis 7:25cadf37fd86 104 paint.DrawLine(0, 0, 40, 50, COLORED);
GerritPathuis 7:25cadf37fd86 105 paint.DrawLine(40, 0, 0, 50, COLORED);
GerritPathuis 7:25cadf37fd86 106 epd.SetFrameMemory(paint.GetImage(), 16, 60, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 107
GerritPathuis 7:25cadf37fd86 108 pc.printf("Circle \n\r");
GerritPathuis 7:25cadf37fd86 109 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 110 paint.DrawCircle(32, 32, 30, COLORED);
GerritPathuis 7:25cadf37fd86 111 epd.SetFrameMemory(paint.GetImage(), 120, 60, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 112
GerritPathuis 7:25cadf37fd86 113 pc.printf("Fille Rectangle \n\r");
GerritPathuis 7:25cadf37fd86 114 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 115 paint.DrawFilledRectangle(0, 0, 40, 50, COLORED);
GerritPathuis 7:25cadf37fd86 116 epd.SetFrameMemory(paint.GetImage(), 16, 130, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 117
GerritPathuis 7:25cadf37fd86 118 pc.printf("Filled circle \n\r");
GerritPathuis 7:25cadf37fd86 119 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 120 paint.DrawFilledCircle(32, 32, 30, COLORED);
GerritPathuis 7:25cadf37fd86 121 epd.SetFrameMemory(paint.GetImage(), 120, 130, paint.GetWidth(), paint.GetHeight());
GerritPathuis 7:25cadf37fd86 122 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 123
GerritPathuis 7:25cadf37fd86 124 wait_ms(2000);
GerritPathuis 0:665e04c85d8d 125
GerritPathuis 7:25cadf37fd86 126 if (epd.Init(lut_partial_update) != 0) {
GerritPathuis 7:25cadf37fd86 127 pc.printf("e-Paper init failed");
GerritPathuis 7:25cadf37fd86 128 return;
GerritPathuis 7:25cadf37fd86 129 }
GerritPathuis 0:665e04c85d8d 130
GerritPathuis 7:25cadf37fd86 131 /**
GerritPathuis 7:25cadf37fd86 132 * there are 2 memory areas embedded in the e-paper display
GerritPathuis 7:25cadf37fd86 133 * and once the display is refreshed, the memory area will be auto-toggled,
GerritPathuis 7:25cadf37fd86 134 * i.e. the next action of SetFrameMemory will set the other memory area
GerritPathuis 7:25cadf37fd86 135 * therefore you have to set the frame memory and refresh the display twice.
GerritPathuis 7:25cadf37fd86 136 */
GerritPathuis 7:25cadf37fd86 137 epd.SetFrameMemory(IMAGE_DATA);
GerritPathuis 7:25cadf37fd86 138 epd.DisplayFrame();
GerritPathuis 7:25cadf37fd86 139 epd.SetFrameMemory(IMAGE_DATA);
GerritPathuis 7:25cadf37fd86 140 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 141
GerritPathuis 7:25cadf37fd86 142 //time_start_ms = millis();
GerritPathuis 7:25cadf37fd86 143 time_start_ms = 0;
GerritPathuis 0:665e04c85d8d 144 }
GerritPathuis 0:665e04c85d8d 145
GerritPathuis 7:25cadf37fd86 146 void loop()
GerritPathuis 7:25cadf37fd86 147 {
GerritPathuis 7:25cadf37fd86 148 // put your main code here, to run repeatedly:
GerritPathuis 7:25cadf37fd86 149 //time_now_s = (millis() - time_start_ms) / 1000;
GerritPathuis 7:25cadf37fd86 150 time_now_s = 999;
GerritPathuis 7:25cadf37fd86 151 char time_string[] = {'0', '0', ':', '0', '0', '\0'};
GerritPathuis 7:25cadf37fd86 152 time_string[0] = time_now_s / 60 / 10 + '0';
GerritPathuis 7:25cadf37fd86 153 time_string[1] = time_now_s / 60 % 10 + '0';
GerritPathuis 7:25cadf37fd86 154 time_string[3] = time_now_s % 60 / 10 + '0';
GerritPathuis 7:25cadf37fd86 155 time_string[4] = time_now_s % 60 % 10 + '0';
GerritPathuis 0:665e04c85d8d 156
GerritPathuis 7:25cadf37fd86 157 paint.SetWidth(32);
GerritPathuis 7:25cadf37fd86 158 paint.SetHeight(96);
GerritPathuis 7:25cadf37fd86 159 paint.SetRotate(ROTATE_270);
GerritPathuis 0:665e04c85d8d 160
GerritPathuis 7:25cadf37fd86 161 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 162 paint.DrawStringAt(0, 4, time_string, &Font24, COLORED);
GerritPathuis 7:25cadf37fd86 163 epd.SetFrameMemory(paint.GetImage(), 80, 72, paint.GetWidth(), paint.GetHeight());
GerritPathuis 7:25cadf37fd86 164 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 165
GerritPathuis 7:25cadf37fd86 166 wait_ms(500);
GerritPathuis 0:665e04c85d8d 167 }
GerritPathuis 0:665e04c85d8d 168
GerritPathuis 7:25cadf37fd86 169 int main()
GerritPathuis 7:25cadf37fd86 170 {
GerritPathuis 8:01db118d1694 171 pc.printf("\n\r\n\r\n\rWaveshare 1.54 inch e-Paper start\n\r");
GerritPathuis 4:8373c3e4f170 172 setup();
GerritPathuis 7:25cadf37fd86 173 pc.printf("Loop\n\r");
GerritPathuis 7:25cadf37fd86 174 loop();
GerritPathuis 7:25cadf37fd86 175 pc.printf("Done\n\r");
GerritPathuis 0:665e04c85d8d 176 while(1) {
GerritPathuis 0:665e04c85d8d 177 myled = 1;
GerritPathuis 0:665e04c85d8d 178 wait(0.2);
GerritPathuis 0:665e04c85d8d 179 myled = 0;
GerritPathuis 0:665e04c85d8d 180 wait(0.2);
GerritPathuis 0:665e04c85d8d 181 }
GerritPathuis 0:665e04c85d8d 182 }
GerritPathuis 0:665e04c85d8d 183