Specyfikacja
- Napięcie zasilania: 3,3 V
- Moc zasilania (przy odświeżaniu ekranu): 26,4 mW
- Interfejs: SPI
- Poziom szarości: 2
- Wymiary zewnętrzne: 103 x 78,5 mm
- Wymiary wyświetlacza: 84,8 x 63,6 mm
- Piksel: 0,212 x 0,212 mm
- Rozdzielczość: 400 x 300 px
- Kąt widzenia: 170 °
ARDUINO
Łączenie dla ESP32, ESP32C3-mini
e-Paper | OPIS | ESP32 | ESP32C3-mini | KOLOR |
---|---|---|---|---|
VCC | 3.3V~5V | 3.3V | 3.3V | szary |
GND | Ground | GND | GND | brązowy |
DIN | SPI MOSI pin | GPIO 23 | GPIO 6 | niebieski |
CLK | SPI SCK pin | GPIO 18 | GPIO 4 | żółty |
CS | SPI chip selection, low active | GPIO 5 | GPIO 10 | pomarańczowy |
DC | Data/Command selection (high for data, low for command) | GPIO 17 | GPIO 9 | zielony |
RST | External reset, low active | GPIO 16 | GPIO 8 | biały |
BUSY | Busy status output, low active | GPIO 4 | GPIO 2 | fiolet |
- Biblioteka na github
Łączenie dla ESP8266 D1 mini.
- BUSY -> D2, fiolet
- RST -> D4, biały // odłączyć podczas programowania D1 mini
- DC -> D3, zielony
- CS -> D8, pomarańczowy
- CLK -> D5, żółty
- DIN -> D7, niebieski
- GND -> GND, brązowy
- 3.3V -> 3.3V, szary
Przykładowy KOD dla Arduino
Poniżej program, który wysyła zapytanie do serwera Flask i odbiera dane, które następnie wyświetla. Program łączy się z siecią WiFi. Kod dla ESP32 i ESP32C3-mini. Mini kompiluje się dobrze wpisując płytkę o nazwie Geekble Mini ESP32-C3. Dla ESP32 DOIT – ESP32 DEVKIT V1. Obie platformy sprawdzone, działają z e-Paper 4.2 znakomicie.
plik config.h wyglądać może tak:
#ifndef CONFIG_H
#define CONFIG_H
#define STASSID "nazwa_sieci"
#define STAPSK "hasło"
const char* server_address = “http://192.168.1.1xx:8080/epd”;
const char* host = “192.168.1.1xx”;
const uint16_t port = 8080;
#endif
#include <GxEPD.h>
#include <GxGDEW042T2/GxGDEW042T2.h> // 4.2" b/w
// FreeFonts from Adafruit_GFX
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeMonoBold24pt7b.h>
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
#include <GxIO/GxIO.h>
#include "config.h"
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#define USE_SERIAL Serial
// Dla esp32
// GxIO_Class io(SPI, SS, 17, 16);
// GxEPD_Class display(io, 16, 4);
// Dla esp32C3-mini
GxIO_Class io(SPI, /*CS=*/10, /*DC=*/9, /*RST=*/8);
GxEPD_Class display(io, /*RST=*/8, /*BUSY=*/2);
// WiFi
WiFiMulti wifiMulti;
const char* ssid = STASSID;
const char* password = STAPSK;
// Dane
struct epd {
String BknT = "00.01";
String SlnT = "00.02";
String IwnT = "00.03";
};
epd dataEPD;
struct package {
float temp = 0.0;
float hum = 0.0;
float pres = 0.0;
float light = 0.0;
float batt = 0.0;
char flag1 = 'x';
char flag2 = 'x';
};
typedef struct package Package;
Package data;
// Bufor i licznik
char buffer[80];
// ---------- FUNKCJE ----------
void printItOnEPD42(const String& text, const GFXfont* f, int16_t x, int16_t y) {
display.setTextColor(GxEPD_BLACK);
display.setFont(f);
display.setCursor(x, y);
display.print(text);
}
String usunPolskieLitery(String myString) {
myString.replace("ą", "a");
myString.replace("ć", "c");
myString.replace("ę", "e");
myString.replace("ł", "l");
myString.replace("ń", "n");
myString.replace("ó", "oo");
myString.replace("ś", "s");
myString.replace("ź", "z");
myString.replace("ż", "z");
return myString;
}
String ip2Str(IPAddress ip) {
String s = "";
for (int i = 0; i < 4; i++) {
s += (i ? "." : "") + String(ip[i]);
}
return s;
}
void sendToServer() {
USE_SERIAL.print("Łączenie z serwerem ");
USE_SERIAL.print(host);
USE_SERIAL.print(':');
USE_SERIAL.println(port);
WiFiClient client;
if (!client.connect(host, port)) {
USE_SERIAL.println("Połączenie nieudane");
delay(5000);
return;
}
USE_SERIAL.println("Wysyłanie danych do serwera");
client.println("EPD: OK ---->");
unsigned long timeout = millis();
size_t i = 0;
memset(buffer, 0, sizeof(buffer));
while (client.available() == 0) {
if (millis() - timeout > 5000) {
USE_SERIAL.println(">>> Timeout klienta!");
client.stop();
return;
}
}
while (client.available()) {
char ch = static_cast<char>(client.read());
if (i < sizeof(buffer) - 1) {
buffer[i++] = ch;
}
}
buffer[i] = '\0';
USE_SERIAL.println("Zamykam połączenie");
client.stop();
USE_SERIAL.print("Buffer: ");
USE_SERIAL.println(buffer);
display.fillScreen(GxEPD_WHITE);
printItOnEPD42(buffer, &FreeMonoBold18pt7b, 0, 80);
display.update();
}
String server_GET() {
if (wifiMulti.run() == WL_CONNECTED) {
HTTPClient http;
USE_SERIAL.println("[HTTP] begin...");
http.begin(server_address);
USE_SERIAL.println("[HTTP] GET...");
int httpCode = http.GET();
if (httpCode > 0) {
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
http.end();
return payload;
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
return "Brak odpowiedzi";
}
void FilenameShown() {
Serial.println("\t=======================================");
printf("\n\tNazwa pliku: %s\n\tData i czas kompilacji: %s, %s\n", __FILE__, __DATE__, __TIME__);
Serial.print("\tMAC: ");
Serial.println(WiFi.macAddress());
Serial.println("\t=======================================\n");
}
// ---------- SETUP / LOOP ----------
void setup() {
Serial.begin(115200);
display.init(115200);
wifiMulti.addAP(ssid, password);
while (wifiMulti.run() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
IPAddress ipaddr = WiFi.localIP();
Serial.println();
Serial.println("WiFi connected.");
Serial.print("IP address: ");
Serial.println(ipaddr);
FilenameShown();
display.fillScreen(GxEPD_WHITE);
printItOnEPD42("WiFi connected.", &FreeMonoBold9pt7b, 20, 283);
printItOnEPD42(ip2Str(ipaddr), &FreeMonoBold9pt7b, 200, 283);
display.update();
}
void loop() {
String request = server_GET();
USE_SERIAL.print("Odpowiedź z serwera: ");
USE_SERIAL.println(request);
display.fillScreen(GxEPD_WHITE);
printItOnEPD42(request, &FreeMonoBold12pt7b, 0, 20);
display.update();
delay(20000);
}
MICROPYTHON
UWAGA! Biblioteka MicroPython, której użyłem pozwala wyświetlać tekst tylko wysokości 8 pikseli. Nie znalazłem żadnej innej biblioteki MicroPython, która umożliwiałaby wyświetlenie tekstu większego. To praktycznie eliminuje użycie e-Paper Module 4in2 jako wyświetlacza temperatury, wilgotności itp.
Więcej informacji: https://docs.micropython.org/en/latest/library/framebuf.html
Przydatne linki
- e-Papier WaveShare 4.3″ (e-Ink) / Jarzebski
- e-paper po polsku
- Forum Arduino dot. biblioteki
- Wiki