User avatar
RogerW
Posts: 284
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

CodeBlocks and pigpio

Tue Mar 12, 2019 11:15 am

I am learning to use codeblocks to develop an application that uses the pigpio library. the using the pigpio library means the application needs to run as sudo.
I can do this by running codeblocks as sudo but then all the files it creates need sudo privileges if I want to delete them.
Is there a way to change the command that codeblocks uses to run the app?

User avatar
DougieLawson
Posts: 35557
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: CodeBlocks and pigpio

Tue Mar 12, 2019 12:03 pm

pigpio does NOT need sudo. It's the pigpiod daemon that runs privileged.
Most GPIO access doesn't need sudo.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
RogerW
Posts: 284
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: CodeBlocks and pigpio

Tue Mar 12, 2019 4:32 pm

True for the daemon but I am not using it. I link direct to the C library. I may have missed something but the first time I ran the program I was told I needed sudo.

User avatar
DougieLawson
Posts: 35557
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: CodeBlocks and pigpio

Tue Mar 12, 2019 5:37 pm

With WiringPi you can set an environment variable to allow it to run without sudo.

You have clearly caught a dose of sudoitis. That's a nasty disease where Raspberry users assume the answer to all problems is sudo.

export WIRINGPI_GPIOMEM=1 in bash.

Or do it in C programs with

Code: Select all

  setenv ("WIRINGPI_GPIOMEM", "1", 1);
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
RogerW
Posts: 284
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: CodeBlocks and pigpio

Tue Mar 12, 2019 5:46 pm

Again true but I am not using wiringpi. I am using the pigpio C interface library.

User avatar
DougieLawson
Posts: 35557
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: CodeBlocks and pigpio

Tue Mar 12, 2019 5:48 pm

What version of pigpiod?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
RogerW
Posts: 284
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: CodeBlocks and pigpio

Tue Mar 12, 2019 5:55 pm

I am not using pigpiod. I am using the C pigpio library which controls the gpios directly.

User avatar
DougieLawson
Posts: 35557
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: CodeBlocks and pigpio

Tue Mar 12, 2019 5:58 pm

What version of that are you using?
Where did it come from?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
RogerW
Posts: 284
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: CodeBlocks and pigpio

Tue Mar 12, 2019 6:05 pm

Its there as standard, compile with -lpigpio. See http://abyz.me.uk/rpi/pigpio/cif.html

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: CodeBlocks and pigpio

Wed Mar 13, 2019 10:54 am

DougieLawson wrote:
Tue Mar 12, 2019 5:37 pm
With WiringPi you can set an environment variable to allow it to run without sudo.

You have clearly caught a dose of sudoitis. That's a nasty disease where Raspberry users assume the answer to all problems is sudo.

export WIRINGPI_GPIOMEM=1 in bash.

Or do it in C programs with

Code: Select all

  setenv ("WIRINGPI_GPIOMEM", "1", 1);
This hasn't been needed for a few years now. It's the default. wiringPi checks if it can access /dev/gpiomem first. Sadly this breaks pwm and some clock codes, but hey ho.

However, the sudo'itis is indeed, a nasty disease, I'd suggest that people stop using sudo unless it's really needed, then again, I've basically given up - it's their computer after all and if someone wants to tell them to sudo a wget/curl script into bash then who am I to stop them.

-Gordon
Last edited by [email protected] on Wed Mar 13, 2019 11:36 am, edited 1 time in total.
--
Gordons projects: https://projects.drogon.net/

User avatar
joan
Posts: 14089
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: CodeBlocks and pigpio

Wed Mar 13, 2019 11:30 am

If you link in the pigpio library (-lpigpio)you need to run the resulting program with root privileges. The library uses various hardware peripherals (e.g. DMA, PWM, PCM, SPI) in a way which is not permitted to a standard userland process.

This is not necessary for programs which use the pigpio daemon (e.g. the Python module, pigs, programs linked with -lpigpiod_if, -lpigpiod_if2).

User avatar
RogerW
Posts: 284
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: CodeBlocks and pigpio

Wed Mar 13, 2019 11:42 am

joan - thanks for the clarification.

I could compile with codeblocks and then run the app from a console but that would be clumsy and I could not use the debugger built into codeblocks.

For the moment I have modified the desktop entry for file manager to run that sudo as well as codeblocks which does mean I can access files if needs be but I don't like using sudo without a good reason.

So my question remains - can I change the command that codeblocks uses to run my program.

Return to “C/C++”