How to check the Raspberry PLC outputs

June 15, 2026 by
How to check the Raspberry PLC outputs
Boot & Work Corp. S.L, Queralt del Águila Munté

To verify that the outputs of your Raspberry PLC are working correctly, the recommended approach is to run a C++ test program that toggles all digital, analogue, and relay outputs every second. If the corresponding LEDs turn on and off, the outputs are working. If they do not respond, the problem is in the software configuration or the hardware itself.

Installing the rpiplc-lib library

The test program depends on the rpiplc-lib. Follow these steps to install it:

  1. Instala git si no está presente: sudo apt update && sudo apt install git
  2. Clona el repositorio en un directorio de tu elección: git clone https://github.com/Industrial-Shields/rpiplc-lib.git
  3. Entra en el directorio y compila: cd rpiplc-lib && make
  4. Instala en el sistema: sudo make install

La librería instala sus cabeceras en /usr/local/include/rpiplc y la librería compilada en /usr/local/lib.

Output test program

Guarda el siguiente código en un archivo llamado test_outputs.cpp. El programa usa condicionales de preprocesador para activar los pines de salida correctos según el modelo de Raspberry PLC.

#include <rpiplc.h>

void setDigitalPins(int state) {
    digitalWrite(PWM3, state);
    digitalWrite(PWM2, state);
    digitalWrite(PWM1, state);

    #if defined(RPIPLC_21) || defined(RPIPLC_38AR) || defined(RPIPLC_42) || defined(RPIPLC_53ARR) || defined(RPIPLC_54ARA) || defined(RPIPLC_57AAR) || defined(RPIPLC_58)
        digitalWrite(Q0_0, state); digitalWrite(Q0_1, state); digitalWrite(Q0_2, state);
        digitalWrite(Q0_3, state); digitalWrite(Q0_4, state); digitalWrite(Q0_5, state);
        digitalWrite(Q0_6, state); digitalWrite(Q0_7, state);
    #elif defined(RPIPLC_19R) || defined(RPIPLC_38R) || defined(RPIPLC_50RRA) || defined(RPIPLC_57R)
        digitalWrite(Q0_0, state); digitalWrite(Q0_1, state); digitalWrite(Q0_2, state);
        digitalWrite(R0_1, state); digitalWrite(R0_2, state); digitalWrite(R0_3, state);
        digitalWrite(R0_4, state); digitalWrite(R0_5, state); digitalWrite(R0_6, state);
        digitalWrite(R0_7, state); digitalWrite(R0_8, state);
    #endif

    #if defined(RPIPLC_42) || defined(RPIPLC_57AAR) || defined(RPIPLC_58)
        digitalWrite(Q1_0, state); digitalWrite(Q1_1, state); digitalWrite(Q1_2, state);
        digitalWrite(Q1_3, state); digitalWrite(Q1_4, state); digitalWrite(Q1_5, state);
        digitalWrite(Q1_6, state); digitalWrite(Q1_7, state);
    #elif defined(RPIPLC_38R) || defined(RPIPLC_38AR) || defined(RPIPLC_50RRA) || defined(RPIPLC_53ARR) || defined(RPIPLC_54ARA) || defined(RPIPLC_57R)
        digitalWrite(Q1_0, state); digitalWrite(Q1_1, state); digitalWrite(Q1_2, state);
        digitalWrite(R1_1, state); digitalWrite(R1_2, state); digitalWrite(R1_3, state);
        digitalWrite(R1_4, state); digitalWrite(R1_5, state); digitalWrite(R1_6, state);
        digitalWrite(R1_7, state); digitalWrite(R1_8, state);
    #endif

    #if defined(RPIPLC_50RRA) || defined(RPIPLC_54ARA) || defined(RPIPLC_58)
        digitalWrite(Q2_0, state); digitalWrite(Q2_1, state); digitalWrite(Q2_2, state);
        digitalWrite(Q2_3, state); digitalWrite(Q2_4, state); digitalWrite(Q2_5, state);
        digitalWrite(Q2_6, state); digitalWrite(Q2_7, state);
    #elif defined(RPIPLC_53ARR) || defined(RPIPLC_57AAR) || defined(RPIPLC_57R)
        digitalWrite(Q2_0, state); digitalWrite(Q2_1, state); digitalWrite(Q2_2, state);
        digitalWrite(R2_1, state); digitalWrite(R2_2, state); digitalWrite(R2_3, state);
        digitalWrite(R2_4, state); digitalWrite(R2_5, state); digitalWrite(R2_6, state);
        digitalWrite(R2_7, state); digitalWrite(R2_8, state);
    #endif
}

void setAnalogPins(int value) {
    #if defined(RPIPLC_21) || defined(RPIPLC_38AR) || defined(RPIPLC_42) || defined(RPIPLC_53ARR) || defined(RPIPLC_54ARA) || defined(RPIPLC_57AAR) || defined(RPIPLC_58)
        analogWrite(A0_5, value); analogWrite(A0_6, value); analogWrite(A0_7, value);
    #elif defined(RPIPLC_19R) || defined(RPIPLC_38R) || defined(RPIPLC_50RRA) || defined(RPIPLC_57R)
        analogWrite(A0_0, value); analogWrite(A0_1, value); analogWrite(A0_2, value);
    #endif

    #if defined(RPIPLC_42) || defined(RPIPLC_57AAR) || defined(RPIPLC_58)
        analogWrite(A1_5, value); analogWrite(A1_6, value); analogWrite(A1_7, value);
    #elif defined(RPIPLC_38R) || defined(RPIPLC_38AR) || defined(RPIPLC_50RRA) || defined(RPIPLC_53ARR) || defined(RPIPLC_54ARA) || defined(RPIPLC_57R)
        analogWrite(A1_0, value); analogWrite(A1_1, value); analogWrite(A1_2, value);
    #endif

    #if defined(RPIPLC_50RRA) || defined(RPIPLC_54ARA) || defined(RPIPLC_58)
        analogWrite(A2_5, value); analogWrite(A2_6, value); analogWrite(A2_7, value);
    #elif defined(RPIPLC_53ARR) || defined(RPIPLC_57AAR) || defined(RPIPLC_57R)
        analogWrite(A2_0, value); analogWrite(A2_1, value); analogWrite(A2_2, value);
    #endif
}

int main() {
    initPins();

    while (true) {
        setDigitalPins(1);
        setAnalogPins(2000);
        delay(1000);

        setDigitalPins(0);
        setAnalogPins(0);
        delay(1000);
    }
}

Compiling and running the test

Compila el programa con el siguiente comando, sustituyendo RPIPLC_XX por el modelo que corresponda a tu unidad (por ejemplo RPIPLC_58):

g++ -o test_outputs test_outputs.cpp -L /usr/local/lib -l rpiplc -I /usr/local/include/rpiplc -D RPIPLC_XX

Los defines de modelo disponibles son: RPIPLC_19R, RPIPLC_21, RPIPLC_38AR, RPIPLC_38R, RPIPLC_42, RPIPLC_50RRA, RPIPLC_53ARR, RPIPLC_54ARA, RPIPLC_57AAR, RPIPLC_57R, RPIPLC_58.

Run the compiled binary as root:

sudo ./test_outputs

The program toggles all outputs every second. Watch the LED panel on the PLC. If any LED does not respond, check the wiring and library installation.

Resources and documentation

​Search in our Blog

How to check the Raspberry PLC outputs
Boot & Work Corp. S.L, Queralt del Águila Munté June 15, 2026
Share this post
Tags

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

PLC Comparison