EC-110 עם Arduino, ESP32, Raspberry Pi ו-Python

איך מחברים את חיישן מוליכות ומליחות דיגיטלי EC-110 - 0 עד 200 mS/cm למיקרו-בקר או למחשב שלכם וקוראים ממנו ב-RS485 Modbus RTU. הטבלאות הן אלה שבדף הנתונים, ושתי דוגמאות הקוד מורצות מול מסגרת הדוגמה שבדף הנתונים לפני שהעמוד מתפרסם.

עמוד המוצר דף נתונים (PDF) דף נתונים (Markdown) סקיצת Arduino (.ino) סקריפט Python (.py)

חיישן מוליכות ומליחות דיגיטלי EC-110 - 0 עד 200 mS/cm

חיבור ה-EC-110

החיישן הוא התקן RS485, ולכן צריך משדר-מקלט בינו לבין הלוח שלכם. במחשב או ב-Raspberry Pi זה מתאם USB ל-RS485. במיקרו-בקר זה מודול מסוג MAX485 על יציאה טורית חומרתית. הזינו את החיישן מספק שנמצא בטווח המתח שבטבלה, וחברו את האדמה שלו לאדמה של המשדר-מקלט.

Wire Color Function Description
Red V+ Power Supply
Black GND Power Ground
Yellow RS485-A Data +
Green RS485-B Data -

דוגמת Python (Raspberry Pi, Linux, macOS, Windows)

הסקריפט צריך רק את pyserial. הוא בונה בעצמו את בקשת ה-Modbus, בודק את ה-CRC של התשובה ומדפיס קריאה אחת כל חמש שניות. ב-Windows העבירו את יציאת ה-COM כארגומנט.

