Dodanie 3 czujników dht22

Poprawa wykresu w excelu
This commit is contained in:
Kamil Siejka
2025-02-26 15:29:45 +01:00
parent a236dacfc3
commit 1423705eb2
2 changed files with 99 additions and 9 deletions

View File

@@ -9,29 +9,54 @@
#include "SD.h" #include "SD.h"
#include "SPI.h" #include "SPI.h"
#define Version "0.36" #define Version "0.37"
#define WIRE Wire #define WIRE Wire
#define DHTTYPE DHT22 #define DHTTYPE DHT22
#define DHTPIN 4 #define DHTPIN 4 //GPIO04 D4
#define SD_CS 5 #define SD_CS 5 //GPIO05 D5
#define BTN_UP 33 #define BTN_UP 33 //GPIO33 D33
#define BTN_ENTER 34 #define BTN_ENTER 34 //GPIO34 D34
#define BTN_DOWN 35 #define BTN_DOWN 35 //GPIO35 D35
#define VOLT_IN 36 #define VOLT_IN 36 //GPIO36 VP
#define FAN_PIN 14 //GPIO36 D14
#define DHTPIN_L 13 //GPIO36 D13
#define DHTPIN_M 16 //GPIO36 D17
#define DHTPIN_H 17 //GPIO36 D16
//Wyświetlacz/Czytnik SD/RTC
//MOSI //GPIO23 D23
//SLC //GPIO22 D22
//SDA //GPIO21 D21
//MISO //GPIO19 D19
//SCK //GPIO18 D18
const float voltageDividerFactor = 1.51;//1.56; const float voltageDividerFactor = 1.51;//1.56;
const float adcMaxVoltage = 3.3; const float adcMaxVoltage = 3.3;
const int adcResolution = 4095; const int adcResolution = 4095;
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE); Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);
DHT dht(DHTPIN, DHTTYPE); DHT dht(DHTPIN, DHTTYPE);
DHT dhtL(DHTPIN_L, DHT22);
DHT dhtM(DHTPIN_M, DHT22);
DHT dhtH(DHTPIN_H, DHT22);
RTC_DS3231 rtc; // Obiekt dla DS3231 RTC_DS3231 rtc; // Obiekt dla DS3231
int menuL0 = 10; int menuL0 = 10;
int menuL1 = 10; int menuL1 = 10;
int menuL2 = 10; int menuL2 = 10;
float hum; float hum;
float humL;
float humM;
float humH;
float temp; float temp;
float tempL;
float tempM;
float tempH;
float heat_idx; float heat_idx;
@@ -196,6 +221,9 @@ void setup() {
display.display(); display.display();
delay(500); delay(500);
dht.begin(); dht.begin();
dhtL.begin();
dhtM.begin();
dhtH.begin();
pinMode(BTN_UP, INPUT_PULLDOWN ); pinMode(BTN_UP, INPUT_PULLDOWN );
pinMode(BTN_ENTER, INPUT_PULLDOWN ); pinMode(BTN_ENTER, INPUT_PULLDOWN );
pinMode(BTN_DOWN, INPUT_PULLDOWN ); pinMode(BTN_DOWN, INPUT_PULLDOWN );
@@ -273,7 +301,14 @@ void loop() {
// display.println(menuL2); // display.println(menuL2);
hum = dht.readHumidity(); hum = dht.readHumidity();
humL = dhtL.readHumidity();
humM = dhtM.readHumidity();
humH = dhtH.readHumidity();
temp = dht.readTemperature(); temp = dht.readTemperature();
tempL = dhtL.readTemperature();
tempM = dhtM.readTemperature();
tempH = dhtH.readTemperature();
// Compute heat index in Celsius (isFahreheit = false) // Compute heat index in Celsius (isFahreheit = false)
heat_idx = dht.computeHeatIndex(temp, hum, false); heat_idx = dht.computeHeatIndex(temp, hum, false);
@@ -508,7 +543,49 @@ void loop() {
display.print("DOWN"); display.print("DOWN");
} }
} }
if (menuL0 == 7 ) {
display.setCursor(0, 0);
display.println(dateString);
display.setCursor(0, 8);
display.println("TemH");
display.setCursor(30, 8);
display.println(tempH,1);
display.setCursor(55, 8);
display.println("C");
display.setCursor(65, 8);
display.println("HumH");
display.setCursor(95, 8);
display.println(humH,1);
display.setCursor(120,8);
display.println("%");
display.setCursor(0, 16);
display.println("TemM");
display.setCursor(30, 16);
display.println(tempM,1);
display.setCursor(55, 16);
display.println("C");
display.setCursor(65, 16);
display.println("HumM");
display.setCursor(95, 16);
display.println(humM,1);
display.setCursor(120,16);
display.println("%");
display.setCursor(0, 24);
display.println("TemL");
display.setCursor(30, 24);
display.println(tempL,1);
display.setCursor(55, 24);
display.println("C");
display.setCursor(65, 24);
display.println("HumL");
display.setCursor(95, 24);
display.println(humL,1);
display.setCursor(120,24);
display.println("%");
}
if (digitalRead(BTN_UP) == HIGH and menuL0 <10 ) { if (digitalRead(BTN_UP) == HIGH and menuL0 <10 ) {
if ( menuL0 < 10 && menuL1 == 10 ) { if ( menuL0 < 10 && menuL1 == 10 ) {
@@ -530,8 +607,8 @@ void loop() {
} }
} }
if (digitalRead(BTN_DOWN) == HIGH and menuL0 >= 8) { if (digitalRead(BTN_DOWN) == HIGH and menuL0 >= 7) {
if (menuL0 > 8 && menuL1 == 10 ) { if (menuL0 > 7 && menuL1 == 10 ) {
menuL0 = menuL0 - 1; menuL0 = menuL0 - 1;
} }
if (menuL1 > 6 and menuL1 <= 9 && menuL2 == 10) { if (menuL1 > 6 and menuL1 <= 9 && menuL2 == 10) {
@@ -550,6 +627,7 @@ void loop() {
} }
} }
if (currentMillis - previousMillis >= interval) { if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis; previousMillis = currentMillis;
adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36 adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36
@@ -608,6 +686,18 @@ void loop() {
file.print(formatNumber(hum)); file.print(formatNumber(hum));
file.print("; "); file.print("; ");
file.println(formatNumber(heat_idx)); file.println(formatNumber(heat_idx));
file.print("; ");
file.print(formatNumber(tempH));
file.print("; ");
file.print(formatNumber(humH));
file.print("; ");
file.print(formatNumber(tempM));
file.print("; ");
file.print(formatNumber(humM));
file.print("; ");
file.print(formatNumber(tempL));
file.print("; ");
file.print(formatNumber(humL));
file.close(); file.close();
delay(1000); delay(1000);
} }