Automated agricultural irrigationRaspberry Pi (Docker)Modbus TCPControl
Driving a Schneider Altivar 320 pump over Modbus TCP
Starting a pump through a Schneider Altivar 320 is more than writing a run bit: the drive follows the DriveCom (CiA402) state machine, and skipping a transition leaves it silently stopped. This Python example for Raspberry Pi walks the full sequence over Modbus TCP — Shutdown, Switch On, Enable Operation — sets the speed reference in rpm and supervises status, current and pipe pressure. It mirrors the pump control used in a real automated irrigation deployment.
The DriveCom sequence, demystified
The ATV320 expects command words 0x0006, 0x0007 and 0x000F written in order to register CMD (8501), with the speed reference loaded in LFRD (8602) beforehand. The example wraps this in an arrancar_bomba() helper with a short delay between transitions. Stopping is graceful too: writing 0x0006 again triggers the deceleration ramp instead of a freewheel stop that hammers the pipework.
Unit ID 255 and the registers that matter
Schneider's Modbus TCP adapter answers on Unit ID 255 by default — the single most common reason a first connection attempt times out. Beyond CMD and LFRD, the script polls ETA (3201) for drive status and fault bit, RFRD (8604) for actual rpm and LCR (3204) for motor current, giving Node-RED everything needed to detect a stalled or faulted pump.
Pressure on the drive's own analog input
A 4-20 mA transducer (0-10 bar) wired to the drive's AI3 input saves a separate I/O module: the Raspberry reads the current value by Modbus and scales it linearly to bar. Out-of-range readings are clamped, so a broken sensor wire shows as 0 bar instead of a negative value, which the alarm logic in MySQL picks up immediately.
A snippet from the implementation
Straight from the example as deployed on the Raspberry Pi (Docker) — copy it freely:
The full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.
Frequently asked questions
Why does my Altivar 320 not respond on Modbus TCP?
Check the Unit ID first — the embedded Ethernet adapter defaults to 255, not 1. Also confirm the command channel is set to Modbus in the drive configuration menu, otherwise writes to CMD are ignored.
Can I stop the pump instantly instead of using the ramp?
Yes, the DriveCom command word supports Quick Stop (0x0002). In irrigation we prefer the deceleration ramp because slamming a pump shut causes water hammer in long pipe runs.
How do I know the drive is in fault?
Read the ETA status word at register 3201 and test bit 3. The example prints FALLO and aborts the cycle when it is set; in production the event is logged to MySQL and pushed by Telegram.