im trying to get temperature and humidity readings main issue rn is that the sensor connection isn't very stable CHTA20.getTemperture() is how temperature is pulled from my sensor but if the sensor's connection is loose or if the sensor is broken then it hangs on the sensor which is an issue since I have multiple sensors
what im looking to do is that if the CHTA20.getTemperature doesn't return information it skip over the line and prints which sensor is not working not very sure how to implement
is it possible to resolve this software side
The sensor im using is called CHTA20 ive tried reading the instruction manual but its all in chinese i can read bit of it so i know the translations arent accurate
As for the loose connection issue i can just tape it down issue is if the sensor just breaks (and it has before) then i have to go and test one by one and the arduio is in a inconvenient place to access (cannot be moved anywhere else unfortunately so id rather not have to go and mess with that replacing the sensors(cutting the wires and attaching a new one) is actually far faster and simpler in this situation
Connections wise its the same as Arduino UNO connection with a TCA9548A along with CHTA20 Sensors
I ve tried reading your message. It seems to be in English but just as awkward as Chinese.
If you expect help, please express your thoughts competently and clearly, use sentences and paragraphs. Attach the full code and actual diagram of your connections, and not some similar one found on the Internet.
Start from reading the forum guidelines to see how to properly insert the code and some other good information on making a good post.
The wiring in the post i linked is not similar its identical i inherited this project from someone else i think that was their post
The code chunck i posted is in the void loop() function and its just the same chunck repeated multiple times
As for what i need help with
When the the sensor for one reason or another is not returning a numerical value or not returning a value at all how do i get the program to just print (sensorx not working) and carry on printing for the other sensors so the loop doesn't get stuck
There is no way you can do this without rewriting the sensor library.
If the temperature measurement function does not return anything, it means the program remains inside this function and you can't move to another line.
Note that that won't compile with the capital 'If' and that inside of that if's parentheses, you're reading the sensor again and discarding the result.
This untested snippet might remember that it is broken and skip the code:
A millis() timer could be used - should a valid sensor result not evince in a given time further attempts would be terminated and a failure value stuffed in ("9999").
An 'attempts counter' could be used to the same effect.
Could you please provide a link to this manual? I tried Googling before I asked and didn't find much about the CHTA20.
Or use a more robust type of connector. Or soldered connections.
Ensure it doesn't break. Sensors tend to 'break' if they're used inappropriately, so ensure that this doesn't happen.
Also:
This will help figuring out which mechanisms can be used to recover from an I2C failure.
Again, try to fix the cause. This all sounds like a bunch of patches pasted over each other to cover up a more fundamental problem that doesn't need to exist.
Sorry to saying that, but your code probably not doing what you expect.
Your "while timeout" loop will work only once, because you do not update the timeout value.
After the value of millis() exceed the value of timeout - your will again stuck endlessly in getTemperature() function.
Moreover - as I said before, the problem can't solved this way, because you do not check in the code, was the call of getTemperature() function successfull or not. Without this knowledge you can't decide, how long you have still stay in the while loop.
Will adding
'''
Timeout=timeout+Currentmillis
'''
Before the while function fix this?
Typing this on my phone since i dont have access to the computer rn
It will fix this discrete issue, but create another - after adding that your every reading the temperature will last 10 seconds.
To avoid this you have to know how to distinguish between successful and failed call of getTemperature()
PS Read more carefully how you were advised to use a timer at #10. You should check the return value of the getTemperature() function for correctness and only stay in your while timeout loop if the value is not valid. There is nothing like this in your code
That was actually my first solution but i dont know what the return value for it being invalid is and i dont understand the manual since its in Chinese so im trying to find an alternative solution and so far it does work in solving my primary concern of getting the rest of the code stuck
I can reduce the temperature reading time