miaomiao
Posts: 22
Joined: Fri Jun 30, 2017 4:07 am

use bcm2835 permission denied on Raspberry pi2

Fri Jun 30, 2017 4:26 am

Hi, I am using Raspberry pi 2 and geany in C language to blink a LED. The compilation is successful but LED cannot blink and show permission denied on RP. I used bcm2835 1.39,connect LED to gpio pin12.
The following is my c program on geany and how I download bcm2835. Can anyone tell me how to solve the problem?Thank you very much.

Code: Select all


#include<bcm2835.h>

#define LED RPI_GPIO_P1_12

int main(int argc,char **argv){

if(!bcm2835_init())return 1;

bcm2835_gpio_fsel(LED,BCM2835_GPIO_FSEL_OUTP);
unsigned int delay=1000;

while(1)
{
bcm2835_gpio_set(LED);
bcm2835_delay(delay);
bcm2835_gpio_clr(LED);
bcm2835_delay(delay);
}
bcm2835_close();
return 0;
}

Code: Select all

pi@raspberrypi:~ $ wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.39.tar.gz

pi@raspberrypi:~ $ tar zxvf bcm2835-1.39.tar.gz

pi@raspberrypi:~ $ cd bcm2835-1.39
pi@raspberrypi:~/bcm2835-1.39 $ ./configure

pi@raspberrypi:~/bcm2835-1.39 $ make

pi@raspberrypi:~/bcm2835-1.39 $ sudo make check

pi@raspberrypi:~/bcm2835-1.39 $ sudo make install

 pi@raspberrypi:~/bcm2835-1.39 $ gcc -o blink -lbcm2835
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/crt1.o: In function `_start':
/build/glibc-H706YU/glibc-2.19/csu/../ports/sysdeps/arm/start.S:119: undefined reference to `main'
collect2: error: ld returned 1 exit status



User avatar
PeterO
Posts: 5878
Joined: Sun Jul 22, 2012 4:14 pm

Re: use bcm2835 permission denied on Raspberry pi2

Mon Jul 10, 2017 3:23 pm

I would use wiringPi which should be installed already.
http://wiringpi.com/

But your "blink" compile command is missing the name of the c source file

gcc -o blink blink.c -lbcm2835


PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “Troubleshooting”