sortie_analogique.ino
The Opta analog output delivers 0-10 V in millivolts: this sketch generates a full triangular ramp, ideal to test a speed drive or proportional valve. The ramp is clamped and writes go through the official PLC API.
Hardware
An STMicroelectronics Opta PLC (real-time STM32H747 + secure i.MX RT1052 companion) programmed with the Arduino PLC environment, 24 V DIN-rail supply. 0-10 V actuator (drive, valve) on the AO0 and analog GND terminals.
Wiring
AO0 to the drive setpoint input, analog 0 V to the setpoint ground (often isolated from power ground: read the drive manual).
How it works
AnalogOut.write(CANAL, mv) drives the DAC; the incremental ramp at 20 steps/s avoids setpoint shocks on the actuator.
Running it
Install the Arduino PLC boards manager, select “Opta PLC”, wire USB/DFU and upload. The sketch runs on the real-time STM32H747 side.
Variants
Replace the ramp with a setpoint written by the SCADA over Modbus, or close a temperature loop (PID on AI + AO).
sortie_analogique.ino
// Opta PLC : rampe de consigne 0-10 V sur AO0 (sortie analogique).
// Usage typique : consigne de variateur, vanne 0-10 V, potentiomètre numérique.
#include "PLCContainer.h"
PLCContainer PLC;
const int CANAL = OPTA_AO_0; // sortie analogique 0 (0-10 000 mV)
const unsigned long PAS_MS = 50; // 20 pas/s
int mv = 0; // valeur courante en millivolts
int sens = 100; // +100 mV par pas
unsigned long t0 = 0;
// Rampe douce : on limite aussi la dérivée pour ne pas brusquer l'actionneur.
void ecrire_mv(int v) {
v = constrain(v, 0, 10000);
PLC.AnalogOut.write(CANAL, v); // API officielle : millivolts
}
void setup() {
Serial.begin(115200);
PLC.begin();
ecrire_mv(0);
Serial.println("Rampe 0-10 V sur AO0 (Ctrl/Reset pour arreter)");
}
void loop() {
if (millis() - t0 < PAS_MS) return;
t0 = millis();
mv += sens;
if (mv >= 10000) { mv = 10000; sens = -100; } // sommet de rampe
if (mv <= 0) { mv = 0; sens = 100; } // pied de rampe
ecrire_mv(mv);
if ((mv % 1000) == 0) Serial.printf("AO0 = %d mV (%.1f V)\n", mv, mv / 1000.0f);
}