Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4909

C/C++ • bcm2835 not working from C++

$
0
0
I can turn on a pin using Joachim Schurig's library, but I cannot get this code to work from the bcm2835 examples (slightly edited).

Code:

# if 0        g++ -o aonbcm -L/opt/lib -I/opt/include aonbcm.cxx -lbcm2835# endif#include <bcm2835.h># include <unistd.h>#include <stdio.h>#define PIN RPI_GPIO_P1_12int main(void){if (!bcm2835_init())        return -2;printf("do the fsel\n");// Set the pin to be an outputbcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);// Turn it onprintf("do the write high\n");bcm2835_gpio_write(PIN, HIGH);//      sleep while doing devel.//      don't want to close immed or you might not see it come on.sleep(8);// Turn it offprintf("do the write low\n");bcm2835_gpio_write(PIN, LOW);bcm2835_close();return 0;}
This all started because my Pi 5 would not run my Schurig-derived code. It seemed that I needed to go to a more actively supported library, so I picked bcm2835. The above is the blink.c example, somewhat edited. It compiles, no errors. It runs, no errors. But it does not turn on the pin.

So, (1) is the above code bad? It doesn't work on Pi 4 or 5. (2) I think it can not be anything like protection modes, since the Schurig code works and this code runs without error -- it just doesn't accomplish anything.

Yes, I put libbcm2825 in /opt; but, like I say, it compiles, links, runs. So everything is defined.
Pi 5, bookworm.
Pi 4, buster.
Both are up to date, patch-wise.

Statistics: Posted by bigcrater — Wed Mar 06, 2024 4:37 am



Viewing all articles
Browse latest Browse all 4909

Trending Articles