1 | /////////////////////////////////////////////////////////////////
|
2 | // ESP32 E-PAPER THERMOMETER 10/22/2020 v1.01 //
|
3 | // Get the latest version of the code here: //
|
4 | // http://educ8s.tv/esp32-e-paper-thermometer //
|
5 | /////////////////////////////////////////////////////////////////
|
6 |
|
7 | #include <GxEPD.h>
|
8 | #include <GxGDEP015OC1/GxGDEP015OC1.h>
|
9 | #include <GxIO/GxIO_SPI/GxIO_SPI.h>
|
10 | #include <GxIO/GxIO.h>
|
11 |
|
12 | #include <OneWire.h>
|
13 | #include <DallasTemperature.h>
|
14 | #include "BitmapGraphics.h"
|
15 |
|
16 | #include <Fonts/FreeSansBold24pt7b.h>
|
17 |
|
18 | #define ONE_WIRE_BUS 15
|
19 |
|
20 | boolean METRIC = true; //Set true for metric system; false for imperial
|
21 | float previousTemperature = -100.0;
|
22 | float temperature = 0;
|
23 |
|
24 | OneWire oneWire(ONE_WIRE_BUS);
|
25 | DallasTemperature sensors(&oneWire);
|
26 |
|
27 | GxIO_Class io(SPI, SS, 22, 21);
|
28 | GxEPD_Class display(io, 16, 4);
|
29 |
|
30 | void setup() {
|
31 |
|
32 | Serial.begin(9600);
|
33 | display.init();
|
34 | sensors.begin();
|
35 |
|
36 | display.drawExampleBitmap(gImage_splash, 0, 0, 200, 200, GxEPD_BLACK);
|
37 | display.update();
|
38 | delay(3000);
|
39 |
|
40 | if(METRIC)
|
41 | {
|
42 | display.drawExampleBitmap(gImage_gui, 0, 0, 200, 200, GxEPD_BLACK);
|
43 | }else
|
44 | {
|
45 | display.drawExampleBitmap(gImage_gui_f, 0, 0, 200, 200, GxEPD_BLACK);
|
46 | }
|
47 |
|
48 | display.update();
|
49 |
|
50 | if(METRIC)
|
51 | {
|
52 | display.drawExampleBitmap(gImage_gui, sizeof(gImage_gui), GxEPD::bm_default | GxEPD::bm_partial_update);
|
53 | }else
|
54 | {
|
55 | display.drawExampleBitmap(gImage_gui_f, sizeof(gImage_gui_f), GxEPD::bm_default | GxEPD::bm_partial_update);
|
56 | }
|
57 | }
|
58 |
|
59 | void loop()
|
60 | {
|
61 | previousTemperature = temperature;
|
62 | temperature = getTemperatureFromSensor();
|
63 |
|
64 | if(previousTemperature!=temperature)
|
65 | {
|
66 | showPartialUpdate(temperature);
|
67 | }
|
68 |
|
69 | printTemperatureToSerial();
|
70 | delay(5000);
|
71 | }
|
72 |
|
73 | float getTemperatureFromSensor()
|
74 | {
|
75 | float temperature = 0;
|
76 | sensors.requestTemperatures();
|
77 | if(METRIC)
|
78 | {
|
79 | temperature = sensors.getTempCByIndex(0);
|
80 | }else
|
81 | {
|
82 | temperature = sensors.getTempFByIndex(0);
|
83 | }
|
84 | temperature = round(temperature * 10) / 10;
|
85 | return temperature;
|
86 | }
|
87 |
|
88 | void showPartialUpdate(float temperature)
|
89 | {
|
90 | Serial.println("Updating display ...");
|
91 | String temperatureString = String(temperature,1);
|
92 | const char* name = "FreeSansBold24pt7b";
|
93 | const GFXfont* f = &FreeSansBold24pt7b;
|
94 |
|
95 | uint16_t box_x = 60;
|
96 | uint16_t box_y = 60;
|
97 | uint16_t box_w = 90;
|
98 | uint16_t box_h = 100;
|
99 | uint16_t cursor_y = box_y + 16;
|
100 |
|
101 | display.setRotation(45);
|
102 | display.setFont(f);
|
103 | display.setTextColor(GxEPD_BLACK);
|
104 |
|
105 | display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
|
106 | display.setCursor(box_x, cursor_y+38);
|
107 | display.print(temperatureString);
|
108 | display.updateWindow(box_x, box_y, box_w, box_h, true);
|
109 | }
|
110 |
|
111 | void printTemperatureToSerial()
|
112 | {
|
113 | Serial.print(temperature);
|
114 | Serial.print(" C");
|
115 | Serial.print("\n");
|
116 | }
|