Raspberry Pi 3, GPIO

Raspberry Pi GPIO – Interaktive GPIO Info
Pinout!

What are the ID EEPROM pins and what can they be used for?

Frameworks

Raspberry gPIo (learn.sparkfun.com)
Official C/C++ library ?
RPi GPIO Code Samples

  • SYSFS
  • Python
  • bcm2816 Library
  • WiringPi
  • pigpio

SYSFS

Introduction to accessing the Raspberry Pi’s GPIO in C++ (sysfs)
github.com/halherta/RaspberryPi-GPIOClass-v1
Exploring Raspberry Pi: Chapter 6: Interfacing to the Raspberry Pi Input/Outputs

Python

GPIO – Event / Using interrupt-driven GPIO in Raspian
raspberry-gpio-python, A Python module to control the GPIO on a Raspberry Pi
gpiozero, A simple interface to GPIO devices with Raspberry Pi

RPi.GPIO update and detecting BOTH rising and falling edges
How to use interrupts with Python on the Raspberry Pi and RPi.GPIO – part 2

void *poll_thread(void *threadarg)
{
    struct epoll_event events;
    char buf;
    struct timeval tv_timenow;
    unsigned long long timenow;
    struct gpios *g;
    int n;

    thread_running = 1;
    while (thread_running) {
        n = epoll_wait(epfd_thread, &events, 1, -1);
    [...]
}

int add_edge_detect(unsigned int gpio, unsigned int edge, int bouncetime)
// return values:
// 0 - Success
// 1 - Edge detection already added
// 2 - Other error
{
    pthread_t threads;
    struct epoll_event ev;
    
    [...]
    // create epfd_thread if not already open
    if ((epfd_thread == -1) && ((epfd_thread = epoll_create(1)) == -1))
        return 2;

    // add to epoll fd
    ev.events = EPOLLIN | EPOLLET | EPOLLPRI;
    ev.data.fd = g->value_fd;
    if (epoll_ctl(epfd_thread, EPOLL_CTL_ADD, g->value_fd, &ev) == -1) {
        remove_edge_detect(gpio);
        return 2;
    }
    g->thread_added = 1;
    [...]
}

bcm2816 Library

GPIO register access
Constants for passing to and from library functions

bcm2835_set_debug(1)
bcm2835_gpio_len()

Sensorian 1.0 – C API Reference Guide Library
Raspberry Pi – detect button press
[POSIX-PIGPIO] Real-time thread on GPIO interrupt?
C program a button to perform a task once when pressed (latch)

int main(int argc, char **argv)
{
    pthread_attr_t attr;
    struct sched_param param;
    pthread_t thread;

    bcm2835_init();
    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT);
    bcm2835_gpio_aren(PIN);

    pthread_attr_init(&attr);
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
    pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);

    param.sched_priority = 99;
    pthread_attr_setschedparam(&attr, &param);
    
    while (1)
    {
        if (bcm2835_gpio_eds(PIN))
        {
            bcm2835_gpio_set_eds(PIN);
            pthread_create(&thread, &attr, callback_acq, NULL);
        }
    }
    bcm2835_close();
    return 0;
}

WiringPi

The GPIO utility
Understand “gpio readall” Bash shell command output on Raspberry Pi
how to read output of gpio readall

pigpio

The pigpio library

Interrupt / Event Detection / poll() / epoll()

GPIO state monitoring via command line?
Raspberry Pi And The IoT In C – Input And Interrupts (Page 1 of 4)
Raspberry Pi And The IoT In C – Input And Interrupts (Page 2 of 4)
What’s the difference between epoll, poll, threadpool?

Off-Topic

How to Use the GPIO on the BeagleBone Black

Leave a Reply

Your email address will not be published.