Basic example showing how to use the ePaper Display (ePD) present on the STM32L053 Discovery (STM32L0538-DISCO) board.

Dependencies:   EPD_GDE021A1 lib_dht22 mbed

Fork of DISCO-L053C8_ePD_demo by ST

Committer:
lamyaezerrouki
Date:
Tue Oct 04 12:05:18 2016 +0000
Revision:
2:a78e4e7d9be2
Parent:
0:e5732175b08b
Debut

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:e5732175b08b 1 #include "mbed.h"
bcostm 0:e5732175b08b 2 #include "EPD_GDE021A1.h"
lamyaezerrouki 2:a78e4e7d9be2 3 #include "dht22.h"
bcostm 0:e5732175b08b 4
bcostm 0:e5732175b08b 5 #define EPD_CS PA_15
bcostm 0:e5732175b08b 6 #define EPD_DC PB_11
bcostm 0:e5732175b08b 7 #define EPD_RESET PB_2
bcostm 0:e5732175b08b 8 #define EPD_BUSY PA_8
bcostm 0:e5732175b08b 9 #define EPD_POWER PB_10
bcostm 0:e5732175b08b 10 #define EPD_SPI_MOSI PB_5
bcostm 0:e5732175b08b 11 #define EPD_SPI_MISO PB_4
bcostm 0:e5732175b08b 12 #define EPD_SPI_SCK PB_3
lamyaezerrouki 2:a78e4e7d9be2 13 #define PTB18 PC_15
bcostm 0:e5732175b08b 14
bcostm 0:e5732175b08b 15 EPD_GDE021A1 epd(EPD_CS, EPD_DC, EPD_RESET, EPD_BUSY, EPD_POWER, EPD_SPI_MOSI, EPD_SPI_MISO, EPD_SPI_SCK);
bcostm 0:e5732175b08b 16
bcostm 0:e5732175b08b 17 DigitalOut led1(LED1);
lamyaezerrouki 2:a78e4e7d9be2 18 DigitalOut led2(LED2);
lamyaezerrouki 2:a78e4e7d9be2 19
lamyaezerrouki 2:a78e4e7d9be2 20 Serial host(USBTX, USBRX);
lamyaezerrouki 2:a78e4e7d9be2 21 DHT22 dht22(PTB18);
bcostm 0:e5732175b08b 22
bcostm 0:e5732175b08b 23 //width 48
bcostm 0:e5732175b08b 24 //height 26
bcostm 0:e5732175b08b 25 static uint8_t Battery_img[] = {
bcostm 0:e5732175b08b 26 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
bcostm 0:e5732175b08b 27 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
bcostm 0:e5732175b08b 28 0xfe, 0xff, 0xff, 0xff, 0xff, 0x0f,
bcostm 0:e5732175b08b 29 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x0c,
bcostm 0:e5732175b08b 30 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 31 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 32 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 33 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 34 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x18,
bcostm 0:e5732175b08b 35 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 36 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 37 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 38 0xfe, 0xff, 0xff, 0x3f, 0xff, 0x39,
bcostm 0:e5732175b08b 39 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 40 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 41 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 42 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x38,
bcostm 0:e5732175b08b 43 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x18,
bcostm 0:e5732175b08b 44 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 45 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 46 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 47 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x0c,
bcostm 0:e5732175b08b 48 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x0c,
bcostm 0:e5732175b08b 49 0xfe, 0xff, 0xff, 0xff, 0xff, 0x0f,
bcostm 0:e5732175b08b 50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
bcostm 0:e5732175b08b 51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
bcostm 0:e5732175b08b 52 };
bcostm 0:e5732175b08b 53
bcostm 0:e5732175b08b 54 int main()
bcostm 0:e5732175b08b 55 {
bcostm 0:e5732175b08b 56 led1 = 1;
lamyaezerrouki 2:a78e4e7d9be2 57 DHT22_data_t dht22_data;
bcostm 0:e5732175b08b 58
bcostm 0:e5732175b08b 59 epd.Clear(EPD_COLOR_WHITE);
bcostm 0:e5732175b08b 60 epd.DisplayStringAtLine(5, (uint8_t*)"MBED", CENTER_MODE);
bcostm 0:e5732175b08b 61 epd.DisplayStringAtLine(3, (uint8_t*)"Epaper display", LEFT_MODE);
bcostm 0:e5732175b08b 62 epd.DisplayStringAtLine(2, (uint8_t*)"demo", LEFT_MODE);
bcostm 0:e5732175b08b 63 epd.DrawImage(130, 0, 48, 26, Battery_img);
bcostm 0:e5732175b08b 64 epd.DrawRect(50, 4, 60, 4);
bcostm 0:e5732175b08b 65 epd.RefreshDisplay();
lamyaezerrouki 2:a78e4e7d9be2 66 wait(1);
bcostm 0:e5732175b08b 67
bcostm 0:e5732175b08b 68 while(1) {
lamyaezerrouki 2:a78e4e7d9be2 69 led1 = 1;
lamyaezerrouki 2:a78e4e7d9be2 70 wait_ms(500);
lamyaezerrouki 2:a78e4e7d9be2 71
lamyaezerrouki 2:a78e4e7d9be2 72 dht22.read(&dht22_data);
lamyaezerrouki 2:a78e4e7d9be2 73
lamyaezerrouki 2:a78e4e7d9be2 74 float temperature = dht22_data.temp / 10.0f;
lamyaezerrouki 2:a78e4e7d9be2 75 float humidity = dht22_data.humidity / 10.0f;
lamyaezerrouki 2:a78e4e7d9be2 76
lamyaezerrouki 2:a78e4e7d9be2 77 host.printf("Temperature: %2.2f Humidity: %2.2f%%\r\n", temperature, humidity);
lamyaezerrouki 2:a78e4e7d9be2 78 wait_ms(500);
lamyaezerrouki 2:a78e4e7d9be2 79
lamyaezerrouki 2:a78e4e7d9be2 80 char str1[5], str2[5];
lamyaezerrouki 2:a78e4e7d9be2 81 sprintf(str1, "%.1f", temperature);
lamyaezerrouki 2:a78e4e7d9be2 82 sprintf(str2, "%.1f", humidity);
lamyaezerrouki 2:a78e4e7d9be2 83
lamyaezerrouki 2:a78e4e7d9be2 84 led1 = 0;
lamyaezerrouki 2:a78e4e7d9be2 85 led2 = 1;
lamyaezerrouki 2:a78e4e7d9be2 86
lamyaezerrouki 2:a78e4e7d9be2 87 epd.Clear(EPD_COLOR_WHITE);
lamyaezerrouki 2:a78e4e7d9be2 88 epd.DisplayStringAtLine(5, (uint8_t*)"Adrien", CENTER_MODE);
lamyaezerrouki 2:a78e4e7d9be2 89 epd.DisplayStringAtLine(3, (uint8_t*)"Temperature: ", LEFT_MODE);
lamyaezerrouki 2:a78e4e7d9be2 90 epd.DisplayStringAtLine(3, (uint8_t*)str1, RIGHT_MODE);
lamyaezerrouki 2:a78e4e7d9be2 91 epd.DisplayStringAtLine(2, (uint8_t*)"Humidity: ", LEFT_MODE);
lamyaezerrouki 2:a78e4e7d9be2 92 epd.DisplayStringAtLine(2, (uint8_t*)str2, RIGHT_MODE);
lamyaezerrouki 2:a78e4e7d9be2 93 epd.RefreshDisplay();
lamyaezerrouki 2:a78e4e7d9be2 94
lamyaezerrouki 2:a78e4e7d9be2 95 led2 = 0;
lamyaezerrouki 2:a78e4e7d9be2 96 wait_ms(500);
bcostm 0:e5732175b08b 97 }
bcostm 0:e5732175b08b 98 }