2024-12-0400
Ich habe Touchscreen oder SD Card einrichten können. Beides zusammen geht nicht. Schade !!!!
This commit is contained in:
parent
d27e6204b5
commit
8897226d9a
|
@ -15,6 +15,8 @@ float K_HTU= -0.00;
|
|||
struct {
|
||||
char temperature[15] = {0};
|
||||
char humity[15] = {0};
|
||||
float t = 0.0;
|
||||
float h = 0.0;
|
||||
} htuData;
|
||||
|
||||
void init_HTU21(){
|
||||
|
@ -31,29 +33,29 @@ void init_HTU21(){
|
|||
|
||||
}
|
||||
|
||||
float read_HTU21D() {
|
||||
float t = htu.readTemperature();
|
||||
//t = t + KorrekturTemperaturHTU;
|
||||
dtostrf(t,7,1,htuData.temperature);
|
||||
float h = htu.readHumidity();
|
||||
dtostrf(h,7,1,htuData.humity);
|
||||
void read_HTU21D() {
|
||||
htuData.t = htu.readTemperature();
|
||||
//htuData.t = htuData.t + KorrekturTemperaturHTU;
|
||||
dtostrf(htuData.t,7,1,htuData.temperature);
|
||||
htuData.h = htu.readHumidity();
|
||||
dtostrf(htuData.h,7,1,htuData.humity);
|
||||
Serial.print("Temperature (HTU21D):\t");
|
||||
Serial.print(htuData.temperature);
|
||||
Serial.print(" °C\t");
|
||||
tft.drawString("Temperatur: ", 1, x, 4);
|
||||
tft.drawFloat(t, 1.0,190, x,4);
|
||||
tft.drawFloat(htuData.t, 1.0,190, x,4);
|
||||
tft.drawString("o", 252, x, 1);
|
||||
tft.drawString("C", 260, x, 4);
|
||||
|
||||
Serial.println(t,8);
|
||||
Serial.println(htuData.t,8);
|
||||
Serial.print("Luftfeuchtigkeit:\t");
|
||||
Serial.print(htuData.humity);
|
||||
Serial.println(" %");
|
||||
tft.drawString("Luftfeuchtigkeit: ", 1, x +=25, 4);
|
||||
tft.drawFloat(h, 1.0,190, x, 4);
|
||||
tft.drawFloat(htuData.h, 1.0,190, x, 4);
|
||||
tft.drawString("%", 252, x, 4);
|
||||
x = 100;
|
||||
return t;
|
||||
|
||||
}
|
||||
|
||||
void M2M_HTU21D(String deviceId = "4711") {
|
||||
|
|
|
@ -9,7 +9,7 @@ framework = arduino
|
|||
lib_deps =
|
||||
bodmer/TFT_eSPI@^2.5.33
|
||||
;nitek/XPT2046_Bitbang_Slim@^2.0.0
|
||||
;https://github.com/PaulStoffregen/XPT2046_Touchscreen.git#v1.4
|
||||
https://github.com/PaulStoffregen/XPT2046_Touchscreen.git#v1.4
|
||||
adafruit/Adafruit HTU21DF Library @ 1.0.5
|
||||
;wollewald/ADS1115_WE @ 1.4.3
|
||||
adafruit/Adafruit MCP9808 Library @ 2.0.0
|
||||
|
|
207
src/main.cpp
207
src/main.cpp
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <Wire.h>
|
||||
|
||||
#include <XPT2046_Touchscreen.h>
|
||||
|
||||
#include <WiFi.h>
|
||||
//#include <NTPClient.h>
|
||||
//#include <WiFiUdp.h>
|
||||
|
@ -26,9 +28,27 @@ int x = 100;
|
|||
char sID[100];
|
||||
char ausgabe[100];
|
||||
|
||||
// The CYD touch uses some non default
|
||||
// SPI pins
|
||||
|
||||
#define XPT2046_IRQ 36
|
||||
#define XPT2046_MOSI 32
|
||||
#define XPT2046_MISO 39
|
||||
#define XPT2046_CLK 25
|
||||
#define XPT2046_CS 33
|
||||
|
||||
#define SD_SCK 18
|
||||
#define SD_MISO 19
|
||||
#define SD_MOSI 23
|
||||
#define SD_CS 5
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
SPIClass spi2 = SPIClass(VSPI);
|
||||
|
||||
SPIClass mySpi = SPIClass(VSPI);
|
||||
XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ);
|
||||
|
||||
|
||||
#include<mess_htu21.h>
|
||||
#include <mcp9808.h>
|
||||
#include <mess_BMP280.h>
|
||||
|
@ -200,8 +220,16 @@ void testFileIO(fs::FS &fs, const char * path) {
|
|||
}
|
||||
|
||||
// ENDE TEST
|
||||
int WiFiError = 36;
|
||||
int Versuche;
|
||||
|
||||
void setup() {
|
||||
|
||||
//spi2.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
|
||||
/* ts.begin(spi2);
|
||||
ts.setRotation(1); */
|
||||
mySpi.begin(SD_SCK, SD_MISO, SD_MOSI);
|
||||
|
||||
// Start the tft display and set it to black
|
||||
tft.init();
|
||||
tft.setRotation(1); //This is the display in landscape
|
||||
|
@ -217,17 +245,32 @@ void setup() {
|
|||
x = 320 /2;
|
||||
y += 16;
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
tft.drawCentreString("Warte auf verbindung", x, y, fontNum *= 2);printf("");
|
||||
tft.drawCentreString("Warte auf verbindung", x, y, fontNum *= 2);
|
||||
Serial.begin(115200);
|
||||
WiFi.reconnect();printf("");
|
||||
delay( 1 );
|
||||
|
||||
Serial.print("Connecting to ");
|
||||
WiFi.reconnect();
|
||||
delay(10);
|
||||
WiFi.disconnect();
|
||||
delay(10);
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
WiFi.begin(ssid, password);
|
||||
Versuche = 0;
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
Versuche += 1;
|
||||
if(Versuche >= WiFiError){
|
||||
Serial.println();
|
||||
tft.fillScreen(TFT_RED);
|
||||
tft.setTextColor(TFT_BLACK, TFT_WHITE);
|
||||
tft.drawCentreString(" Wlan Stoerung ", 160, 110, fontNum = 4);
|
||||
for(int a = 0; a < 20; a++){
|
||||
tft.invertDisplay(a % 2);
|
||||
delay(500);
|
||||
}
|
||||
WiFi.disconnect();
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
// Print local IP address and start web server
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
@ -235,47 +278,8 @@ Serial.print("Connecting to ");
|
|||
Serial.println("WiFi connected.");
|
||||
Serial.print("IP address: \t");
|
||||
Serial.println(WiFi.localIP());
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
tft.setTextSize(2);
|
||||
tft.println(WiFi.localIP());
|
||||
tft.setTextSize(1);
|
||||
delay(5000);
|
||||
// Initialize a NTPClient to get time
|
||||
//timeClient.begin();
|
||||
// Set offset time in seconds to adjust for your timezone, for example:
|
||||
// GMT +1 = 3600
|
||||
// GMT +8 = 28800
|
||||
// GMT -1 = -3600
|
||||
// GMT 0 = 0
|
||||
//timeClient.setTimeOffset(3600);
|
||||
|
||||
configTime(0, 0, NTP_SERVER);
|
||||
// See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region
|
||||
setenv("TZ", TZ_INFO, 1);
|
||||
|
||||
if (getNTPtime(10)) { // wait up to 10sec to sync
|
||||
} else {
|
||||
Serial.println("Time not set");
|
||||
delay(5000);
|
||||
ESP.restart();
|
||||
}
|
||||
lastNTPtime = time(&now);
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
init_HTU21();
|
||||
init_MCP9808();
|
||||
Init_BMP280();
|
||||
if (F_MCP9808 == true){
|
||||
valTemp = getTemperature_MCP9808();
|
||||
}
|
||||
|
||||
x = 320 /2;
|
||||
y += 32;
|
||||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
|
||||
if (!SD.begin(SS, spi2, 80000000)) {
|
||||
// SD Karte ----------------------------------------
|
||||
if (!SD.begin(SS, mySpi, 80000000)) {
|
||||
Serial.println("Card Mount Failed");
|
||||
return;
|
||||
}
|
||||
|
@ -297,7 +301,7 @@ Serial.print("Connecting to ");
|
|||
Serial.println("UNKNOWN");
|
||||
}
|
||||
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
|
||||
Serial.printf("SD Card Size: %lluMB\n", cardSize);
|
||||
Serial.printf("SD Card Size: %llu MB\n", cardSize);
|
||||
|
||||
listDir(SD, "/", 0);
|
||||
/* createDir(SD, "/mydir");
|
||||
|
@ -306,28 +310,127 @@ Serial.print("Connecting to ");
|
|||
listDir(SD, "/", 2);
|
||||
testFileIO(SD, "/hello.txt");
|
||||
deleteFile(SD, "/hello.txt"); */
|
||||
// ---------------------------------End SD Karte -------------------
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
tft.setTextSize(2);
|
||||
tft.println(WiFi.localIP());
|
||||
tft.setTextSize(1);
|
||||
delay(5000);
|
||||
// Initialize a NTPClient to get time
|
||||
configTime(0, 0, NTP_SERVER);
|
||||
// See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region
|
||||
setenv("TZ", TZ_INFO, 1);
|
||||
|
||||
if (getNTPtime(10)) { // wait up to 10sec to sync
|
||||
} else {
|
||||
Serial.println("Time not set");
|
||||
tft.fillScreen(TFT_RED);
|
||||
tft.setTextColor(TFT_BLACK, TFT_WHITE);
|
||||
tft.drawCentreString(" Stoerung NTP Server ", 160, 110, fontNum = 4);
|
||||
for(int a = 0; a < 20; a++){
|
||||
tft.invertDisplay(a % 2);
|
||||
delay(500);
|
||||
}
|
||||
WiFi.disconnect();
|
||||
ESP.restart();
|
||||
}
|
||||
lastNTPtime = time(&now);
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
init_HTU21();
|
||||
init_MCP9808();
|
||||
Init_BMP280();
|
||||
if (F_MCP9808 == true){
|
||||
valTemp = getTemperature_MCP9808();
|
||||
}
|
||||
|
||||
x = 320 /2;
|
||||
y += 32;
|
||||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
}
|
||||
|
||||
void printTouchToDisplay(TS_Point p) {
|
||||
|
||||
// Clear screen first
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
int x = 320 / 2; // center of display
|
||||
int y = 100;
|
||||
int fontSize = 2;
|
||||
|
||||
String temp = "Pressure = " + String(p.z);
|
||||
tft.drawCentreString(temp, x, y, fontSize);
|
||||
|
||||
y += 16;
|
||||
temp = "X = " + String(p.x);
|
||||
tft.drawCentreString(temp, x, y, fontSize);
|
||||
|
||||
y += 16;
|
||||
temp = "Y = " + String(p.y);
|
||||
tft.drawCentreString(temp, x, y, fontSize);
|
||||
}
|
||||
|
||||
|
||||
void printTouchToSerial(TS_Point p) {
|
||||
Serial.print("Pressure = ");
|
||||
Serial.print(p.z);
|
||||
Serial.print(", x = ");
|
||||
Serial.print(p.x);
|
||||
Serial.print(", y = ");
|
||||
Serial.print(p.y);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printTouchToSerial2(int x, int y, int z) {
|
||||
Serial.print("Pressure = ");
|
||||
Serial.print(z);
|
||||
Serial.print(", x = ");
|
||||
Serial.print(x);
|
||||
Serial.print(", y = ");
|
||||
Serial.print(y);
|
||||
Serial.println();
|
||||
}
|
||||
int Minuten, MintenOld = 99;
|
||||
float test;
|
||||
int ts_x, ts_y, ts_z;
|
||||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 240
|
||||
|
||||
void loop() {
|
||||
|
||||
if (ts.tirqTouched() && ts.touched()) {
|
||||
TS_Point p = ts.getPoint();
|
||||
//printTouchToSerial(p);
|
||||
ts_x = map(p.x, 200, 3700, 1, SCREEN_WIDTH);
|
||||
ts_y = map(p.y, 240, 3800, 1, SCREEN_HEIGHT);
|
||||
ts_z = p.z;
|
||||
printTouchToSerial2(ts_x, ts_y, ts_z);
|
||||
|
||||
if((ts_x >= 300) && (ts_y >= 220)){
|
||||
Serial.printf(" Gefunden bei: %i : %i : %i \t", p.y, p.x, p.z);
|
||||
} else {
|
||||
printTouchToDisplay(p);
|
||||
}
|
||||
|
||||
}
|
||||
getNTPtime(10);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
zeigeZeit(timeinfo, 210, 0);
|
||||
zeigeZeit(timeinfo, 215, 0);
|
||||
Minuten = timeinfo.tm_min;
|
||||
if (Minuten != MintenOld){
|
||||
MintenOld = Minuten;
|
||||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
x = 100;
|
||||
test = read_HTU21D();
|
||||
read_HTU21D();
|
||||
getTemperature_MCP9808();
|
||||
read_BMP_280();
|
||||
if (Minuten % SAVE_INTERVAL == 0){
|
||||
sprintf(ausgabe, "%s;%f\n", szZeit, test);
|
||||
sprintf(ausgabe, "%s;%f;%f\n", szZeit, htuData.t, htuData.h);
|
||||
appendFile(SD, "/daten.csv", ausgabe);
|
||||
Serial.print("SAVE ----> "); Serial.println(szZeit);
|
||||
Serial.print("SAVE ----> "); Serial.println(ausgabe);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,7 +466,7 @@ void showTime(tm localTime) {
|
|||
}
|
||||
|
||||
void zeigeZeit(tm localTime, int x = 0, int y = 0){
|
||||
sprintf(szZeit,"%02d:%02d:%02d\n",
|
||||
sprintf(szZeit,"%02d:%02d:%02d",
|
||||
localTime.tm_hour,
|
||||
localTime.tm_min,
|
||||
localTime.tm_sec);
|
||||
|
|
Loading…
Reference in New Issue
Block a user