1

I'm using a class that I found on github to control the GPIO pins. That class can be found here: https://github.com/halherta/RaspberryPi-GPIOClass-v2

From what I understand this class works by writing the direction and values to a file in sys/class/gpio somewhere. I wrote some code off of the demo used in the github repository and it compiled fine, but when I tried to run it I got a Permission Denied error. After this, I changed the permissions with

sudo chmod 777

and tried running the same code but now I get this:

could not write to SYSFS GPIO export device: Device or resource busy

The code I'm using is:

int main (void)
{
string state;
GPIOClass* gpio17 = new GPIOClass("19");
GPIOClass* gpio27 = new GPIOClass("26");

gpio17->setdir_gpio("out");
gpio27->setdir_gpio("out");

gpio17->setval_gpio("0");
gpio27->setval_gpio("0");

for(;;)
    {
    usleep(1000000);
    gpio17->getval_gpio(state);
    if(state == "0"){gpio17->setval_gpio("1");}
    else { gpio17->setval_gpio("0");}

    gpio27->getval_gpio(state);
    if(state == "0") { gpio27->setval_gpio("1");}
    else {gpio27->setval_gpio("0");}
    }
}

How can I stop Raspbian from using up the GPIO so I can use it?

  • It's impossible to help as we don't know the sequence of events. I suspect you are now seeing misleading errors because of what you have done earlier. Can you start from a reboot and document each step? The initial error was because you need root privileges to manipulate the gpios. Anything afterwards is clouded by this initial error. – joan Oct 4 '14 at 8:08
1

You do not state what you have tried, so it is difficult to give an definitive answer.

Have you tried basic tests? I recommend the wiringpi library which includes lots of test programs and the very useful gpio utility which can display state of pins.

It is unclear what pins you are trying to use. Not all are brought to the header. To make matters more difficult there are several different conventions for pi numbering, the most common being BMC GPIO and WiringPi, but Physical numbering is also used.

What pin are you expecting from GPIOClass* gpio27 = new GPIOClass("26");? GPIO 26 is not on the header.

I can't help commenting on the c++ class. Why? Why not just use simple 'c' functions. c++ can be useful, but unless you using class state it just seems an added complication.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.