gpiod-dio-industrial-switch-5.ino

BIOSSTAR BIWCL-PAT: 3.5" Industrial SBC with Intel Wildcat Lake · File : gpiod-dio-industrial-switch-5.ino · Language : c · Use case : Lecture d'un interrupteur industriel et contrôle d'un voyant via le header DIO 8 bits.

C program using libgpiod to read a digital input and control a digital output on the card's DIO header.

Hardware: Switch between GND and DIO Pin 1 (Input), LED + resistor between DIO Pin 0 (Output) and GND. The 8-bit DIO header maps to Linux GPIOs. Compilation: sudo apt install libgpiod-dev && gcc dio_control.c -o dio_control -lgpiod. Execution: sudo ./dio_control. Note: Pin numbering (0/1) may vary depending on the specific BIOS/UEFI electrical map of the BIWCL-PAT, verify with gpioinfo.

gpiod-dio-industrial-switch-5.ino

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gpiod.h>

#define CHIP_NAME "gpiochip0" /* Vérifier avec 'gpioinfo' sur Ubuntu 24.04 */
#define PIN_OUT 0 /* Sortie pour LED/Relais */
#define PIN_IN 1  /* Entrée pour Bouton Poussoir */

int main() {
    struct gpiod_chip *chip;
    struct gpiod_line *line_out, *line_in;
    int value;

    chip = gpiod_chip_open_by_name(CHIP_NAME);
    if (!chip) { fprintf(stderr, "Impossible d'ouvrir la puce GPIO\n"); return 1; }

    line_out = gpiod_chip_get_line(chip, PIN_OUT);
    line_in = gpiod_chip_get_line(chip, PIN_IN);

    if (gpiod_line_request_output(line_out, "biwcl-demo", 0) < 0) {
        fprintf(stderr, "Erreur config sortie\n"); gpiod_chip_close(chip); return 1;
    }
    if (gpiod_line_request_input(line_in, "biwcl-demo") < 0) {
        fprintf(stderr, "Erreur config entrée\n"); gpiod_chip_close(chip); return 1;
    }

    printf("Surveillance DIO active (Ctrl+C pour quitter)...\n");
    while(1) {
        value = gpiod_line_get_value(line_in);
        if (value == 1) { /* Bouton pressé (circuit ouvert ou fermé selon montage) */
            gpiod_line_set_value(line_out, 1); // Allumer voyant
            printf("Bouton Pressé -> Voyant ON\n");
        } else {
            gpiod_line_set_value(line_out, 0); // Éteindre voyant
        }
        usleep(100000); // Pause 100ms pour éviter le rebond
    }

    gpiod_line_release(line_out);
    gpiod_line_release(line_in);
    gpiod_chip_close(chip);
    return 0;
}

← Back to the board