#!/usr/bin/env python3
"""Read the Agrinovo EC-110 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_110.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 sensor'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"sensor returned Modbus error {reply[2]}")
    if len(reply) != 5 + 2 * count or crc16(reply[:-2]) != reply[-2:]:
        raise IOError("no valid reply from the sensor")
    return reply[3:-2]


def read_probe(port):
    data = read_registers(port, ADDRESS, 0x03, 0x0000, 4)
    return {
        "conductivity": struct.unpack(">H", data[0:2])[0] * 10,  # µS/cm
        "temperature":  struct.unpack(">H", data[2:4])[0] * 0.1,  # °C
        "tds":          struct.unpack(">H", data[4:6])[0] * 10,  # ppm
        "salinity":     struct.unpack(">H", data[6:8])[0] * 0.1,  # ppt
    }


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)

דוגמת Arduino (Uno, Mega, ESP32, ESP8266, MKR, Pico)

הסקיצה משתמשת בספריית Agrinovo: ב-Arduino IDE פתחו את Sketch > Include Library > Manage Libraries והתקינו את "Agrinovo". הספרייה בוחרת את היציאה הטורית לפי הלוח, והפינים רשומים בראש הקובץ AgrinovoDefaultPort.h. DE ו-RE של המשדר-מקלט מתחברים לפין יציאה אחד.

// Agrinovo EC-110 conductivity and salinity probe
// Prints conductivity, temperature, TDS and salinity every 5 seconds.
//
// Sensor cable
//   Red     supply +, 12-24 V DC
//   Black   supply ground, joined to the board's ground
//   Yellow  RS485 A
//   Green   RS485 B
//
// The board talks to the sensor through an RS485 transceiver (MAX485 or
// similar). AgrinovoDefaultPort.h lists the serial pins used on each board.
//
// https://agrinovo.io/products/sensors/aqua/ec/ec-110-probe/

#include <Agrinovo.h>
#include <AgrinovoDefaultPort.h>

const int DE_PIN = 4;  // transceiver DE and RE, tied together

AgrinovoBus bus(AGRINOVO_PORT, DE_PIN);
AgrinovoEC110 probe(bus);  // Modbus address 1

void setup() {
  Serial.begin(115200);
  agrinovoPortBegin(9600);
  bus.begin();
}

void loop() {
  if (probe.read()) {
    Serial.print("Conductivity: ");
    Serial.print(probe.conductivity(), 0);
    Serial.println(" µS/cm");
    Serial.print("Temperature: ");
    Serial.print(probe.temperature(), 1);
    Serial.println(" °C");
    Serial.print("TDS: ");
    Serial.print(probe.tds(), 0);
    Serial.println(" ppm");
    Serial.print("Salinity: ");
    Serial.print(probe.salinity(), 1);
    Serial.println(" ppt");
  } else {
    Serial.println(probe.errorText());
  }
  delay(5000);
}

מה הדוגמאות קוראות

שתי הדוגמאות שולחות בקשה אחת, פונקציה 0x03, 4 רגיסטרים החל מ-0x0000, ומפענחות את הערכים האלה:

ערך יחידה רגיסטר קידוד
Conductivity µS/cm 0x0000 מספר שלם של 16 סיביות ללא סימן, עם מקדם קנה מידה
Temperature °C 0x0001 מספר שלם של 16 סיביות ללא סימן, עם מקדם קנה מידה
TDS ppm 0x0002 מספר שלם של 16 סיביות ללא סימן, עם מקדם קנה מידה
Salinity ppt 0x0003 מספר שלם של 16 סיביות ללא סימן, עם מקדם קנה מידה

כלי Modbus אחרים

אותה בקשה עובדת מכל מאסטר Modbus RTU: pymodbus, minimalmodbus, Node-RED, LabVIEW, בקר מתוכנת (PLC) או דאטה לוגר של צד שלישי עם יציאת Modbus. השתמשו בהגדרות התקשורת הטורית, בקוד הפונקציה ובכתובות הרגיסטרים שלמעלה.

איסוף נתונים בלי לכתוב קוד

בקר Omni Genesis קורא את ה-EC-110 ושולח את הקריאות לענן Agrinovo ברשת הסלולרית, ומשם אפשר לייצא אותן או לקרוא אותן דרך ה-API של הענן.

מתוך דף הנתונים

Specifications

Parameter Specification
Conductivity Range 0 to 200,000 µS/cm (0 to 200 mS/cm)
Salinity Range 0 to 100 ppt
TDS Output ppm (composition dependent)
Accuracy ±1.5% FS
Temperature Range 0 to 60°C
Temperature Compensation Automatic
Operating Humidity ≤85% RH
Power Consumption ≤0.5 W
Electrode Constant K = 10.0
Electrode Material Two-graphite
Housing Material PTFE
Output RS485 Modbus-RTU
Supply Voltage 12-24 VDC

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)

Address Description Scaling Range
0x0000 Conductivity Value × 10 → µS/cm 0 to 200,000 µS/cm
0x0001 Temperature Value ÷ 10 → °C 0 to 60°C
0x0002 TDS Value × 10 → ppm composition dependent
0x0003 Salinity Value ÷ 10 → ppt 0 to 100 ppt

The salinity-to-TDS ratio depends on water composition. For NaCl-dominant water (seawater, marine aquaculture, industrial brine), the ratio is typically 1.5 to 2.0.

Configuration Registers (Function 0x06)

Address Description Range / Notes
0x0000 Slave Address 0x01 to 0xFE
0x0004 Slope Value × 1000 (default: 1000)

Reading Data

Read 4 registers from 0x0000:

Request:  01 03 00 00 00 04 44 09
Response: 01 03 08 00 1A 00 BF 00 0D 00 02 2B CF

Decoding (tap water example):

Register Hex Decimal Scaling Result
Conductivity 0x001A 26 × 10 260 µS/cm
Temperature 0x00BF 191 ÷ 10 19.1°C
TDS 0x000D 13 × 10 130 ppm
Salinity 0x0002 2 ÷ 10 0.2 ppt

Address Configuration

Change Address (0x01 to 0x02)

Write to register 0x0000:

01 06 00 00 00 02 08 0B

Broadcast Discovery

Use address 0xFE with only one device on the bus.

Calibration

Slope Adjustment

The slope register at 0x0004 trims the sensor against a known reference standard. Slope is stored as value × 1000. To set a slope of 1.200, write 1200 (0x04B0):

01 06 00 04 04 B0 CB 7F

Default slope is 1.000 (raw value 1000).

Revision History

Rev Date Changes
1.0 June 2026 Initial release
1.1 August 2026 Layout revision
1.2 October 2026 New layout

Contact

Agrinovo, https://agrinovo.io/products, [email protected], +972 54 688 8148 (direct / WhatsApp). Specifications subject to change without notice.

שאלות על החיווט או על הפרוטוקול?

ספרו לנו באיזה לוח או דאטה לוגר אתם משתמשים ומה צריך למדוד.