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:
Mon Mar 26 17:20:56 2018 +0000
Revision:
1:d27a7e06c233
Parent:
0:665e04c85d8d
Child:
2:d7fc318a1528
Tussenstand

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