Hello guys,
Im super ecxited- I managed to work with the lg c library on the Pi 5 with the help of chat gpt.
https://github.com/joan2937/lg
https://abyz.me.uk/lg/lgpio.html
Features
reading and writing GPIO singly and in groups
software timed PWM and waves
GPIO callbacks
pipe notification of GPIO alerts
I2C wrapper
SPI wrapper
serial link wrapper
a simple interface to start and stop new threads
Here is a code for a blink project:
Im super ecxited- I managed to work with the lg c library on the Pi 5 with the help of chat gpt.
https://github.com/joan2937/lg
https://abyz.me.uk/lg/lgpio.html
Features
reading and writing GPIO singly and in groups
software timed PWM and waves
GPIO callbacks
pipe notification of GPIO alerts
I2C wrapper
SPI wrapper
serial link wrapper
a simple interface to start and stop new threads
Here is a code for a blink project:
Code:
#include <stdio.h>#include <stdlib.h>#include <unistd.h> // Include for usleep#include <lgpio.h>#define LED_GPIO 26#define BLINK_DELAY_MS 1000 // delay in milliseconds for blinking (1 second)int main(int argc, char *argv[]) { int handle; int state = 0; // initial state of the LED // Open /dev/gpiochip4 handle = lgGpiochipOpen(4); if (handle >= 0) { // Claim GPIO pin as output if (lgGpioClaimOutput(handle, 0, LED_GPIO, state) == LG_OKAY) { printf("LED on GPIO %d is now blinking.\n", LED_GPIO); // Blink the LED infinitely while (1) { // Toggle the state of the LED state = !state; lgGpioWrite(handle, LED_GPIO, state); // Delay for blinking usleep(BLINK_DELAY_MS * 1000); // usleep() takes microseconds } } else { fprintf(stderr, "Error: Failed to claim GPIO pin as output.\n"); } // Close GPIO chip lgGpiochipClose(handle); } else { fprintf(stderr, "Error: Failed to open GPIO chip.\n"); } return 0;}
Statistics: Posted by Ido1212 — Thu May 02, 2024 11:18 pm