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:
Sun Mar 25 12:14:55 2018 +0000
Revision:
0:665e04c85d8d
Child:
1:d27a7e06c233
Start point

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