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:
Wed Mar 28 09:21:33 2018 +0000
Revision:
6:469fb6b0d26d
Parent:
4:8373c3e4f170
Child:
7:25cadf37fd86
Compilation succes

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 6:469fb6b0d26d 38 DigitalOut reset_pin(PTC17);
GerritPathuis 6:469fb6b0d26d 39 DigitalOut dc_pin(PTD5);
GerritPathuis 6:469fb6b0d26d 40 DigitalOut cs_pin(PTD0);
GerritPathuis 6:469fb6b0d26d 41 DigitalIn busy_pin(PTA13);
GerritPathuis 6:469fb6b0d26d 42 SPI epaper(PTD2,PTD3,PTD1); //MOSI, MISO, CLK
GerritPathuis 0:665e04c85d8d 43 DigitalOut myled(LED1);
GerritPathuis 0:665e04c85d8d 44
GerritPathuis 1:d27a7e06c233 45 // See --- epdif.h ---
GerritPathuis 1:d27a7e06c233 46 DigitalOut pins_out[] = {PTC17, PTD5, PTD0}; //reset_pin, dc_pin, cs_pin
GerritPathuis 1:d27a7e06c233 47 DigitalIn pins_in[] = {PTA13}; //busy pin
GerritPathuis 1:d27a7e06c233 48
GerritPathuis 0:665e04c85d8d 49 /**
GerritPathuis 0:665e04c85d8d 50 * Due to RAM not enough in Arduino UNO, a frame buffer is not allowed.
GerritPathuis 0:665e04c85d8d 51 * In this case, a smaller image buffer is allocated and you have to
GerritPathuis 0:665e04c85d8d 52 * update a partial display several times.
GerritPathuis 0:665e04c85d8d 53 * 1 byte = 8 pixels, therefore you have to set 8*N pixels at a time.
GerritPathuis 0:665e04c85d8d 54 */
GerritPathuis 0:665e04c85d8d 55 unsigned char image[1024];
GerritPathuis 0:665e04c85d8d 56 Paint paint(image, 0, 0); // width should be the multiple of 8
GerritPathuis 0:665e04c85d8d 57 Epd epd;
GerritPathuis 0:665e04c85d8d 58 unsigned long time_start_ms;
GerritPathuis 0:665e04c85d8d 59 unsigned long time_now_s;
GerritPathuis 0:665e04c85d8d 60
GerritPathuis 0:665e04c85d8d 61 void setup() {
GerritPathuis 0:665e04c85d8d 62 // put your setup code here, to run once:
GerritPathuis 3:e4399b5ceb4b 63 pc.baud(9600);
GerritPathuis 0:665e04c85d8d 64 if (epd.Init(lut_full_update) != 0) {
GerritPathuis 3:e4399b5ceb4b 65 pc.printf("e-Paper init failed");
GerritPathuis 0:665e04c85d8d 66 return;
GerritPathuis 0:665e04c85d8d 67 }
GerritPathuis 0:665e04c85d8d 68
GerritPathuis 0:665e04c85d8d 69 /**
GerritPathuis 0:665e04c85d8d 70 * there are 2 memory areas embedded in the e-paper display
GerritPathuis 0:665e04c85d8d 71 * and once the display is refreshed, the memory area will be auto-toggled,
GerritPathuis 0:665e04c85d8d 72 * i.e. the next action of SetFrameMemory will set the other memory area
GerritPathuis 0:665e04c85d8d 73 * therefore you have to clear the frame memory twice.
GerritPathuis 0:665e04c85d8d 74 */
GerritPathuis 0:665e04c85d8d 75 epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
GerritPathuis 0:665e04c85d8d 76 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 77 epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
GerritPathuis 0:665e04c85d8d 78 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 79
GerritPathuis 0:665e04c85d8d 80 paint.SetRotate(ROTATE_0);
GerritPathuis 0:665e04c85d8d 81 paint.SetWidth(200);
GerritPathuis 0:665e04c85d8d 82 paint.SetHeight(24);
GerritPathuis 0:665e04c85d8d 83
GerritPathuis 0:665e04c85d8d 84 /* For simplicity, the arguments are explicit numerical coordinates */
GerritPathuis 0:665e04c85d8d 85 paint.Clear(COLORED);
GerritPathuis 0:665e04c85d8d 86 paint.DrawStringAt(30, 4, "Hello world!", &Font16, UNCOLORED);
GerritPathuis 0:665e04c85d8d 87 epd.SetFrameMemory(paint.GetImage(), 0, 10, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 88
GerritPathuis 0:665e04c85d8d 89 paint.Clear(UNCOLORED);
GerritPathuis 0:665e04c85d8d 90 paint.DrawStringAt(30, 4, "e-Paper Demo", &Font16, COLORED);
GerritPathuis 0:665e04c85d8d 91 epd.SetFrameMemory(paint.GetImage(), 0, 30, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 92
GerritPathuis 0:665e04c85d8d 93 paint.SetWidth(64);
GerritPathuis 0:665e04c85d8d 94 paint.SetHeight(64);
GerritPathuis 0:665e04c85d8d 95
GerritPathuis 0:665e04c85d8d 96 paint.Clear(UNCOLORED);
GerritPathuis 0:665e04c85d8d 97 paint.DrawRectangle(0, 0, 40, 50, COLORED);
GerritPathuis 0:665e04c85d8d 98 paint.DrawLine(0, 0, 40, 50, COLORED);
GerritPathuis 0:665e04c85d8d 99 paint.DrawLine(40, 0, 0, 50, COLORED);
GerritPathuis 0:665e04c85d8d 100 epd.SetFrameMemory(paint.GetImage(), 16, 60, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 101
GerritPathuis 0:665e04c85d8d 102 paint.Clear(UNCOLORED);
GerritPathuis 0:665e04c85d8d 103 paint.DrawCircle(32, 32, 30, COLORED);
GerritPathuis 0:665e04c85d8d 104 epd.SetFrameMemory(paint.GetImage(), 120, 60, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 105
GerritPathuis 0:665e04c85d8d 106 paint.Clear(UNCOLORED);
GerritPathuis 0:665e04c85d8d 107 paint.DrawFilledRectangle(0, 0, 40, 50, COLORED);
GerritPathuis 0:665e04c85d8d 108 epd.SetFrameMemory(paint.GetImage(), 16, 130, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 109
GerritPathuis 0:665e04c85d8d 110 paint.Clear(UNCOLORED);
GerritPathuis 0:665e04c85d8d 111 paint.DrawFilledCircle(32, 32, 30, COLORED);
GerritPathuis 0:665e04c85d8d 112 epd.SetFrameMemory(paint.GetImage(), 120, 130, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 113 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 114
GerritPathuis 0:665e04c85d8d 115 wait_ms(2000);
GerritPathuis 0:665e04c85d8d 116
GerritPathuis 0:665e04c85d8d 117 if (epd.Init(lut_partial_update) != 0) {
GerritPathuis 3:e4399b5ceb4b 118 pc.printf("e-Paper init failed");
GerritPathuis 0:665e04c85d8d 119 return;
GerritPathuis 0:665e04c85d8d 120 }
GerritPathuis 0:665e04c85d8d 121
GerritPathuis 0:665e04c85d8d 122 /**
GerritPathuis 0:665e04c85d8d 123 * there are 2 memory areas embedded in the e-paper display
GerritPathuis 0:665e04c85d8d 124 * and once the display is refreshed, the memory area will be auto-toggled,
GerritPathuis 0:665e04c85d8d 125 * i.e. the next action of SetFrameMemory will set the other memory area
GerritPathuis 0:665e04c85d8d 126 * therefore you have to set the frame memory and refresh the display twice.
GerritPathuis 0:665e04c85d8d 127 */
GerritPathuis 0:665e04c85d8d 128 epd.SetFrameMemory(IMAGE_DATA);
GerritPathuis 0:665e04c85d8d 129 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 130 epd.SetFrameMemory(IMAGE_DATA);
GerritPathuis 0:665e04c85d8d 131 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 132
GerritPathuis 4:8373c3e4f170 133 //time_start_ms = millis();
GerritPathuis 4:8373c3e4f170 134 time_start_ms = 0;
GerritPathuis 0:665e04c85d8d 135 }
GerritPathuis 0:665e04c85d8d 136
GerritPathuis 0:665e04c85d8d 137 void loop() {
GerritPathuis 0:665e04c85d8d 138 // put your main code here, to run repeatedly:
GerritPathuis 4:8373c3e4f170 139 //time_now_s = (millis() - time_start_ms) / 1000;
GerritPathuis 4:8373c3e4f170 140 time_now_s = 999;
GerritPathuis 0:665e04c85d8d 141 char time_string[] = {'0', '0', ':', '0', '0', '\0'};
GerritPathuis 0:665e04c85d8d 142 time_string[0] = time_now_s / 60 / 10 + '0';
GerritPathuis 0:665e04c85d8d 143 time_string[1] = time_now_s / 60 % 10 + '0';
GerritPathuis 0:665e04c85d8d 144 time_string[3] = time_now_s % 60 / 10 + '0';
GerritPathuis 0:665e04c85d8d 145 time_string[4] = time_now_s % 60 % 10 + '0';
GerritPathuis 0:665e04c85d8d 146
GerritPathuis 0:665e04c85d8d 147 paint.SetWidth(32);
GerritPathuis 0:665e04c85d8d 148 paint.SetHeight(96);
GerritPathuis 0:665e04c85d8d 149 paint.SetRotate(ROTATE_270);
GerritPathuis 0:665e04c85d8d 150
GerritPathuis 0:665e04c85d8d 151 paint.Clear(UNCOLORED);
GerritPathuis 0:665e04c85d8d 152 paint.DrawStringAt(0, 4, time_string, &Font24, COLORED);
GerritPathuis 0:665e04c85d8d 153 epd.SetFrameMemory(paint.GetImage(), 80, 72, paint.GetWidth(), paint.GetHeight());
GerritPathuis 0:665e04c85d8d 154 epd.DisplayFrame();
GerritPathuis 0:665e04c85d8d 155
GerritPathuis 0:665e04c85d8d 156 wait_ms(500);
GerritPathuis 0:665e04c85d8d 157 }
GerritPathuis 0:665e04c85d8d 158
GerritPathuis 0:665e04c85d8d 159 int main() {
GerritPathuis 4:8373c3e4f170 160 setup();
GerritPathuis 0:665e04c85d8d 161
GerritPathuis 0:665e04c85d8d 162 while(1) {
GerritPathuis 0:665e04c85d8d 163 myled = 1;
GerritPathuis 0:665e04c85d8d 164 wait(0.2);
GerritPathuis 0:665e04c85d8d 165 myled = 0;
GerritPathuis 0:665e04c85d8d 166 wait(0.2);
GerritPathuis 0:665e04c85d8d 167 }
GerritPathuis 0:665e04c85d8d 168 }
GerritPathuis 0:665e04c85d8d 169