{"id":7555,"date":"2018-03-15T13:15:06","date_gmt":"2018-03-15T13:15:06","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=7555"},"modified":"2018-05-07T19:20:39","modified_gmt":"2018-05-07T19:20:39","slug":"raspberry-pi-3-gpio","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=7555","title":{"rendered":"Raspberry Pi 3, GPIO"},"content":{"rendered":"<p><a href=\"http:\/\/raspberrypi.ws\/\">Raspberry Pi GPIO &#8211; Interaktive GPIO Info<\/a><br \/>\n<a href=\"https:\/\/pinout.xyz\/\">Pinout!<\/a><\/p>\n<p><a href=\"https:\/\/raspberrypi.stackexchange.com\/questions\/50348\/what-are-the-id-eeprom-pins-and-what-can-they-be-used-for\">What are the ID EEPROM pins and what can they be used for?<\/a><\/p>\n<h1>Frameworks<\/h1>\n<p><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/raspberry-gpio\">Raspberry gPIo<\/a> (learn.sparkfun.com)<br \/>\n<a href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?t=119472\">Official C\/C++ library ?<\/a><br \/>\n<a href=\"https:\/\/elinux.org\/RPi_GPIO_Code_Samples\">RPi GPIO Code Samples<\/a><\/p>\n<ul>\n<li>SYSFS<\/li>\n<li>Python<\/li>\n<li>bcm2816 Library<\/li>\n<li>WiringPi<\/li>\n<li>pigpio<\/li>\n<\/ul>\n<h3>SYSFS<\/h3>\n<p><a href=\"http:\/\/hertaville.com\/introduction-to-accessing-the-raspberry-pis-gpio-in-c.html\">Introduction to accessing the Raspberry Pi&#8217;s GPIO in C++ (sysfs) <\/a><br \/>\n<a href=\"https:\/\/github.com\/halherta\/RaspberryPi-GPIOClass-v1\">github.com\/halherta\/RaspberryPi-GPIOClass-v1<\/a><br \/>\n<a href=\"http:\/\/exploringrpi.com\/chapter6\/\">Exploring Raspberry Pi: Chapter 6: Interfacing to the Raspberry Pi Input\/Outputs<\/a><\/p>\n<h3>Python<\/h3>\n<p><a href=\"https:\/\/hoeser-medien.de\/2013\/04\/gpio-event-using-interrupt-driven-gpio-in-raspian\/\">GPIO \u2013 Event \/ Using interrupt-driven GPIO in Raspian<\/a><br \/>\n<a href=\"https:\/\/sourceforge.net\/projects\/raspberry-gpio-python\/\">raspberry-gpio-python<\/a>, A Python module to control the GPIO on a Raspberry Pi<br \/>\n<a href=\"http:\/\/gpiozero.readthedocs.io\/en\/stable\/index.html\">gpiozero<\/a>, A simple interface to GPIO devices with Raspberry Pi<\/p>\n<p><a href=\"http:\/\/raspi.tv\/2014\/rpi-gpio-update-and-detecting-both-rising-and-falling-edges\">RPi.GPIO update and detecting BOTH rising and falling edges<\/a><br \/>\n<a href=\"http:\/\/raspi.tv\/2013\/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-2\">How to use interrupts with Python on the Raspberry Pi and RPi.GPIO \u2013 part 2<\/a><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvoid *poll_thread(void *threadarg)\r\n{\r\n    struct epoll_event events;\r\n    char buf;\r\n    struct timeval tv_timenow;\r\n    unsigned long long timenow;\r\n    struct gpios *g;\r\n    int n;\r\n\r\n    thread_running = 1;\r\n    while (thread_running) {\r\n        n = epoll_wait(epfd_thread, &amp;events, 1, -1);\r\n    &#x5B;...]\r\n}\r\n\r\nint add_edge_detect(unsigned int gpio, unsigned int edge, int bouncetime)\r\n\/\/ return values:\r\n\/\/ 0 - Success\r\n\/\/ 1 - Edge detection already added\r\n\/\/ 2 - Other error\r\n{\r\n    pthread_t threads;\r\n    struct epoll_event ev;\r\n    \r\n    &#x5B;...]\r\n    \/\/ create epfd_thread if not already open\r\n    if ((epfd_thread == -1) &amp;&amp; ((epfd_thread = epoll_create(1)) == -1))\r\n        return 2;\r\n\r\n    \/\/ add to epoll fd\r\n    ev.events = EPOLLIN | EPOLLET | EPOLLPRI;\r\n    ev.data.fd = g-&gt;value_fd;\r\n    if (epoll_ctl(epfd_thread, EPOLL_CTL_ADD, g-&gt;value_fd, &amp;ev) == -1) {\r\n        remove_edge_detect(gpio);\r\n        return 2;\r\n    }\r\n    g-&gt;thread_added = 1;\r\n    &#x5B;...]\r\n}\r\n<\/pre>\n<h3>bcm2816 Library<\/h3>\n<p><a href=\"http:\/\/www.airspayce.com\/mikem\/bcm2835\/group__gpio.html\">GPIO register access<\/a><br \/>\n<a href=\"http:\/\/www.airspayce.com\/mikem\/bcm2835\/group__constants.html\">Constants for passing to and from library functions<\/a><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nbcm2835_set_debug(1)\r\nbcm2835_gpio_len()\r\n<\/pre>\n<p><a href=\"https:\/\/sensorian.github.io\/c_docs\/_l_e_d_2_example4_2_utilities_8c_source.html\">Sensorian 1.0 &#8211; C API Reference Guide Library<\/a><br \/>\n<a href=\"https:\/\/gist.github.com\/hsiboy\/9394520\">Raspberry Pi &#8211; detect button press<\/a><br \/>\n<a href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?t=184843\">[POSIX-PIGPIO] Real-time thread on GPIO interrupt?<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/16306901\/c-program-a-button-to-perform-a-task-once-when-pressed-latch\">C program a button to perform a task once when pressed (latch)<\/a><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nint main(int argc, char **argv)\r\n{\r\n    pthread_attr_t attr;\r\n    struct sched_param param;\r\n    pthread_t thread;\r\n\r\n    bcm2835_init();\r\n    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT);\r\n    bcm2835_gpio_aren(PIN);\r\n\r\n    pthread_attr_init(&amp;attr);\r\n    pthread_attr_setschedpolicy(&amp;attr, SCHED_FIFO);\r\n    pthread_attr_setinheritsched(&amp;attr, PTHREAD_EXPLICIT_SCHED);\r\n\r\n    param.sched_priority = 99;\r\n    pthread_attr_setschedparam(&amp;attr, &amp;param);\r\n    \r\n    while (1)\r\n    {\r\n        if (bcm2835_gpio_eds(PIN))\r\n        {\r\n            bcm2835_gpio_set_eds(PIN);\r\n            pthread_create(&amp;thread, &amp;attr, callback_acq, NULL);\r\n        }\r\n    }\r\n    bcm2835_close();\r\n    return 0;\r\n}\r\n<\/pre>\n<h3>WiringPi<\/h3>\n<p><a href=\"http:\/\/wiringpi.com\/the-gpio-utility\/\">The GPIO utility<\/a><br \/>\n<a href=\"https:\/\/iotbreaks.com\/understand-gpio-readall-bash-shell-command-output-on-raspberry-pi\/\">Understand \u201cgpio readall\u201d Bash shell command output on Raspberry Pi<\/a><br \/>\n<a href=\"https:\/\/raspberrypi.stackexchange.com\/questions\/66873\/how-to-read-output-of-gpio-readall\">how to read output of gpio readall<\/a><\/p>\n<h3>pigpio<\/h3>\n<p><a href=\"http:\/\/abyz.me.uk\/rpi\/pigpio\/\">The pigpio library<\/a><\/p>\n<h1>Interrupt \/ Event Detection \/ poll() \/ epoll()<\/h1>\n<p><a href=\"https:\/\/raspberrypi.stackexchange.com\/questions\/63503\/gpio-state-monitoring-via-command-line\">GPIO state monitoring via command line?<\/a><br \/>\n<a href=\"https:\/\/www.iot-programmer.com\/index.php\/books\/22-raspberry-pi-and-the-iot-in-c\/chapters-raspberry-pi-and-the-iot-in-c\/55-raspberry-pi-and-the-iot-in-c-input-and-interrupts?showall=&#038;limitstart=\">Raspberry Pi And The IoT In C &#8211; Input And Interrupts<\/a> (Page 1 of 4)<br \/>\n<a href=\"https:\/\/www.iot-programmer.com\/index.php\/books\/22-raspberry-pi-and-the-iot-in-c\/chapters-raspberry-pi-and-the-iot-in-c\/55-raspberry-pi-and-the-iot-in-c-input-and-interrupts?showall=&#038;start=1\">Raspberry Pi And The IoT In C &#8211; Input And Interrupts<\/a> (Page 2 of 4)<br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/4093185\/whats-the-difference-between-epoll-poll-threadpool\/5449827\">What&#8217;s the difference between epoll, poll, threadpool?<\/a><\/p>\n<h1>Off-Topic<\/h1>\n<p><a href=\"http:\/\/blogdugas.net\/blog\/2016\/01\/04\/how-to-use-the-gpio-on-the-beaglebone-black\/\">How to Use the GPIO on the BeagleBone Black<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Raspberry Pi GPIO &#8211; 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&#8217;s GPIO in C++ (sysfs) github.com\/halherta\/RaspberryPi-GPIOClass-v1 Exploring Raspberry Pi: Chapter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7555","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/7555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7555"}],"version-history":[{"count":14,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/7555\/revisions"}],"predecessor-version":[{"id":7785,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/7555\/revisions\/7785"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}