2024-12-0400

This commit is contained in:
hans-jurgen 2024-12-04 01:04:02 +01:00
parent d5c42db02f
commit 00bfee25f5
2 changed files with 152 additions and 52 deletions

View File

@ -13,6 +13,7 @@ platform = espressif32
board = lolin32
framework = arduino
monitor_speed=115200
monitor_filters=time
lib_deps =
# The exact version
adafruit/Adafruit MAX31865 library @ 1.6.2

View File

@ -46,6 +46,7 @@ int LED_Blue = 2;
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
@ -56,6 +57,67 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
const char* ssid = "MagentaWLAN-RGDO";
const char* password = "93329248424922704583";
const char* NTP_SERVER = "de.pool.ntp.org";
const char* TZ_INFO = "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00"; // enter your time zone (https://remotemonitoringsystems.ca/time-zone-abbreviations.php)
tm timeinfo;
time_t now;
long unsigned lastNTPtime;
unsigned long lastEntryTime;
char szZeit[20];
bool getNTPtime(int sec) {
{
uint32_t start = millis();
do {
time(&now);
localtime_r(&now, &timeinfo);
delay(10);
} while (((millis() - start) <= (1000 * sec)) && (timeinfo.tm_year < (2016 - 1900)));
if (timeinfo.tm_year <= (2016 - 1900)) return false; // the NTP call was not successful
}
return true;
}
void showTime(tm localTime) {
Serial.printf(
"%04d-%02d-%02d %02d:%02d:%02d, day %d, %s time\n",
localTime.tm_year + 1900,
localTime.tm_mon + 1,
localTime.tm_mday,
localTime.tm_hour,
localTime.tm_min,
localTime.tm_sec,
(localTime.tm_wday > 0 ? localTime.tm_wday : 7 ),
(localTime.tm_isdst == 1 ? "summer" : "standard")
);
}
void zeigeZeit(tm localTime){
//Serial.printf(" Zeit: %s", szZeit); // Nur zum testen ....
display.setCursor(0,20); // Zeile 2
display.setTextSize(1);
// Alten Inhalt löschen....................
display.setTextColor(BLACK);
display.println(szZeit);
// Jetzt neu schreiben ....................
display.setCursor(0,20); // Zeile 2
display.setTextColor(WHITE);
sprintf(szZeit,"%02d:%02d:%02d\n",
localTime.tm_hour,
localTime.tm_min,
localTime.tm_sec);
display.println(szZeit);
display.setTextSize(2);
// Feritg --------------------------------
}
void blink(){
digitalWrite (LED_Blue, HIGH);
delay(100);
@ -64,10 +126,17 @@ void blink(){
void drawIST(float wert){
char msgt[20];
String mw;
dtostrf(wert, 6, 2, msgt);
mw = msgt;
display.clearDisplay();
/*
Punkt in Komma wndeln.
Sucht dass Array msgt durch
auf . und ersetzt es durch , .
*/
for (byte i = 0; i < sizeof(msgt) - 1; i++) {
if (msgt[i] == '.'){
msgt[i] = ',';
}
}
display.setCursor(0,0); // Start at top-left corner
display.println("--PT1000--");
display.setCursor(0,32); // Zeile 2
@ -76,8 +145,7 @@ void drawIST(float wert){
display.println("Temperatur:");
display.setCursor(20,48); // Zeile 3
display.setTextSize(2);
mw.replace('.',',');
display.print(mw);
display.print(msgt);
display.setTextSize(1);
display.print(" o");
display.setTextSize(2);
@ -87,13 +155,25 @@ void drawIST(float wert){
void setup() {
Serial.begin(115200);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
delay(2000); // Pause for 2 seconds
display.ssd1306_command(SSD1306_SETCONTRAST);
display.ssd1306_command(8);
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.printf("\nConnecting to %s\n", ssid);
// Clear the buffer
display.clearDisplay();
@ -101,19 +181,46 @@ void setup() {
display.setTextColor(WHITE); // Draw white text
display.setCursor(0,0); // Start at top-left corner
display.println("--PT1000--");
display.display();
//display.display();
pinMode (LED_Blue, OUTPUT);
digitalWrite (LED_Blue, HIGH);
Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
thermo.begin(MAX31865_2WIRE); // set to 2WIRE or 4WIRE as necessary
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);
zeigeZeit(timeinfo);
display.display();
}
int Minuten, MintenOld = 99;
void loop() {
uint16_t rtd = thermo.readRTD();
getNTPtime(10);
//display.clearDisplay(); // Lösche Display
zeigeZeit(timeinfo);
Minuten = timeinfo.tm_min;
if (Minuten != MintenOld){
MintenOld = Minuten;
display.clearDisplay(); // Lösche Display
zeigeZeit(timeinfo);
uint16_t rtd = thermo.readRTD();
Serial.print("RTD value: "); Serial.println(rtd);
float ratio = rtd;
float messung;
@ -121,19 +228,8 @@ void loop() {
Serial.print("Ratio = "); Serial.println(ratio,8);
Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
messung = thermo.temperature(RNOMINAL, RREF);
Serial.print("Temperature = "); Serial.println(messung);
/* display.clearDisplay();
display.setCursor(0,0); // Start at top-left corner
display.println("--PT1000--");
display.setCursor(0,32); // Start at top-left corner
display.println(thermo.temperature(RNOMINAL, RREF));
display.display(); */
Serial.printf("Temperature: %3.1f °C\n", messung);
drawIST(messung);
// Check and print any faults
uint8_t fault = thermo.readFault();
if (fault) {
@ -160,5 +256,8 @@ void loop() {
}
Serial.println();
blink();
delay(5000);
}
display.display();
delay(100);
display.display();
}