PB-100 con Arduino, ESP32, Raspberry Pi y Python
Cómo conectar Pb-100 Electrodo de ion selectivo de plomo 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) Sketch de Arduino (.ino) Script de Python (.py)
Conexión de PB-100
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+ | DC Power Supply (12-24V DC) |
| Black | GND | DC Power Ground |
| Yellow | RS485-A | Data T/R+ |
| White | RS485-B | Data T/R− |
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 PB-100 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 pb_100.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, 10)
return {
"lead": struct.unpack(">f", data[2:4] + data[0:2])[0], # mg/L
"electrode_signal": struct.unpack(">f", data[6:8] + data[4:6])[0], # mV
"temperature": struct.unpack(">f", data[18:20] + data[16:18])[0], # °C
}
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 (Uno, Mega, ESP32, ESP8266, MKR, Pico)
El sketch usa la biblioteca Agrinovo: en el Arduino IDE abra Sketch > Include Library > Manage Libraries e instale "Agrinovo". La biblioteca elige el puerto serial según la placa, y los pines están al inicio de AgrinovoDefaultPort.h. DE y RE del transceptor van a un mismo pin de salida.
// Agrinovo PB-100 lead probe
// Prints lead, electrode signal and temperature every 5 seconds.
//
// Sensor cable
// Red supply +, 12-24 V DC
// Black supply ground, joined to the board's ground
// Yellow RS485 A
// White 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/ion-selective/pb-100-probe/
#include <Agrinovo.h>
#include <AgrinovoDefaultPort.h>
const int DE_PIN = 4; // transceiver DE and RE, tied together
AgrinovoBus bus(AGRINOVO_PORT, DE_PIN);
AgrinovoPB100 probe(bus); // Modbus address 1
void setup() {
Serial.begin(115200);
agrinovoPortBegin(9600);
bus.begin();
}
void loop() {
if (probe.read()) {
Serial.print("Lead: ");
Serial.print(probe.lead(), 2);
Serial.println(" mg/L");
Serial.print("Electrode signal: ");
Serial.print(probe.electrodeSignal(), 1);
Serial.println(" mV");
Serial.print("Temperature: ");
Serial.print(probe.temperature(), 1);
Serial.println(" °C");
} else {
Serial.println(probe.errorText());
}
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 |
|---|---|---|---|
| Lead | mg/L | 0x0000 | Flotante de 32 bits en dos registros, palabra baja primero |
| Electrode signal | mV | 0x0002 | Flotante de 32 bits en dos registros, palabra baja primero |
| Temperature | °C | 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 PB-100 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 |
|---|---|
| Ion Range | 0.2 to 1000 ppm (customizable up to 21000 ppm) |
| Ion Resolution | 0.01 ppm |
| Ion Accuracy | ±5% F.S. |
| Repeatability | ±2% |
| Slope | 56 ± 3 mV |
| Response Time | 30 s to 95% response |
| pH Range | 0 to 12 pH |
| Output Impedance | 20 to 50 MΩ |
| Isopotential Point | 50,000 ppm |
| Interference | Ag⁺, Hg²⁺, Cu²⁺, high levels of Cd²⁺, Fe²⁺ |
| Temperature Range | 0 to 60°C |
| Temperature Resolution | 0.1°C |
| Temperature Accuracy | ±0.5°C |
| Temperature Sensor | Thermistor NTC10K |
| Temperature Compensation | Automatic / Manual |
| Pressure Range | 0 to 2 atm |
Electrical Characteristics
| Parameter | Specification |
|---|---|
| Supply Voltage | 12-24 VDC |
| Power Consumption | ≤0.5W |
| Isolation | 2500Vrms |
| Housing Material | PMMA + PVC |
| Reference Electrode | Double salt bridge, single hole ceramic liquid junction |
| Mounting Thread | 3/4 inch front thread |
Communication Settings
| Parameter | Value |
|---|---|
| Protocol | Modbus-RTU |
| Baud Rate | 9600 bps (configurable: 1200/2400/4800/9600/19200) |
| Data Bits | 8 |
| Parity | None |
| Stop Bits | 1 |
| Default Address | 0x01 (range 1 to 247) |
Notes:
- All registers are dual-byte (16-bit). Transmitted high byte first, low byte second.
- Negative integers use two’s complement (−1 = 0xFFFF, −2 = 0xFFFE).
- CRC16: Standard Modbus, high byte first, low byte second. CRC bypass code: 0x2A2A.
- Command frame length is fixed at 8 bytes. Frames shorter than 8 bytes after a 0.1s gap are ignored.
Register Map
The sensor has three register groups: Measurement (real-time data), Parameter (configuration), and Information (device status/identity).
Measurement Registers - Integer Mode (Function 0x04)
| Address | Description | Range | Scaling | R/W |
|---|---|---|---|---|
| 0x0000 | Ion Concentration | 0 to 20000 | See decimal register | R |
| 0x0001 | Ion Decimal + Unit | - | See unit table | R |
| 0x0002 | Electrode Signal | −7500 to 7500 | ÷10 → mV | R |
| 0x0003 | Signal Decimal + Unit | - | See unit table | R |
| 0x0008 | Temperature | −100 to 1100 | ÷10 → °C | R |
| 0x0009 | Temp Decimal + Unit | - | See unit table | R |
Over-range indicators: 0x7FFF = above upper limit, 0x8000 = below lower limit.
Measurement Registers - Float Mode (Function 0x03)
Each value occupies 2 registers (float32):
| Address | Description | Range | Unit | R/W |
|---|---|---|---|---|
| 0x0000 to 0x0001 | Ion Concentration | 0.000 to 20000 | ppm | R |
| 0x0002 to 0x0003 | Electrode Signal | −750.0 to 750.0 | mV | R |
| 0x0008 to 0x0009 | Temperature | −10.0 to 110.0 | °C | R |
Parameter Registers (Function 0x03 read / 0x06 write)
| Address | Description | Range | Default | R/W |
|---|---|---|---|---|
| 0x0019 | Calibration Status | BIT1 - BIT5 (see calibration) | - | R/D |
| 0x001C | Electrode Efficiency | 70.0 to 130.0% (int: 700 to 1300) | 100.0% | R/D |
| 0x001D | Calibrated Point Count | 0 to 5 | 0 | R/D |
| 0x001E | Slave Address | 1 to 247 (0xFF = broadcast) | 1 | R/W |
| 0x001F | Baud Rate | 0:1200 · 1:2400 · 2:4800 · 3:9600 · 4:19200 | 3 (9600) | R/W |
| 0x0020 | Temp Compensation Type | 0: Manual · 1: Automatic | 1 (Auto) | R/W/D |
| 0x0021 | Temp Setpoint / Offset | Manual: −10.0 to 110.0°C · Auto: −10.0 to 10.0°C (×10) | 25.0 / 0.0°C | R/W/D |
| 0x0023 | Ion Valence | 0: Not set · 1: Monovalent · 2: Divalent | - | R/W |
R/W/D: D = reset to default by factory restore. Registers without D are unaffected by factory restore.
Information Registers (Function 0x03 read / 0x06 write)
| Address | Description | Values | R/W |
|---|---|---|---|
| 0x0040 | Working Mode | 0x0010: Measurement · 0x0050: Settings · 0x0060: Calibration | R/W |
| 0x0041 | Mode Parameter | See settings/calibration sections | R/W |
| 0x0042 | Work Event | - | R |
| 0x0043 | Calibration Status & Operation | See calibration section | R/W |
| 0x0044 | Device Type | 0x0010 (ION) | R |
| 0x0045 | Device Model | 0x1210 (ION1210) | R |
| 0x0046 | Software Version | BCD coded | R |
| 0x0047 | Hardware Version | BCD coded | R |
| 0x0048 | Serial Number High | BCD coded | R |
| 0x0049 | Serial Number Low | BCD coded | R |
Reading Data
Integer Mode - Read ion concentration, electrode signal, and temperature (Function 0x04)
Read 10 registers from 0x0000:
Request: 01 04 00 00 00 0A 70 0D
Response: 01 04 14 03 EB 02 11 03 EC 01 00 00 00 00 00 00 00 00 00 00 FA 01 0B F1 B7
Decoding:
| Register | Hex | Decimal | Scaling | Result |
|---|---|---|---|---|
| 0x0000 Ion Value | 0x03EB | 1000 | ÷100 (from 0x0001) | 10.00 ppm |
| 0x0002 Electrode Signal | 0x03EC | 1001 | ÷10 (from 0x0003) | 100.1 mV |
| 0x0008 Temperature | 0x00FA | 250 | ÷10 (from 0x0009) | 25.0°C |
Float Mode - Read ion concentration, electrode signal, and temperature (Function 0x03)
Read 10 registers from 0x0000:
Request: 01 03 00 00 00 0A C5 CD
Response: 01 03 14 00 00 41 20 33 33 42 C8 00 00 00 00 00 00 00 00 E3 E8 41 C7 43 0C
Decoding:
| Register | Float Value | Result |
|---|---|---|
| 0x0000 to 0x0001 Ion | 10.00 | 10.00 ppm |
| 0x0002 to 0x0003 Electrode | 100.1 | 100.1 mV |
| 0x0008 to 0x0009 Temperature | 24.986282 | 25.0°C |
Address Configuration
Change Address (0x01 → 0x02)
Request: 01 06 00 1E 00 02 68 0D
Response: 01 06 00 1E 00 02 68 0D
Change Baud Rate (9600 → 2400)
Request: 01 06 00 1F 00 01 79 CC
Response: 01 06 00 1F 00 01 79 CC
Change Ion Valence (→ Divalent)
Request: 01 06 00 23 00 02 F9 C1
Response: 01 06 00 23 00 02 F9 C1
Broadcast Discovery
Use address 0xFF with only one device connected.
Calibration
The ion electrode requires calibration with 2 or more standard solutions before it can calculate ion concentration. Up to 5 calibration points are supported.
Standard Solution Codes
| Concentration | Code | Bit Position |
|---|---|---|
| 0.1 ppm | 0x0002 | BIT1 |
| 1 ppm | 0x0004 | BIT2 |
| 10 ppm | 0x0008 | BIT3 |
| 100 ppm | 0x0010 | BIT4 |
| 1000 ppm | 0x0020 | BIT5 |
Calibration Flow
- Place the electrode in standard solution.
- Write the standard solution code to calibration register (0x0043).
- Wait for completion. Read 0x0043 status:
- 0: Calibration successful (returned to measurement mode)
- 1: Calibrating - read again shortly
- 2: No valid standard value received within 180s (returned to measurement)
- 3: Signal unstable or out of range within 180s (returned to measurement)
- 4: Sensor performance (efficiency/offset) out of limits (returned to measurement)
Calibration Notes
- Each successful calibration calculates electrode efficiency. If out of range, error 4 is returned.
- Writing 0x7FFF to 0x0043 clears all calibration data.
- Calibration status can be read from register 0x0019 and electrode efficiency from 0x001C.
- Ion valence must be set to divalent (write 0x0002 to register 0x0023) before calibration, as Pb²⁺ is a divalent ion.
Calibration Commands
| Command | Addr | Func | Register | Value | CRC |
|---|---|---|---|---|---|
| Clear all calibration | 01 | 06 | 00 43 | 7F FF | 18 6E |
| Calibrate 0.1 ppm | 01 | 06 | 00 43 | 00 02 | F9 DF |
| Calibrate 1 ppm | 01 | 06 | 00 43 | 00 04 | 79 DD |
| Calibrate 10 ppm | 01 | 06 | 00 43 | 00 08 | 79 D8 |
| Calibrate 100 ppm | 01 | 06 | 00 43 | 00 10 | 79 D2 |
| Calibrate 1000 ppm | 01 | 06 | 00 43 | 00 20 | 79 C6 |
| Query calibration status | 01 | 03 | 00 43 | 00 01 | 75 DE |
Temperature Compensation
Set to Manual Compensation
Request: 01 06 00 20 00 00 88 00
Response: 01 06 00 20 00 00 88 00
When manual: register 0x0021 is the manual temperature setpoint (×10).
Set to Automatic Compensation
Request: 01 06 00 20 00 01 49 C0
Response: 01 06 00 20 00 01 49 C0
When automatic: register 0x0021 is the temperature offset (×10). Default 0.0°C.
Set Temperature Offset to −5.0°C
Request: 01 06 00 21 FF CE 19 A4
Response: 01 06 00 21 FF CE 19 A4
Factory Reset
Factory reset requires two sequential commands:
Step 1 - Enter Settings Mode (write 0x0050 to 0x0040):
Request: 01 06 00 40 00 50 88 22
Response: 01 06 00 40 00 50 88 22
Step 2 - Execute Factory Reset (write 0x7FFF to 0x0041):
Request: 01 06 00 41 7F FF B9 AE
Response: 01 06 00 41 7F FF B9 AE
This clears all calibration data, resets temperature mode to automatic, offset to 0.0°C, and restores default parameter values. The device will restart.
Error Handling
When an invalid command is received, the device responds with the function code + 0x80:
| Error Code | Description |
|---|---|
| 01 | Invalid function code (only 0x03, 0x04, 0x06 supported) |
| 02 | Invalid register address |
| 03 | Invalid register count (exceeds register group boundary) |
| 04 | Invalid modification value (out of range) |
| 05 | CRC error |
| 06 | Write to read-only register |
Common Commands Reference
Read Registers
| Command | Addr | Func | Start | Count | CRC |
|---|---|---|---|---|---|
| Read measurement (integer) | 01 | 04 | 00 00 | 00 0A | 70 0D |
| Read measurement (float) | 01 | 03 | 00 00 | 00 0A | C5 CD |
| Read all parameters | 01 | 03 | 00 19 | 00 0C | 94 08 |
| Read all info registers | 01 | 03 | 00 40 | 00 0A | C4 19 |
Write Registers
| Command | Addr | Func | Register | Value | CRC |
|---|---|---|---|---|---|
| Set address to 0x02 | 01 | 06 | 00 1E | 00 02 | 68 0D |
| Set baud to 2400 | 01 | 06 | 00 1F | 00 01 | 79 CC |
| Temp comp → manual | 01 | 06 | 00 20 | 00 00 | 88 00 |
| Temp comp → auto | 01 | 06 | 00 20 | 00 01 | 49 C0 |
| Temp offset −5.0°C | 01 | 06 | 00 21 | FF CE | 19 A4 |
| Ion valence → monovalent | 01 | 06 | 00 23 | 00 01 | B9 C0 |
| Ion valence → divalent | 01 | 06 | 00 23 | 00 02 | F9 C1 |
Unit Lookup Table
The low byte of “Decimal + Unit” registers (0x0001, 0x0003, 0x0009) contains the unit code:
| Code | Unit | Code | Unit | Code | Unit |
|---|---|---|---|---|---|
| 0x00 | mV | 0x01 | nA | 0x02 | uA |
| 0x03 | mA | 0x04 | Ω | 0x05 | KΩ |
| 0x06 | MΩ | 0x07 | uS | 0x08 | mS |
| 0x09 | S | 0x0A | pH | 0x0B | °C |
| 0x0C | °F | 0x0D | ug/L | 0x0E | mg/L |
| 0x0F | g/L | 0x10 | ppb | 0x11 | ppm |
| 0x12 | ppt | 0x13 | % | 0x14 | mbar |
| 0x15 | bar | 0x16 | mmHg |
The high byte contains the number of decimal places for the value register.
Revision History
| Rev | Date | Changes |
|---|---|---|
| 1.0 | June 2026 | Initial release |
| 1.1 | August 2026 | Layout revision; calibration command table corrected |
| 1.2 | October 2026 | New layout; corrected Modbus example CRC values |
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.