In dit project gaan we data verzamelen uit ons domoticz systeem, en deze data via NODE-Red weergeven op een TFT Display van 320 *480 dpi
Raspberry Pi 3 met Domoticz en Nod Red op geïnstalleerd.
2 oudere projecten (deze projecten zorgen ervoor dat we onze data in Domoticz krijgen.
Dit project is gebaseerd op eerdere projecten om data Via MQTT uit te lezen
Hardware
ESP Wroom 32 ali ESP32 wroom
TFT Display ali Display TFT
Software
Volgende Lib moet geïnstalleerd worden in Arduino IDE ( als je niet weet hoe het moet Google is Your Friend !)
Benodigde Libraries nodig voor dit project !!! (als je de vorige projecten hebt gemaakt zijn deze normaal reeds geïnstalleerd
#include "EspMQTTClient.h"
#include <WiFi.h>
#include <SPI.h>
#include <TFT_eSPI.h>
ESP 32 aansluiten op TFT display !
Na installatie van de Library in IDE moeten we eerst de User_Setup.h instellen voor de Display die we gebruiken.
Normaal moet je dit bestand hier vinden : C:\Users\ASUS\Documents\Arduino\libraries\TFT_eSPI-master
Of bestand eventueel gewoon opzoeken op je PC via het zoekvenster
Eerst de Display instellen, als je display ertussen staat deze lijn // wegdoen.
In dit project gebruik ik een ILI9488 SPI 320*480 display
In het 2e deel van de user setup bepalen we welke CPU we gebruiken, Deze regels // verwijderen.
Belangrijk let ook op dat er geen andere regels de // wegzijn anders gaat dit niet werken !!!!
Dit zijn dus onze verbindingen die we gaan maken .
TFT_MISO 19TFT_MOSI 23TFT_SCLK 18TFT_CS 15 // Chip select control pinTFT_DC 2 // Data Command control pinTFT_RST 4 // Reset pin (could connect to RST pin)Enkele foto's van demo model tot eind resultaat !
Als de kleur verhouding niet juist zijn dit aanpassen !!
/*
Test the tft.print() viz the libraries embedded write() function
This sketch used font 2, 4, 7
Make sure all the required fonts are loaded by editing the
User_Setup.h file in the TFT_eSPI library folder.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
#########################################################################
*/
#include "EspMQTTClient.h"
#include <WiFi.h>
//#include "Free_Fonts.h"
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
const uint8_t MESG_SIZE = 255;
char curMessage1[MESG_SIZE];
char newMessage1[MESG_SIZE];
char curMessage2[MESG_SIZE];
char newMessage2[MESG_SIZE];
char curMessage3[MESG_SIZE];
char newMessage3[MESG_SIZE];
char curMessage4[MESG_SIZE];
char newMessage4[MESG_SIZE];
char curMessage5[MESG_SIZE];
char newMessage5[MESG_SIZE];
char curMessage6[MESG_SIZE];
char newMessage6[MESG_SIZE];
bool newMessageAvailable = false;
EspMQTTClient client(
"Tenda_Spike",
"johanveerle22",
"192.168.1.19", // MQTT Broker server ip
"spike", // Can be omitted if not needed
"1234", // Can be omitted if not needed
"ILI", // Client name that uniquely identify your device
1883 // The MQTT port, default to 1883. this line can be omitted
);
void setup(void) {
Serial.begin(115200);
curMessage1[0] = newMessage1[0] = '\0';
curMessage2[0] = newMessage2[0] = '\0';
curMessage3[0] = newMessage3[0] = '\0';
curMessage4[0] = newMessage4[0] = '\0';
curMessage5[0] = newMessage5[0] = '\0';
curMessage6[0] = newMessage6[0] = '\0';
sprintf(curMessage1, "");
sprintf(curMessage2, "");
sprintf(curMessage3, " 000 ");
sprintf(curMessage4, " 000 ");
sprintf(curMessage5, " 000 ");
sprintf(curMessage6, " 000 ");
tft.init();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
tft.fillRoundRect(0, 0, 480, 28, 10, TFT_YELLOW);
tft.fillRoundRect(20, 40, 210, 54, 10, TFT_BLUE);
tft.fillRoundRect(240, 40, 210, 54, 10, TFT_WHITE);
tft.fillRoundRect(0, 98, 480, 28, 10, TFT_GREEN);
WiFi.mode(WIFI_STA);
/*
tft.fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
Parameterd:
x0:x coordinate of the starting point
y0:y coordinate of the starting point
w:the length of the square
h:the width of the square
radius:the radius of the round corners
color:the color of the square
*/
}
void onConnectionEstablished()
{
client.subscribe("leddisplay6/text", [](const String & payload) { //naam van de gegevens uit node red
sprintf(curMessage1, payload.c_str());
});
client.subscribe("leddisplay5/text", [](const String & payload) {
sprintf(curMessage2, payload.c_str());
});
client.subscribe("leddisplay10/soc", [](const String & payload) {
sprintf(curMessage3, payload.c_str());
});
client.subscribe("leddisplay11/text", [](const String & payload) {
sprintf(curMessage4, payload.c_str());
});
client.subscribe("leddisplay12/text", [](const String & payload) {
sprintf(curMessage5, payload.c_str());
});
client.subscribe("leddisplay13/text", [](const String & payload) {
sprintf(curMessage6, payload.c_str());
});
}
void loop() {
client.loop();
tft.setCursor(100, 2);
tft.setTextColor(TFT_BLACK);
tft.setTextFont(4);
tft.println("Energy Monitor NET");
tft.setCursor(40, 44);
tft.setTextColor(TFT_GREEN,TFT_BLUE);
// tft.setTextColor(TFT_GREEN);
tft.setTextFont(7);
// tft.println(" ");
// tft.setCursor(40, 44);
tft.println(curMessage1);
tft.setCursor(250, 44);
tft.setTextColor(TFT_RED, TFT_WHITE);
// tft.setTextFont(3);
tft.println(curMessage2);
// Set the font colour to be green with black background, set to font 4
tft.setTextFont(2);
tft.setTextColor(TFT_GREEN);
tft.setCursor(30, 26);
tft.print("Export naar Net");
tft.setTextColor(TFT_WHITE);
tft.setCursor(270, 26);
tft.print("Import van Net");
//tft.setTextColor(TFT_BLACK,TFT_GREEN);
tft.setTextColor(TFT_BLACK);
tft.setCursor(85, 100);
tft.setTextFont(4);
tft.println("Energy Monitor BATTERY");
tft.setTextColor(TFT_GREEN,TFT_BLACK);
tft.setTextFont(7);
tft.setCursor(0, 160);
tft.println(curMessage3); //soc
tft.setCursor(0, 250);
tft.println(curMessage6); //Spanning
tft.setCursor(240, 160);
tft.println(curMessage5); // Stroom
tft.setCursor(240, 250);
tft.println(curMessage4); // Power
// info text bij berichten
tft.setTextColor(TFT_WHITE,TFT_BLACK);
tft.setTextFont(4);
tft.setCursor(0, 130);
tft.println("SOC = %");
tft.setCursor(240, 130);
tft.println("Spanning = Volt ");
tft.setCursor(0, 220);
tft.println("Stroom = Amp");
tft.setCursor(240, 220);
tft.println("Power = Watt");
//serial info
Serial.println(curMessage1);
Serial.println(curMessage2);
Serial.println(curMessage3);
Serial.println(curMessage4);
Serial.println(curMessage5);
Serial.println(curMessage6);
tft.setTextFont(1);
tft.setTextColor(TFT_WHITE);
tft.setCursor(0, 310);
tft.print("ip=");
delay(500);
}