This is how I did it:
- Clone MRAA to your system
git clone https://github.com/eclipse/mraa
- Install dependencies (removed nodejs-dev because it was giving error)
sudo apt-get install git build-essential swig3.0 python-dev cmake libjson-c-dev
- Modify gpio_advanced.c example to use your pin and your command
sudo nano gpio_advanced.c
Modify #define GPIO_PIN 6
to pin that you want (not all pins work, pins 13, 22, 23, 24 seem to work).
Now lets modify interrupt code to use your command:
fprintf(stdout, "ISR triggered\n");
// Add your command here, I used: system("shutdown now");
In the bottom of the file, there is following line:
/* wait 30 seconds isr trigger */
Modify it to be
- Build mraa by following commands:
- Enable the pin that you used in the gpio_advanced.c example by doing following:
echo 23 > export
after this command, when you type ls, pin23 should be visible.
- Run the program
If it gives you error, try other pin.
If it works, let me know. I can also show how to automate it inside shell script/service.