As part of my setup loop I want to check the sensors I have connected and make sure they are all there and working correctly. Any ideas on how to do something like this?
Thanks!
Zak
As part of my setup loop I want to check the sensors I have connected and make sure they are all there and working correctly. Any ideas on how to do something like this?
Thanks!
Zak
You are going to have to be a lot more specific than that if you want the level of help that I suspect you are expecting.
As it stands the answer is to do it in the setup function.
A switch is a sensor: the only way to tell if it's working is to read it and see if the value changes.
I think thats actually all the help I needed. I plan to use a mix of i2c sensors, serial sensors as well as analog sensors. I was just wondering if there was a way to make sure a sensor was connected and not giving error but As JimboZA pointed out you cant really test a sensor unless you actuate it.
Thanks for the help gents
ZakAttack92:
you cant really test a sensor unless you actuate it.
That said though, some libraries do provide for testing their sensors, as this DHT11 snippet shows:
//.....
chk = DHT.read(DHT11_PIN); // READ DATA
switch (chk){
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
//....
You have to ask yourself what you are going to do with the information that the sensor is not working when you "test" it in the setup function?
If the answer is to freeze then it looks to the user that your system is broken where as it might just be one sensor.
I'd offer the user the choice to continue with say only 2 of 3 temp sensors working, but perhaps force a shut down if only 1 of 3 was operational.
Point is, some rules would need to be established (and agreed....) at design.
Thank you very much for both of your help.
I think I need to have a bit more of a concept developed before I can actually come up with this code.
The intent was to freeze the program like you said Grumpy_Mike, but you also made me realize this may not be a good idea.
Maybe a better idea would be to initialize all my inputs then display the first values on an lcd so the user can check the values and see if anything looks out of whack.
Either way I am going to consider this solved!
Thanks for your help!