EC-120 con Arduino, ESP32, Raspberry Pi y Python
Cómo conectar EC-120 Sonda digital de alta conductividad a su propio microcontrolador o computadora y obtener lecturas por RS485 Modbus RTU. Las tablas son las de la ficha técnica, y los dos ejemplos de código se ejecutan contra la trama de ejemplo de la ficha técnica antes de publicar esta página.
Página del producto Ficha técnica (PDF) Ficha técnica (Markdown)
Conexión de EC-120
La sonda es un dispositivo RS485, por lo que necesita un transceptor entre ella y su placa. En una computadora o una Raspberry Pi es un adaptador USB a RS485. En un microcontrolador es un módulo tipo MAX485 en un puerto serial por hardware. Alimente la sonda con una fuente dentro del rango de tensión de la tabla y conecte su tierra a la tierra del transceptor.
| Wire Color | Function | Description |
|---|---|---|
| Red | V+ | Power Supply (7 to 24 VDC) |
| Black | GND | Power Ground |
| Yellow | RS485-A | Data+ |
| Green | RS485-B | Data- |
| White | 4 to 20mA+ | Analog Current Output |
to 20mA Loop Load
| Supply Voltage | Maximum Load |
|---|---|
| 12 V | 250 Ω |
| 20 V | 500 Ω |
| 24 V | >500 Ω |
Ejemplo en Python (Raspberry Pi, Linux, macOS, Windows)
El script solo necesita pyserial. Arma la solicitud Modbus por sí mismo, verifica el CRC de la respuesta e imprime una lectura cada cinco segundos. En Windows, pase el puerto COM como argumento.
#!/usr/bin/env python3
"""Read the Agrinovo EC-120 over RS485 Modbus RTU.
Works on a Raspberry Pi or any computer with a USB to RS485 adapter.
Install the serial library once: pip install pyserial
Run: python3 ec_120.py /dev/ttyUSB0
"""
import struct
import sys
import time
import serial
PORT = sys.argv[1] if len(sys.argv) > 1 else "/dev/ttyUSB0"
ADDRESS = 0x01 # the probe's Modbus address
def crc16(frame: bytes) -> bytes:
crc = 0xFFFF
for byte in frame:
crc ^= byte
for _ in range(8):
crc = (crc >> 1) ^ 0xA001 if crc & 1 else crc >> 1
return struct.pack("<H", crc)
def read_registers(port, address, function, start, count):
request = struct.pack(">BBHH", address, function, start, count)
port.reset_input_buffer()
port.write(request + crc16(request))
reply = port.read(5 + 2 * count)
if len(reply) >= 5 and reply[1] == function | 0x80:
raise IOError(f"probe returned Modbus error {reply[2]}")
if len(reply) != 5 + 2 * count or crc16(reply[:-2]) != reply[-2:]:
raise IOError("no valid reply from the probe")
return reply[3:-2]
def read_probe(port):
data = read_registers(port, ADDRESS, 0x03, 0x0000, 10)
return {
"conductivity_ms_cm": struct.unpack(">f", data[2:4] + data[0:2])[0],
"resistivity_ohm_cm": struct.unpack(">f", data[6:8] + data[4:6])[0],
"temperature_c": struct.unpack(">f", data[10:12] + data[8:10])[0],
"tds_ppm": struct.unpack(">f", data[14:16] + data[12:14])[0],
"salinity_ppm": struct.unpack(">f", data[18:20] + data[16:18])[0],
}
if __name__ == "__main__":
with serial.Serial(PORT, 9600, bytesize=8, parity="N", stopbits=1, timeout=1) as port:
while True:
print(read_probe(port))
time.sleep(5) Ejemplo para Arduino (ESP32, Mega y otras placas con un segundo puerto serial)
El sketch no usa ninguna biblioteca. En un ESP32 usa Serial2 en los pines definidos al inicio; en placas AVR usa Serial1. DE y RE del transceptor van a un mismo pin de salida.
// Agrinovo EC-120 over RS485 Modbus RTU.
// For a board with a spare hardware serial port (ESP32, Mega, Leonardo, Due)
// and a MAX485-type transceiver. Power the probe from its own supply, as the
// wiring table says, and join the grounds.
const uint8_t ADDRESS = 0x01; // the probe's Modbus address
const int DE_PIN = 4; // transceiver DE and RE tied together
const int RX_PIN = 16; // ESP32 only
const int TX_PIN = 17; // ESP32 only
#if defined(ESP32)
#define RS485 Serial2
#else
#define RS485 Serial1
#endif
uint16_t crc16(const uint8_t *frame, size_t length) {
uint16_t crc = 0xFFFF;
for (size_t i = 0; i < length; i++) {
crc ^= frame[i];
for (int bit = 0; bit < 8; bit++) {
crc = (crc & 1) ? (crc >> 1) ^ 0xA001 : crc >> 1;
}
}
return crc;
}
// Builds a float from its four bytes, most significant first.
float float32(uint8_t b3, uint8_t b2, uint8_t b1, uint8_t b0) {
uint32_t bits = ((uint32_t)b3 << 24) | ((uint32_t)b2 << 16) | ((uint32_t)b1 << 8) | b0;
float value;
memcpy(&value, &bits, sizeof value);
return value;
}
// Reads `count` registers into `data`. Returns false when the probe does not
// answer or the checksum is wrong.
bool readRegisters(uint8_t function, uint16_t start, uint16_t count, uint8_t *data) {
uint8_t request[8] = {ADDRESS, function, (uint8_t)(start >> 8), (uint8_t)start,
(uint8_t)(count >> 8), (uint8_t)count, 0, 0};
uint16_t crc = crc16(request, 6);
request[6] = crc & 0xFF;
request[7] = crc >> 8;
while (RS485.available()) RS485.read();
digitalWrite(DE_PIN, HIGH);
RS485.write(request, 8);
RS485.flush();
digitalWrite(DE_PIN, LOW);
uint8_t reply[5 + 2 * 16];
size_t expected = 5 + 2 * count;
if (RS485.readBytes(reply, expected) != expected) return false;
uint16_t received = reply[expected - 2] | ((uint16_t)reply[expected - 1] << 8);
if (reply[1] != function || crc16(reply, expected - 2) != received) return false;
memcpy(data, reply + 3, 2 * count);
return true;
}
void setup() {
Serial.begin(115200);
pinMode(DE_PIN, OUTPUT);
digitalWrite(DE_PIN, LOW);
#if defined(ESP32)
RS485.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN);
#else
RS485.begin(9600);
#endif
RS485.setTimeout(1000);
}
void loop() {
uint8_t data[2 * 10];
if (!readRegisters(0x03, 0x0000, 10, data)) {
Serial.println("no reply");
delay(5000);
return;
}
Serial.print("conductivity_ms_cm=");
Serial.print(float32(data[2], data[3], data[0], data[1]), 3);
Serial.print(" resistivity_ohm_cm=");
Serial.print(float32(data[6], data[7], data[4], data[5]), 1);
Serial.print(" temperature_c=");
Serial.print(float32(data[10], data[11], data[8], data[9]), 1);
Serial.print(" tds_ppm=");
Serial.print(float32(data[14], data[15], data[12], data[13]), 1);
Serial.print(" salinity_ppm=");
Serial.print(float32(data[18], data[19], data[16], data[17]), 1);
Serial.println();
delay(5000);
} Qué leen los ejemplos
Ambos ejemplos envían una sola solicitud, función 0x03, 10 registros desde 0x0000, y decodifican estos valores:
| Valor | Unidad | Registro | Codificación |
|---|---|---|---|
conductivity_ms_cm | mS/cm | 0x0000 | Flotante de 32 bits en dos registros, palabra baja primero |
resistivity_ohm_cm | Ω·cm | 0x0002 | Flotante de 32 bits en dos registros, palabra baja primero |
temperature_c | °C | 0x0004 | Flotante de 32 bits en dos registros, palabra baja primero |
tds_ppm | ppm | 0x0006 | Flotante de 32 bits en dos registros, palabra baja primero |
salinity_ppm | ppm | 0x0008 | Flotante de 32 bits en dos registros, palabra baja primero |
Otras herramientas Modbus
La misma solicitud funciona desde cualquier maestro Modbus RTU: pymodbus, minimalmodbus, Node-RED, LabVIEW, un PLC o un registrador de datos de terceros con puerto Modbus. Use la configuración serial, el código de función y las direcciones de registro indicados arriba.
Registro de datos sin escribir código
El controlador Omni Genesis lee EC-120 y envía las lecturas a la nube de Agrinovo por la red celular, donde se pueden exportar o leer mediante la API de la nube.
Referencia de la ficha técnica
Specifications
| Parameter | Specification |
|---|---|
| Conductivity Range | 0 to 200,000 µS/cm (0 to 200 mS/cm) |
| Salinity Range | 0.00 to 100.00 ppt |
| Accuracy | ±1.5% FS |
| Measured Values | Conductivity, resistivity, temperature, TDS, salinity |
| Temperature Compensation | 0 to 60°C (automatic) |
| Operating Temperature | 0 to 60°C |
| Operating Humidity | ≤85% RH |
| Electrode Constant | K = 10.0 |
| Electrode Material | Graphite |
| Body Material | PTFE |
| Output | RS485 Modbus-RTU and 4 to 20mA |
| Supply Voltage | 7 to 24 VDC (12 to 24 VDC when the 4 to 20mA output is used) |
| Power Consumption | ≤0.5 W |
Communication Settings
| Parameter | Value |
|---|---|
| Protocol | Modbus-RTU |
| Baud Rate | 9600 bps |
| Data Bits | 8 |
| Parity | None |
| Stop Bits | 1 |
| Default Address | 0x01 |
Register Map
Measurement Registers (Function 0x03)
Every value is a 32-bit IEEE-754 float held in two registers, low word first.
| Address | Description | Unit |
|---|---|---|
| 0x0000 to 0x0001 | Conductivity | mS/cm |
| 0x0002 to 0x0003 | Resistivity | Ω·cm |
| 0x0004 to 0x0005 | Temperature | °C |
| 0x0006 to 0x0007 | TDS | ppm |
| 0x0008 to 0x0009 | Salinity | ppm (÷ 1000 for ppt) |
Configuration Registers (Function 0x06)
| Address | Description |
|---|---|
| 0x0014 | Slave Address |
Reading Data
Read 10 registers from 0x0000:
Request: 01 03 00 00 00 0A C5 CD
Response: 01 03 14 08 12 3E A2 7E 0F 45 45 A2 B1 41 DD 3B E2 43 1E 0E AC 43 2E F8 F6
Decoding: swap the two 16-bit words of each value, then read the result as a float. Conductivity arrives as 08 12 3E A2, which becomes 3E A2 08 12 = 0.316.
| Value | Received | Swapped | Result |
|---|---|---|---|
| Conductivity | 08 12 3E A2 | 3E A2 08 12 | 0.316 mS/cm |
| Resistivity | 7E 0F 45 45 | 45 45 7E 0F | 3159.9 Ω·cm |
| Temperature | A2 B1 41 DD | 41 DD A2 B1 | 27.7°C |
| TDS | 3B E2 43 1E | 43 1E 3B E2 | 158.2 ppm |
| Salinity | 0E AC 43 2E | 43 2E 0E AC | 174.1 ppm (0.174 ppt) |
Address Configuration
Change Address (0x01 to 0x02)
Write the new address to register 0x0014:
01 06 00 14 00 02 48 0F
Broadcast Discovery
Use address 0xFF with only one device connected. The sensor replies with its own address.
FF 03 00 00 00 0A D0 13
Revision History
| Rev | Date | Changes |
|---|---|---|
| 1.0 | February 2026 | Initial release |
| 2.0 | October 2026 | New sensor generation: graphite electrode, 0 to 100 ppt salinity range, float32 register map, 4 to 20mA output |
| 2.1 | October 2026 | New layout |
Contact
Agrinovo, https://agrinovo.io/products, [email protected], +972 54 688 8148 (direct / WhatsApp). Specifications subject to change without notice.
¿Preguntas sobre el cableado o el protocolo?
Cuéntenos qué placa o registrador usa y qué necesita medir.