Posts: 9,076
Threads: 1,202
Joined: Oct 2020
Reputation:
235
it's not easy to change address, you can try to open the sensor, there is a tiny PCB, if you can weld, you can change the i2c address.
Posts: 3
Threads: 0
Joined: Jul 2024
Reputation:
0
Finally, it is working. Thank you very much.
For anyone else trying to set an address without the provided software. You should set the address to registry `0x0a`.
Posts: 9,076
Threads: 1,202
Joined: Oct 2020
Reputation:
235
ok, thanks share your result.
Posts: 2
Threads: 0
Joined: Jul 2025
Reputation:
0
I tried this buy can't be able to set calibratión with modbus parameters: from pymodbus.client import ModbusSerialClient
import struct
import time
# --- CONFIGURACIÓN DEL SENSOR ---
PUERTO_COM = 'COM9' # ⚠️ Cambiar según tu puerto (Windows: COMx, Linux: /dev/ttyUSB0)
BAUDRATE = 9600
DIRECCION_MODBUS = 1 # Dirección del sensor (normalmente 1)
# --- VALORES DE CALIBRACIÓN ---
CALIBRACION_TEMP = 10.0 # °C → valor que se forzará como temperatura
CALIBRACION_HUM = -10.0 # %RH → valor que se forzará como humedad
OFFSET_TEMP = 20.0 # °C → offset de corrección aplicado a temperatura
# --- FUNCIONES AUXILIARES ---
def float_to_2regs(value):
"""Convierte un float IEEE-754 a 2 registros Modbus (32 bits)"""
raw = struct.pack('>f', value) # Big-endian float
hi, lo = struct.unpack('>HH', raw)
return hi, lo
def read_float_from_registers(regs, index):
"""Convierte 2 registros consecutivos a float IEEE-754"""
hi = regs[index]
lo = regs[index + 1]
raw = struct.pack('>HH', hi, lo)
return struct.unpack('>f', raw)[0]
# --- INICIO DEL PROGRAMA ---
client = ModbusSerialClient(
port=PUERTO_COM,
baudrate=BAUDRATE,
stopbits=1,
bytesize=8,
parity='N',
timeout=1
)
if client.connect():
print("✅ Conectado al sensor\n")
# --- Escribir calibraciones ---
print("✏️ Enviando parámetros de calibración...\n")
registros_calibracion = {
0x000C: float_to_2regs(CALIBRACION_TEMP), # Temp en 0x000C–0x000D
0x000E: float_to_2regs(CALIBRACION_HUM), # Hum en 0x000E–0x000F
0x0010: float_to_2regs(OFFSET_TEMP) # Offset en 0x0010–0x0011
}
for reg_base, (hi, lo) in registros_calibracion.items():
response = client.write_registers(address=reg_base, values=[hi, lo], slave=DIRECCION_MODBUS)
if response.isError():
print(f"❌ Error escribiendo en registros 0x{reg_base:04X} y 0x{reg_base+1:04X}")
else:
print(f"✅ Registros 0x{reg_base:04X}-{reg_base+1:04X} ← [{hi}, {lo}]")
print("\n⌛ Esperando 2 segundos para aplicar calibración...\n")
time.sleep(2)
# --- Leer temperatura y humedad ---
result = client.read_holding_registers(address=0, count=6, slave=DIRECCION_MODBUS)
if not result.isError():
regs = result.registers
temp_int = regs[0] / 10
hum_int = regs[1] / 10
temp_float = read_float_from_registers(regs, 2)
hum_float = read_float_from_registers(regs, 4)
print("? Lectura del sensor:")
print(f"?️ Temperatura (int): {temp_int:.1f} °C")
print(f"? Humedad (int): {hum_int:.1f} %RH")
print(f"?️ Temperatura (float): {temp_float:.3f} °C")
print(f"? Humedad (float): {hum_float:.3f} %RH")
else:
print("❌ Error al leer los registros del sensor.")
client.close()
else:
print("❌ No se pudo conectar al sensor.")