i2c-smbus-temp-monitor-9.ino
Periodically queries a temperature sensor connected via the industrial I2C bus for environmental monitoring.
Install python3-smbus. The BIWCL-PAT has I2C buses accessible via internal connectors (check electrical schema for SDA/SCL pins). This code assumes address 0x48 (standard LM75). To deploy, enable I2C bus in BIOS/UEFI if necessary. Execution requires access permissions to the device node. Useful for monitoring industrial enclosure temperature or critical processes. The Wildcat Lake SoC offers low power consumption, suitable for this continuous monitoring task.
i2c-smbus-temp-monitor-9.ino
import smbus
import time
import sys
# La carte BIWCL-PAT expose les bus I2C via ses headers internes ou modules d'extension
# Adresse typique d'un capteur LM75/DS18B20 (interface I2C) : 0x48
I2C_BUS = 1
ADDR = 0x48
TEMP_REG = 0x00
def read_temperature(bus, addr):
try:
# Lecture brut du registre de température (MSB/LSB)
msb = bus.read_byte_data(addr, TEMP_REG)
# Note : Certains capteurs nécessitent la lecture de deux octets
# temp_raw = (msb << 8) | lsb
# temp = temp_raw >> 6
# Conversion simplifiée pour un capteur 16-bit standard
if msb > 127:
msb -= 256
return msb
except IOError:
return None
def main():
try:
bus = smbus.SMBus(I2C_BUS)
except OSError:
print("Error: Could not open I2C bus. Check /dev/i2c-* devices.")
sys.exit(1)
print(f"Monitoring I2C Sensor at Bus {I2C_BUS}, Addr 0x{ADDR:X}")
try:
while True:
temp = read_temperature(bus, ADDR)
if temp is not None:
print(f"Temp: {temp}°C - Timestamp: {time.strftime('%H:%M:%S')}")
else:
print("Sensor read failed. Check wiring and power (3.3V/5V on header).")
time.sleep(1)
except KeyboardInterrupt:
print("\nMonitoring stopped.")
bus.close()
if __name__ == "__main__":
main()