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:
Sat Mar 31 08:36:11 2018 +0000
Revision:
9:9503e1ff98ea
Parent:
8:01db118d1694
Child:
10:08e026240a5f
Works as expected

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 9:9503e1ff98ea 27 // The 1.54 Incht E-paper Waveshare software is modified to work on a Kl25Z
GerritPathuis 9:9503e1ff98ea 28 // epaper --------- KL25X
GerritPathuis 9:9503e1ff98ea 29 // BUSY ----------- PTA13
GerritPathuis 9:9503e1ff98ea 30 // RST ------------ PTA17
GerritPathuis 9:9503e1ff98ea 31 // DC ------------- PTD5
GerritPathuis 9:9503e1ff98ea 32 // CS ------------- PTD0
GerritPathuis 9:9503e1ff98ea 33 // CLK ------------ PTD1
GerritPathuis 9:9503e1ff98ea 34 // DIN ------------ PTD2
GerritPathuis 9:9503e1ff98ea 35 // GND ------------ PTE3
GerritPathuis 9:9503e1ff98ea 36 // 3.3V ----------- PTD9
GerritPathuis 9:9503e1ff98ea 37 // NO connection with PTD3
GerritPathuis 9:9503e1ff98ea 38
GerritPathuis 0:665e04c85d8d 39 #include "mbed.h"
GerritPathuis 1:d27a7e06c233 40 #include "epd1in54.h"
GerritPathuis 1:d27a7e06c233 41 #include "epdpaint.h"
GerritPathuis 1:d27a7e06c233 42 #include "epdif.h"
GerritPathuis 0:665e04c85d8d 43 #include "imagedata.h"
GerritPathuis 0:665e04c85d8d 44
GerritPathuis 0:665e04c85d8d 45 #define COLORED 0
GerritPathuis 0:665e04c85d8d 46 #define UNCOLORED 1
GerritPathuis 0:665e04c85d8d 47
GerritPathuis 0:665e04c85d8d 48 Serial pc(USBTX, USBRX, 115200);
GerritPathuis 1:d27a7e06c233 49
GerritPathuis 8:01db118d1694 50 DigitalOut reset_pin(PTA17);
GerritPathuis 6:469fb6b0d26d 51 DigitalOut dc_pin(PTD5);
GerritPathuis 6:469fb6b0d26d 52 DigitalOut cs_pin(PTD0);
GerritPathuis 8:01db118d1694 53 DigitalIn busy_pin(PTA13, PullNone);
GerritPathuis 6:469fb6b0d26d 54 SPI epaper(PTD2,PTD3,PTD1); //MOSI, MISO, CLK
GerritPathuis 8:01db118d1694 55 DigitalOut myled(LED2);
GerritPathuis 9:9503e1ff98ea 56 Timer timer;
GerritPathuis 1:d27a7e06c233 57
GerritPathuis 0:665e04c85d8d 58 /**
GerritPathuis 0:665e04c85d8d 59 * Due to RAM not enough in Arduino UNO, a frame buffer is not allowed.
GerritPathuis 7:25cadf37fd86 60 * In this case, a smaller image buffer is allocated and you have to
GerritPathuis 0:665e04c85d8d 61 * update a partial display several times.
GerritPathuis 0:665e04c85d8d 62 * 1 byte = 8 pixels, therefore you have to set 8*N pixels at a time.
GerritPathuis 0:665e04c85d8d 63 */
GerritPathuis 0:665e04c85d8d 64 unsigned char image[1024];
GerritPathuis 7:25cadf37fd86 65 Paint paint(image, 0, 0); // width should be the multiple of 8
GerritPathuis 0:665e04c85d8d 66 Epd epd;
GerritPathuis 0:665e04c85d8d 67 unsigned long time_start_ms;
GerritPathuis 0:665e04c85d8d 68 unsigned long time_now_s;
GerritPathuis 0:665e04c85d8d 69
GerritPathuis 7:25cadf37fd86 70 void setup()
GerritPathuis 7:25cadf37fd86 71 {
GerritPathuis 7:25cadf37fd86 72 // put your setup code here, to run once:
GerritPathuis 7:25cadf37fd86 73 if (epd.Init(lut_full_update) != 0) {
GerritPathuis 9:9503e1ff98ea 74 pc.printf("e-Paper init failed !!!");
GerritPathuis 7:25cadf37fd86 75 return;
GerritPathuis 7:25cadf37fd86 76 }
GerritPathuis 7:25cadf37fd86 77
GerritPathuis 7:25cadf37fd86 78 /**
GerritPathuis 7:25cadf37fd86 79 * there are 2 memory areas embedded in the e-paper display
GerritPathuis 7:25cadf37fd86 80 * and once the display is refreshed, the memory area will be auto-toggled,
GerritPathuis 7:25cadf37fd86 81 * i.e. the next action of SetFrameMemory will set the other memory area
GerritPathuis 7:25cadf37fd86 82 * therefore you have to clear the frame memory twice.
GerritPathuis 7:25cadf37fd86 83 */
GerritPathuis 0:665e04c85d8d 84
GerritPathuis 7:25cadf37fd86 85 epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
GerritPathuis 7:25cadf37fd86 86 epd.DisplayFrame();
GerritPathuis 7:25cadf37fd86 87 epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
GerritPathuis 7:25cadf37fd86 88 epd.DisplayFrame();
GerritPathuis 7:25cadf37fd86 89
GerritPathuis 7:25cadf37fd86 90 paint.SetRotate(ROTATE_0);
GerritPathuis 7:25cadf37fd86 91 paint.SetWidth(200);
GerritPathuis 7:25cadf37fd86 92 paint.SetHeight(24);
GerritPathuis 0:665e04c85d8d 93
GerritPathuis 7:25cadf37fd86 94 /* For simplicity, the arguments are explicit numerical coordinates */
GerritPathuis 7:25cadf37fd86 95
GerritPathuis 7:25cadf37fd86 96 paint.Clear(COLORED);
GerritPathuis 7:25cadf37fd86 97 paint.DrawStringAt(30, 4, "Hello world!", &Font16, UNCOLORED);
GerritPathuis 7:25cadf37fd86 98 epd.SetFrameMemory(paint.GetImage(), 0, 10, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 99
GerritPathuis 7:25cadf37fd86 100 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 101 paint.DrawStringAt(30, 4, "e-Paper Demo", &Font16, COLORED);
GerritPathuis 7:25cadf37fd86 102 epd.SetFrameMemory(paint.GetImage(), 0, 30, paint.GetWidth(), paint.GetHeight());
GerritPathuis 7:25cadf37fd86 103
GerritPathuis 7:25cadf37fd86 104 paint.SetWidth(64);
GerritPathuis 7:25cadf37fd86 105 paint.SetHeight(64);
GerritPathuis 0:665e04c85d8d 106
GerritPathuis 7:25cadf37fd86 107 pc.printf("Rectangle \n\r");
GerritPathuis 7:25cadf37fd86 108 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 109 paint.DrawRectangle(0, 0, 40, 50, COLORED);
GerritPathuis 7:25cadf37fd86 110 paint.DrawLine(0, 0, 40, 50, COLORED);
GerritPathuis 7:25cadf37fd86 111 paint.DrawLine(40, 0, 0, 50, COLORED);
GerritPathuis 7:25cadf37fd86 112 epd.SetFrameMemory(paint.GetImage(), 16, 60, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 113
GerritPathuis 7:25cadf37fd86 114 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 115 paint.DrawCircle(32, 32, 30, COLORED);
GerritPathuis 7:25cadf37fd86 116 epd.SetFrameMemory(paint.GetImage(), 120, 60, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 117
GerritPathuis 7:25cadf37fd86 118 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 119 paint.DrawFilledRectangle(0, 0, 40, 50, COLORED);
GerritPathuis 7:25cadf37fd86 120 epd.SetFrameMemory(paint.GetImage(), 16, 130, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 121
GerritPathuis 7:25cadf37fd86 122 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 123 paint.DrawFilledCircle(32, 32, 30, COLORED);
GerritPathuis 7:25cadf37fd86 124 epd.SetFrameMemory(paint.GetImage(), 120, 130, paint.GetWidth(), paint.GetHeight());
GerritPathuis 7:25cadf37fd86 125 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 126
GerritPathuis 7:25cadf37fd86 127 wait_ms(2000);
GerritPathuis 0:665e04c85d8d 128
GerritPathuis 7:25cadf37fd86 129 if (epd.Init(lut_partial_update) != 0) {
GerritPathuis 7:25cadf37fd86 130 pc.printf("e-Paper init failed");
GerritPathuis 7:25cadf37fd86 131 return;
GerritPathuis 7:25cadf37fd86 132 }
GerritPathuis 0:665e04c85d8d 133
GerritPathuis 7:25cadf37fd86 134 /**
GerritPathuis 7:25cadf37fd86 135 * there are 2 memory areas embedded in the e-paper display
GerritPathuis 7:25cadf37fd86 136 * and once the display is refreshed, the memory area will be auto-toggled,
GerritPathuis 7:25cadf37fd86 137 * i.e. the next action of SetFrameMemory will set the other memory area
GerritPathuis 7:25cadf37fd86 138 * therefore you have to set the frame memory and refresh the display twice.
GerritPathuis 7:25cadf37fd86 139 */
GerritPathuis 7:25cadf37fd86 140 epd.SetFrameMemory(IMAGE_DATA);
GerritPathuis 7:25cadf37fd86 141 epd.DisplayFrame();
GerritPathuis 7:25cadf37fd86 142 epd.SetFrameMemory(IMAGE_DATA);
GerritPathuis 7:25cadf37fd86 143 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 144
GerritPathuis 9:9503e1ff98ea 145 time_start_ms = timer.read_ms();
GerritPathuis 0:665e04c85d8d 146 }
GerritPathuis 0:665e04c85d8d 147
GerritPathuis 7:25cadf37fd86 148 void loop()
GerritPathuis 7:25cadf37fd86 149 {
GerritPathuis 7:25cadf37fd86 150 // put your main code here, to run repeatedly:
GerritPathuis 9:9503e1ff98ea 151 time_now_s = (timer.read_ms() - time_start_ms) / 1000;
GerritPathuis 7:25cadf37fd86 152 char time_string[] = {'0', '0', ':', '0', '0', '\0'};
GerritPathuis 7:25cadf37fd86 153 time_string[0] = time_now_s / 60 / 10 + '0';
GerritPathuis 7:25cadf37fd86 154 time_string[1] = time_now_s / 60 % 10 + '0';
GerritPathuis 7:25cadf37fd86 155 time_string[3] = time_now_s % 60 / 10 + '0';
GerritPathuis 7:25cadf37fd86 156 time_string[4] = time_now_s % 60 % 10 + '0';
GerritPathuis 0:665e04c85d8d 157
GerritPathuis 7:25cadf37fd86 158 paint.SetWidth(32);
GerritPathuis 7:25cadf37fd86 159 paint.SetHeight(96);
GerritPathuis 7:25cadf37fd86 160 paint.SetRotate(ROTATE_270);
GerritPathuis 0:665e04c85d8d 161
GerritPathuis 7:25cadf37fd86 162 paint.Clear(UNCOLORED);
GerritPathuis 7:25cadf37fd86 163 paint.DrawStringAt(0, 4, time_string, &Font24, COLORED);
GerritPathuis 7:25cadf37fd86 164 epd.SetFrameMemory(paint.GetImage(), 80, 72, paint.GetWidth(), paint.GetHeight());
GerritPathuis 7:25cadf37fd86 165 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 166 }
GerritPathuis 0:665e04c85d8d 167
GerritPathuis 7:25cadf37fd86 168 int main()
GerritPathuis 7:25cadf37fd86 169 {
GerritPathuis 9:9503e1ff98ea 170 timer.start();
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 9:9503e1ff98ea 173
GerritPathuis 0:665e04c85d8d 174 while(1) {
GerritPathuis 9:9503e1ff98ea 175 loop();
GerritPathuis 0:665e04c85d8d 176 myled = 1;
GerritPathuis 9:9503e1ff98ea 177 wait(0.5);
GerritPathuis 0:665e04c85d8d 178 myled = 0;
GerritPathuis 9:9503e1ff98ea 179 wait(0.5);
GerritPathuis 0:665e04c85d8d 180 }
GerritPathuis 9:9503e1ff98ea 181
GerritPathuis 0:665e04c85d8d 182 }
GerritPathuis 0:665e04c85d8d 183