16 Aralık 2018, 14:39:46

Haberler:

Eposta uyarılarını yanıtlamayınız ( ! ) https://bit.ly/2J7yi0d


Raspberry with C++ program

Başlatan johntimber, 14 Temmuz 2018, 18:49:41

johntimber

Hi,

I bought the Raspberry Pi 3 because I love the Raspberry Pi very much.I have to make Project with C++ language. I installed Raspbian on my Pi. I want to control my Pi in C++ language. I tried to run C++ Program and I can run c++ example program on Raspberry Pi. For Example : - g++ -o program program.cpp I would like to write the C ++ program for interacting on the hardware. I thought it's batter to do experiment with LED. I would like to Turn on/off LED on Raspberry Pi with C++ language.
I have searched on internet.. I didn't found any simple Example. From google search I think I have to install WiringPi so I have Installed WiringPi on Raspberry Pi.
I hope someone can help me with my problem?

Please help.

I didn't find the right solution from the Internet.

References:-
https://www.raspberrypi.org/forums/viewtopic.php?t=215377
AAnimated video studio

Thanks!


OptimusPrime

You dont need to use any object oriented language to drive an led. However, you could compile and build your c code with c++ compiler.

There are some ways to toggle cpu pins such as gpio sysfs interface, memory mapping, writing device driver or using an external library.

If you would like to go ahead with gpio sysfs interface you could call system commands through your c/c++ code. Only thing you need to do is to export a pin you want to control than change the direction as output to turn your led on or off.

You can follow the directions on the below link.
https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

You can also use an additional library to perform these actions. WiringPi would be the best one you might work on.

After this point the things are getting complicated. In order to reach directly to the cpu registers to control the output pin, you have to map the memory in advance. Moreover, you should be careful since you are about to change the contents the registers in a system where an operating system runs.

Check out the below link for more information.

https://www.raspberrypi.org/forums/viewtopic.php?t=8476

You could also write your own gpio driver which is really a pain in the ass. The only benefit writing your own driver is handling the gpio interrupts in the kernel space. You could also catch gpio interrupts in user space through user space driver if your current linux distribution has the special driver.

Take a look at the link shown below
http://derekmolloy.ie/kernel-gpio-programming-buttons-and-leds/

By the way, you can't write a kernel driver in c++. Just forward your information.