Post by N8MDP on Jun 9, 2021 3:02:14 GMT -8
I'm looking for a simple method in Python3 to implement in my GroveWeatherPi initialization process which detects hardware connected or not. Knowing that the I2C address on I2C Bus 0 is 0x5C, is there a way to detect this at the address without sending commands to get a temperature or humidity reading? I've read through a number of subject threads where use of: sudo i2cdetect -y 1 doesn't always return the 5C address and you may have to do this twice to get it to wake up. I reviewed the AM2315.py module looking for a simple and clean way to detect the sensor, but nothing stands out to me. if the sensor is unplugged and you use the def _read_data(self) function, the function stays in an endless loop if the sensor is not connected.
I'm not using the tentacle_pi.AM2315 module but the revised stand-alone AM2315.py module. Thus the following code is not being used that was originally used in the GroveWeatherPi.py program:
##############
# Setup AM2315
# turn I2CBus 0 on
if (config.TCA9545_I2CMux_Present):
tca9545.write_control_register(TCA9545_CONFIG_BUS0)
###############
# Detect AM2315
try:
from tentacle_pi.AM2315 import AM2315
try:
am2315 = AM2315(0x5c,"/dev/i2c-1")
outsideTemperature, outsideHumidity, crc_check = am2315.sense()
#print "outsideTemperature: %0.1f C" % outsideTemperature
#print "outsideHumidity: %0.1f %%" % outsideHumidity
#print "crc: %i" % crc_check
config.AM2315_Present = True
if (crc_check == -1):
config.AM2315_Present = False
except:
config.AM2315_Present = False
except:
config.AM2315_Present = False
print "------> See Readme to install tentacle_pi"
Thanks for suggestions offered.
I'm not using the tentacle_pi.AM2315 module but the revised stand-alone AM2315.py module. Thus the following code is not being used that was originally used in the GroveWeatherPi.py program:
##############
# Setup AM2315
# turn I2CBus 0 on
if (config.TCA9545_I2CMux_Present):
tca9545.write_control_register(TCA9545_CONFIG_BUS0)
###############
# Detect AM2315
try:
from tentacle_pi.AM2315 import AM2315
try:
am2315 = AM2315(0x5c,"/dev/i2c-1")
outsideTemperature, outsideHumidity, crc_check = am2315.sense()
#print "outsideTemperature: %0.1f C" % outsideTemperature
#print "outsideHumidity: %0.1f %%" % outsideHumidity
#print "crc: %i" % crc_check
config.AM2315_Present = True
if (crc_check == -1):
config.AM2315_Present = False
except:
config.AM2315_Present = False
except:
config.AM2315_Present = False
print "------> See Readme to install tentacle_pi"
Thanks for suggestions offered.