Is there a way i could display the temp and hum for each sensor on an lcd screen?
I know how to do this for data that is not using pointers.
below is my sketch that flips between 2 sensors on the LCD
/* test modified from a v1 basic mutliple multi dht22 sketch
Gives correct temp and humidity readings for each dht22 in domoticz (ie not crossed between 1 and 2)
Not displaying properly on the LCD yet
Domoticz ver 4.11558 beta
Gateway 3.2.1
node 3.2.1
09/12/2019
Arduino Mega
1.8 inch TFT LCD Display 128x160 8/16Bit ST7735S
x2 DHT22
NRF24
*/
#define MY_DEBUG
#define MY_RADIO_NRF24 //Mega Pins 49 CE, 53 CSN/CS, 52 SCK, 51 MOSI, 50 MISO
#define MY_RF24_CE_PIN 49
#define MY_RF24_CS_PIN 53
#define MY_RF24_PA_LEVEL (RF24_PA_MIN)
#define MY_NODE_ID 103
#include <UTFT.h> //LCD 1.8
#include <SPI.h>
#include <MySensors.h>
#include <DHT.h>
#define RELAY1 44
#define RELAY2 45
//static const uint8_t FORCE_UPDATE_N_READS = 10;
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
#define NUM_SENSORS 2
unsigned long SLEEP_TIME = 6000; // Sleep time between reads (in milliseconds)
//MySensor gw;
MyMessage tempMssg(0, V_TEMP);
MyMessage humMssg(NUM_SENSORS, V_HUM);
byte tempID[NUM_SENSORS] = {0, 1};
byte humID[NUM_SENSORS] = {2, 3};
DHT* dht[NUM_SENSORS];
byte sensorPin[NUM_SENSORS] = {40, 42};
float lastTemp[NUM_SENSORS] = {0.0, 0.0};
float lastHum[NUM_SENSORS] = {0.0, 0.0};
boolean metric = true;
//LCD setup
UTFT myGLCD(ITDB18SP, 11, 12, 8, 9, 10); // lcd pins 3,2,6,5,4
void setup()
{
myGLCD.InitLCD(LANDSCAPE);// or PORTRAIT
myGLCD.clrScr();
myGLCD.setColor(200, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(SmallFont);
myGLCD.print("Version & Sketch", LEFT, 3);
myGLCD.print("V.2 TEST5", LEFT, 16);
delay(1000);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.setColor(255, 255, 255);
myGLCD.print("TH1 OUTSIDE", 2, 2);
myGLCD.print("o", 67, 12);
myGLCD.print("C", 74, 15);
myGLCD.print("%", 150, 15);
myGLCD.print("TH2 INSIDE", 2, 36);
myGLCD.print("o", 67, 46);
myGLCD.print("C", 74, 49);
myGLCD.print("%", 150, 49);
Serial.begin(9600);
// begin();
for (int i = 0; i < NUM_SENSORS; i++)
{
dht[i] = new DHT;
dht[i]->setup(sensorPin[i]);
}
sendSketchInfo("DHT22 Humidity test5", "2.0");
for (int i = 0; i < NUM_SENSORS; i++)
{
present(tempID[i], S_TEMP);
present(humID[i], S_HUM);
}
metric = getControllerConfig().isMetric;
Serial.println(F("Setup Complete."));
}
void loop()
{
for (int i = 0; i < NUM_SENSORS; i++)
{
delay(dht[i]->getMinimumSamplingPeriod());
float temperature = dht[i]->getTemperature();
if (isnan(temperature))
{
Serial.print(F("Failed reading temperature from DHT"));
Serial.println(i);
}
else if (temperature != lastTemp[i])
{
lastTemp[i] = temperature;
if (!metric)
{
temperature = dht[i]->toFahrenheit(temperature);
}
send(tempMssg.setSensor(i).set(temperature, false)); // no ack
Serial.print(F("T"));
Serial.print(i);
Serial.print(F("= "));
Serial.println(temperature);
}
myGLCD.setFont(BigFont);
myGLCD.setColor(100, 255, 255);
myGLCD.printNumF(temperature, 1, 1, 15); // this where something needs to be changed to get it to display each temp separately
float humidity = dht[i]->getHumidity();
if (isnan(humidity))
{
Serial.print("Failed reading humidity from DHT");
Serial.println(i);
}
else if (humidity != lastHum[i])
{
lastHum[i] = humidity;
send(humMssg.setSensor(i).set(humidity, false)); // no ack
Serial.print(F("H"));
Serial.print(i);
Serial.print(F("= "));
Serial.println(humidity); // this where something needs to be changed to get it to display each hum separately
myGLCD.setFont(BigFont);
myGLCD.setColor(100, 255, 255);
myGLCD.printNumF(humidity, 1, 85, 15);
}
}
sleep(SLEEP_TIME); //sleep a bit
}```