Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

433
Views
GPIO Pins RaspberryPi Using C++

I'm writing a program to control the GPIO pins on my raspberryPi with C++ and having difficulty I'm able to export with the following code:

char pathString[256];
sprintf(pathString, "%s/export", "/sys/class/gpio");
ofstream exporterFile(pathString);
exporterFile << pinNumber;
exporterFile.close()

This works an successfully exports the pin but this does not set the direction:

sprintf(pathString, "%sgpio%d/direction", "/sys/class/gpio", pinNumber);
ofstream directionFile(pathString);
directionFile << pinDirection;
directionFile.close();

For some reason I cannot write to the file, perhaps I do not have the right privileges. My question is, is that the problem and if so how do I solve it so I can write to the file.

Thanks in advance

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to be root or run your program with sudo in order to use the GPIO pins. However, I'd recommend using the wiringpi library http://wiringpi.com/ to access GPIO from c/c++. It is easy to use and raises the abstraction level a bit. It also lets you do things like PWM. A program using wiringpi also needs to be run with sudo.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!