Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A8S and Modbus sensor
#11
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.
Reply
#12
In your e-shop you write that the address should be editable. So is it?
https://shop.kincony.com/products/rs485-...e-by-sht30
Reply
#13
use PC software to config the RS485 address. after click "set" button, then power off the sensor and power on again.
   
PC software download: 
.zip   Debug.zip (Size: 4.08 MB / Downloads: 128)
Reply
#14
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`.
Reply
#15
ok, thanks share your result.
Reply
#16
Do you have all info about this sensor? https://shop.kincony.com/products/rs485-...e-by-sht30 I need to calibrate the sensor, as the temperature and humidity are very off (about 5°C higher than real values ​​and 20% lower than real values). Is there a way to send commands via Modbus to recalibrate the sensor so it can be read correctly later? The goal is to be able to perform certified calibration and supply pre-calibrated sensors to customers.
Reply
#17
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.")
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)