I am currently french students, my group project and I meet a problem with a code on Arduino. We use a temperature sensor and humidity named "Sensirion Sht7x" and a CO2 sensor named T6615
Indeed, in our program, we have established libraries that are "Sensirion.h" for our sensor and "ColorLCDShield.h" to display local data on an LCD (Arduino Shield) screen
here is our code
#include <ColorLCDShield.h>
#include <Sensirion.h>
#define BACKGROUND BLACK
#define C_COLOR RED
#define H_COLOR BLUE
#define M_COLOR GREEN
#define S_COLOR YELLOW
#define W_COLOR WHITE
LCDShield lcd;
int recu;
byte envoye;
int test;
char affichageco2 [16];
char affichagetemperature [16];
char affichagehumidite [16];
char mystring[] = "CO2";
char mystring1[] = "Temperature";
char mystring2[] = "Humidite";
char assignationresult;
//Temperature
const uint8_t dataPin = 9;
const uint8_t sclkPin = 8;
const uint8_t ledPin = 13;
const uint32_t TRHSTEP = 5000UL;
const uint32_t BLINKSTEP = 250UL;
Sensirion sht = Sensirion(dataPin, sclkPin);
uint16_t rawData;
float temperature;
float humidity;
float dewpoint;
byte ledState = 0;
byte measActive = false;
byte measType = TEMP;
unsigned long trhMillis = 0;
unsigned long blinkMillis = 0;
void setup()
{
Serial.begin(9600);
lcd.init(PHILIPS);
lcd.contrast(0);
lcd.clear(BACKGROUND);
//Temperature
pinMode(ledPin, OUTPUT);
delay(15);
sht.measTemp(&rawData);
temperature = sht.calcTemp(rawData);
sht.measHumi(&rawData);
humidity = sht.calcHumi(rawData, temperature);
dewpoint = sht.calcDewpoint(humidity, temperature);
logData();
//
afficheText();
}
void loop()
{
envoye=0xFF;
Serial.write(envoye);
envoye=0xFE;
Serial.write(envoye);
envoye=0x02;
Serial.write(envoye);
envoye=0x02;
Serial.write(envoye);
envoye=0x03;
Serial.write(envoye);
assignationresult = Serial.read();
assignationresult = Serial.read();
assignationresult = Serial.read();
assignationresult = Serial.read();
sprintf (affichageco2, "%d", assignationresult);
assignationresult = Serial.read();
sprintf (affichageco2, "%d", assignationresult);
//////Temperature
unsigned long curMillis = millis();
// Rapidly blink LED. Blocking calls take too long to allow this.
if (curMillis - blinkMillis >= BLINKSTEP) { // Time to toggle the LED state?
ledState ^= 1;
digitalWrite(ledPin, ledState);
blinkMillis = curMillis;
}
// Demonstrate non-blocking calls
if (curMillis - trhMillis >= TRHSTEP) {
measActive = true;
measType = TEMP;
sht.meas(TEMP, &rawData, NONBLOCK);
trhMillis = curMillis;
}
if (measActive && sht.measRdy()) {
if (measType == TEMP) {
measType = HUMI;
temperature = sht.calcTemp(rawData);
sht.meas(HUMI, &rawData, NONBLOCK);
} else {
measActive = false;
humidity = sht.calcHumi(rawData, temperature);
dewpoint = sht.calcDewpoint(humidity, temperature);
logData();
}
}
//
afficheText();
delay(1000);
}
//Temperature
void logData() {
Serial.print("Temperature = "); Serial.print(temperature);
Serial.print(" C, Humidity = "); Serial.print(humidity);
Serial.print(" %, Dewpoint = "); Serial.print(dewpoint);
Serial.println(" C");
}
//
void afficheText()
{
lcd.setStr(mystring, 0, 50, W_COLOR, BACKGROUND);
lcd.setStr(affichageco2, 20, 50, W_COLOR, BACKGROUND);
lcd.setStr(mystring1, 40, 22, W_COLOR, BACKGROUND);
lcd.setStr(affichagetemperature, 60, 50, W_COLOR, BACKGROUND);
lcd.setStr(mystring2, 80, 32, W_COLOR, BACKGROUND);
lcd.setStr(affichagehumidite, 100, 50, W_COLOR, BACKGROUND);
}
It is because of this line that we're stuck ""Sensirion sht = Sensirion(dataPin, sclkPin);"
I'll explain when we this line, there is no error, only the LCD screen does not light up but we can see our data in the monitor directly to Arduino. When we remove all rows for the sensor temperature and humidity display lights up but there is no data unfortunately.