Pages: [1]   Go Down
Author Topic: Check if the communication of the sensor work  (Read 386 times)
0 Members and 1 Guest are viewing this topic.
Capo d'Orlando
Offline Offline
God Member
*****
Karma: 0
Posts: 500
Electronics & Web Dev, Unix User, Ω LEO, Rock/Deep Music, Tech/Science/Finance addicted, Ski/Snowboard and much more …
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

I'm using this sensor: DHT22, MPL11A2, DS18B20 and SD shield.

I would like to check, in the setup, if the communication from arduino to the sensors work.
For now I'm using this code:

Code:
    //SD Shield
    if (!SD.begin(4)) {
        Serial.println("Modulo SD: ERRORE");
        return;
    }
    Serial.println("Modulo SD: OK");
   

    //DHT22
    if (isnan(dht.readTemperature()) || isnan(dht.readHumidity())) {
        Serial.println("Modulo DHT: ERRORE");
    }
    else {
        Serial.println("Modulo DHT: OK");
    }
   

    //DS18B20
    ds18b20.requestTemperatures();
    if (isnan(ds18b20.getTempCByIndex(0)) || isnan(ds18b20.getTempCByIndex(0))) {
        Serial.println("Modulo DS18B20: ERRORE");
    }
    else {
        Serial.println("Modulo DS18B20: OK");
    }
   
   
    //MPL115A2
    if (isnan(mpl115a2.getPressure())) {
        Serial.println("Modulo MPL115A2: ERRORE");
    }
    else {
        Serial.println("Modulo MPL115A2: OK");
    }

So, there is a better way ?

Thank you
Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8430
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What values do you get back when a device is not there? I assume isnan() tests for Not a Number but a simple compare may be simpler.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Capo d'Orlando
Offline Offline
God Member
*****
Karma: 0
Posts: 500
Electronics & Web Dev, Unix User, Ω LEO, Rock/Deep Music, Tech/Science/Finance addicted, Ski/Snowboard and much more …
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

for the arduino work ! lool

for example, if I remove ds18b20 the serial communication read -127.00°C. This is a number and for the sketch there is a communication.
But I need a confirm that the sensor communicate correctly with arduino !
Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8430
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if I remove ds18b20 the serial communication read -127.00°C. This is a number...
So your current code doesn't work then?

I thought it did work but you just wanted a better way.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: