Paso 4: Código de Python para HIH7130
HIH7130 es un sensor de comunicación basado en I2C, por lo que escribir código es muy fácil.
#https://www.controleverything.com/content/Humidityfrom OmegaExpansion import onionI2Cimport timeimport sysprint 'Starting: onionI2C module testing...'i2c = onionI2C.OnionI2C(0)# set the verbosityi2c.setVerbosity(1)# HIH7130 address, 0x27(39)# Read data back from 0x00(00), 4 bytes# humidity MSB, humidity LSB, temp MSB, temp LSBdata = i2c.readBytes(0x27, 0x00, 4) # Convert the data to 14-bitshumidity = ((((data[0] & 0x3F) * 256) + data[1]) * 100.0) / 16383.0temp = (((data[2] & 0xFF) * 256) + (data[3] & 0xFC)) / 4cTemp = (temp / 16384.0) * 165.0 - 40.0fTemp = cTemp * 1.8 + 32 # Output data to screenprint "Relative Humidity : %.2f %%" %humidityprint "Temperature in Celsius : %.2f C" %cTempprint "Temperature in Fahrenheit : %.2f F" %fTemp