Qt library and tool for working with GPIOs.
 
 
 
 
Go to file
jenkins ccc1e6b80a Jenkins release build 1.14.2 2026-02-19 12:13:04 +01:00
debian-qt5 Jenkins release build 1.14.2 2026-02-19 12:13:04 +01:00
debian-qt6 Add libgpiod support to libnymea-gpio 2025-12-19 11:38:58 +01:00
docs Update license text and add SPDX identifier 2025-12-02 09:52:54 +01:00
libnymea-gpio Add gpiod API V2 support 2025-12-19 13:03:51 +01:00
nymea-gpio-tool Update source formating using new clang format 2025-12-19 11:35:09 +01:00
tools Add source code formating tool 2025-12-19 11:34:41 +01:00
.clang-format Add clang-format 2025-12-19 11:34:36 +01:00
.gitignore Update .gitignore 2025-11-17 12:10:40 +01:00
COPYING Update license text and add SPDX identifier 2025-12-02 09:52:54 +01:00
COPYING.LESSER Update license text and add SPDX identifier 2025-12-02 09:52:54 +01:00
LICENSE.GPL3 Update copyright 2020-01-23 00:55:03 +01:00
LICENSE.LGPL3 Fix license file name 2022-05-05 17:18:52 +02:00
README.md Update README.md 2026-01-09 10:40:14 +01:00
debian Add Qt6 debian packaging 2025-08-07 11:25:33 +02:00
nymea-gpio.pri Add gpiod API V2 support 2025-12-19 13:03:51 +01:00
nymea-gpio.pro Update license text and add SPDX identifier 2025-12-02 09:52:54 +01:00

README.md

nymea-gpio

nymea-gpio is a small Qt/C++ GPIO helper library for Linux and a matching CLI tool. The library is used by nymea but can be embedded in other Qt applications, while the CLI is handy for scripting, bring-up, and diagnostics.

Components

  • libnymea-gpio: Qt library with Gpio, GpioMonitor, and GpioButton helpers.
  • nymea-gpio-tool: CLI wrapper around the same API.

Supported GPIO backends

  • Linux libgpiod API v1 or v2 (auto-detected via pkg-config).
  • Linux sysfs GPIO (deprecated upstream, build-time opt-in).

Requirements

  • Linux
  • Qt 5 or Qt 6 (qmake)
  • pkg-config and libgpiod (unless building the legacy sysfs backend)
  • dpkg-parsechangelog (from dpkg-dev) to populate VERSION_STRING during build

Build

Build both the library and the CLI:

qmake nymea-gpio.pro
make -j

If you are building with Qt 6, use qmake6 instead of qmake.

To force the legacy sysfs backend:

qmake "CONFIG+=nymea_gpio_sysfs" nymea-gpio.pro
make -j

Install (optional):

make install

The install step drops the library, headers, and a nymea-gpio pkg-config file into your Qt prefix.

CLI usage

nymea-gpio-tool requires a GPIO number and then either sets an output value or monitors input changes.

Set a GPIO output:

nymea-gpio-tool --gpio 17 --set-value 1

Monitor input changes (default edge is both):

nymea-gpio-tool --gpio 17 --monitor --interrupt both

Active-low input or output:

nymea-gpio-tool --gpio 17 --set-value 0 --active-low

Library examples

Output GPIO:

Gpio *gpioOut = new Gpio(23, this);

// Export Gpio
if (!gpioOut->exportGpio()) {
    qWarning() << "Could not export Gpio" << gpioOut->gpioNumber();
    gpioOut->deleteLater();
    return;
}

// Configure Gpio direction
if (!gpioOut->setDirection(Gpio::DirectionOutput)) {
    qWarning() << "Could not set direction of Gpio" << gpioOut->gpioNumber();
    gpioOut->deleteLater();
    return;
}

gpioOut->setValue(Gpio::ValueHigh);

Input GPIO:

Gpio *gpioIn = new Gpio(24, this);

// Export Gpio
if (!gpioIn->exportGpio()) {
    qWarning() << "Could not export Gpio" << gpioIn->gpioNumber();
    gpioIn->deleteLater();
    return;
}

// Configure Gpio direction
if (!gpioIn->setDirection(Gpio::DirectionInput)) {
    qWarning() << "Could not set direction of Gpio" << gpioIn->gpioNumber();
    gpioIn->deleteLater();
    return;
}

qDebug() << "Current value" << gpioIn->value();

Monitor a button with GpioMonitor:

Button::Button(QObject *parent) :
    QObject(parent)
{
    m_button = new GpioMonitor(110, this);
    connect(m_button, &GpioMonitor::valueChanged, this, &Button::stateChanged);
}
bool Button::init()
{
    return m_button->enable();
}
void Button::stateChanged(const bool &value)
{
    if (m_pressed != value) {
        m_pressed = value;
        if (value) {
            emit buttonPressed();
        } else {
            emit buttonReleased();
        }
    }
}

Button helper with debounced GpioButton:

GpioButton *button = new GpioButton(15, this);
button->setName("User button");
if (!button->enable()) {
    qWarning() << "Could not enable the" << this;
    button->deleteLater();
    return;
}

connect(button, &GpioButton::clicked, this, [this, button](){
    qDebug() << button << "clicked";
});

License

  • libnymea-gpio is licensed under the GNU Lesser General Public License v3.0 or (at your option) any later version. See LICENSE.LGPL3.
  • nymea-gpio-tool is licensed under the GNU General Public License v3.0 or (at your option) any later version. See LICENSE.GPL3.