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:40:16 2018 +0000
Revision:
10:08e026240a5f
Parent:
9:9503e1ff98ea
Minor text update

Who changed what in which revision?

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