Ir al contenido

Debugging on the shop floor: serial monitor, logic analyzers and common wiring mistakes

Code that works on the bench sometimes fails once it is wired into a real panel. This lesson gives you a short decision path to follow before you start rewriting code, and closes the pump station project.

What you will learn

  • Separate what the PLC reads from what it decides to do.
  • Pick the right tool: Serial Monitor, multimeter or logic analyzer.
  • Check the three wiring mistakes behind most first-install problems.

Step 1: the Serial Monitor, your cheapest tool

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print("I0_0: ");
  Serial.println(digitalRead(I0_0));
  delay(200);
}

Printing the raw input and output states answers the most common question: is the problem in what the PLC reads, or in what it decides to do? Remove the prints afterwards, they add overhead if left running permanently.

Step 2: if the reading is wrong, go upstream of the code

If the printed value does not match the physical signal, the problem is likely wiring, sensor supply voltage or a signal that changes faster than loop() reads it. A multimeter confirms whether the expected voltage is present at the terminal. A logic analyzer or oscilloscope catches fast or intermittent signals that a print is too slow to show.

Step 3: the three wiring checks

  1. The terminal you used matches the pinout diagram for your exact board variant.
  2. The sensor supply voltage matches what your board provides or expects.
  3. There is a shared ground between the PLC and any externally powered sensor.

These three explain a large share of first-install problems that look like code bugs.

Step 4: if the reading is right, debug the logic

For the state machine from lesson 1, print the current state and the inputs only when something changes, not on every pass. Seeing exactly when and why a transition happened is usually faster than stepping through the switch in your head.

State lastState = IDLE;

if (currentState != lastState) {
  Serial.print("State ");
  Serial.print(lastState);
  Serial.print(" -> ");
  Serial.println(currentState);
  lastState = currentState;
}

Where you are now

Your pump station has a state machine, non-blocking timing, a Modbus interface, retained data, a watchdog, a plan for expansion and a dashboard. That is the skeleton of a deployable machine.

Go deeper

You have finished the course. Take the quiz below to check what you have learned.

Calificación
0 0

No hay comentarios por ahora.

para ser el primero en comentar.