| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A comprehensive Lua C library wrapper for libgpiod, providing complete GPIO control functionality for Linux systems.
This library provides a complete Lua binding for the libgpiod library, allowing you to control GPIO pins on Linux systems from Lua scripts. It supports all major gpiod features including input/output operations, event handling, bulk operations, and chip enumeration.
On Ubuntu/Debian:
sudo apt-get install libgpiod-dev lua5.4-dev build-essentialOn Fedora/RHEL:
sudo dnf install libgpiod-devel lua-devel gccmakesudo make installlocal gpiod = require("gpiod")
-- Open GPIO chip
local chip = gpiod.chip_open("gpiochip0")
-- Get a GPIO line
local line = chip:get_line(18)
-- Configure as output
line:request_output("my_app", 0)
-- Set high
line:set_value(1)
-- Clean up
line:release()
chip:close()local gpiod = require("gpiod")
local chip = gpiod.chip_open("gpiochip0")
local line = chip:get_line(24)
-- Request rising edge events
line:request_rising_edge_events("button_monitor")
print("Waiting for button press...")
if line:event_wait(5.0) then -- 5 second timeout
local event = line:event_read()
print("Button pressed at:", event:timestamp())
print("Event type:", event:event_type())
end
line:release()
chip:close()local gpiod = require("gpiod")
local chip = gpiod.chip_open("gpiochip0")
local lines = chip:get_lines({18, 19, 20, 21})
-- Configure all as outputs with initial values
lines:request_output("led_controller", {0, 1, 0, 1})
-- Set all values at once
lines:set_values({1, 1, 1, 1})
-- Read all values
local values = lines:get_values()
for i, value in ipairs(values) do
print("Line " .. (i-1) .. ": " .. value)
end
lines:release()
chip:close()Run the example:
lua gpiod_example.luaTest module loading:
make testBuild and test using Docker (recommended for CI/CD):
# Build the Docker image
docker build -t lua-gpiod-test .
# Run tests in container
docker run --rm lua-gpiod-test
# Interactive shell for manual testing
docker run --rm -it lua-gpiod-test /bin/bashThe Docker environment includes:
This project is licensed under the MIT License - see the LICENSE file for details.
This project is hosted at: https://github.com/HsOjo/lua-gpiod
Contributions are welcome! Please feel free to submit issues and pull requests at the GitHub repository.
If you get permission errors, you may need to add your user to the gpio group:
sudo usermod -a -G gpio $USERList available GPIO chips:
gpiodetectMake sure libgpiod is installed and the shared library is in the correct path.
| Back | FazBrowse Home | New Git URL |