Page 1 of 1

C vs Python which has more GPIO support?

Posted: Sun Nov 25, 2018 7:30 pm
by zeilotech
Please I'm an absolute beginner in Raspberry Pi, though I'm 'well grounded' in C for embedded system. My question now is which of C and Python has more support in terms of libraries, for Raspberry Pi? Secondly, after writing a python code, how can I make it to be executing repeatedly anytime the Pi is booted?
Thanks in advance, everyone, for tolerating my questions and responding.

Re: C vs Python which has more GPIO support?

Posted: Mon Nov 26, 2018 4:18 pm
by LegendOfPi
As for C vs Python I would ask in the General programming discussion topic, but have you tried running the following?

python /home/pi/example.py &

Simply put it in /etc/rc.local and your python file should run on boot.

Re: C vs Python which has more GPIO support?

Posted: Mon Nov 26, 2018 4:28 pm
by DavidS
Both are about equal. There are as many good options either way, it will depend on what you want to do and what language you are most comfortable with.

Python will not quite match the speed of C, so if you are attempting to bang out at a rate of 10MHz then you are going to want C (and quite a few tricks to keep the OS out of the way [without talking about bare metal]).

Personally I use either Basic, C, or ARM Assembly when I play with the GPIO, depending on what best fits the particular project.

Re: C vs Python which has more GPIO support?

Posted: Mon Nov 26, 2018 5:24 pm
by Heater
What happened here?

This question got moved from the end of a thread dating back to 2012 to this new thread. But the responses there did not move with it.

When DavidS says "does not quite match" he means Python will be hundreds of times slower. You can toggle a GPIO pin at 50MHz in C. I refuse to believe Python could get anywhere near that.

However, so what? Perhaps your application does not need that kind of performance and ease of creating a solution is more important.

Re: C vs Python which has more GPIO support?

Posted: Mon Nov 26, 2018 6:15 pm
by ElEscalador
If speed is not critical during program execution python will be much faster to learn and get your project working and there's tooons of tutorials around python but not quite as many for c/c++;

Re: C vs Python which has more GPIO support?

Posted: Mon Nov 26, 2018 9:04 pm
by DavidS
ElEscalador wrote:
Mon Nov 26, 2018 6:15 pm
If speed is not critical during program execution python will be much faster to learn and get your project working and there's tooons of tutorials around python but not quite as many for c/c++;
I hope you do not mind this qualifier:

There are tones of tuts for RPi GPIO in Python, not as many for RPi GPIO in C. As there are tones of tutorials on C itself, likely to be way more than python just do to the time the languages have been popular relatively speeking.

Re: C vs Python which has more GPIO support?

Posted: Mon Nov 26, 2018 10:43 pm
by buja
Heater wrote:
Mon Nov 26, 2018 5:24 pm
What happened here?

This question got moved from the end of a thread dating back to 2012 to this new thread. But the responses there did not move with it.
...
So my incredibly valuable contribution is lost? :o
For the record, it should be the second post, as a reply to zeilotech's question.
So all posts before zeilotech are gone, and my reply after that, and I think another one.

Edit: I reported this to the mods because I find it strange that posts disappear.

Re: C vs Python which has more GPIO support?

Posted: Tue Nov 27, 2018 12:19 am
by mahjongg
buja wrote:
Mon Nov 26, 2018 10:43 pm
Heater wrote:
Mon Nov 26, 2018 5:24 pm
What happened here?

This question got moved from the end of a thread dating back to 2012 to this new thread. But the responses there did not move with it.
...
So my incredibly valuable contribution is lost? :o
For the record, it should be the second post, as a reply to zeilotech's question.
So all posts before zeilotech are gone, and my reply after that, and I think another one.

Edit: I reported this to the mods because I find it strange that posts disappear.
your "invaluable post" was not lost, its still on this forum, but in the 2012 thread.....
buja wrote:
Sun Nov 25, 2018 10:20 pm
Python has more support than C. Almost every piece of hardware for the Pi comes with a Python library to support it. Supplier support for C is sometimes available, supplier support for other languages seems to be non-existent.

If you like to write your own C driver software there are the GPIO libraries (wiringPi, PIGPIO and BCM2835). Especially wiringPi supports some often used devices "out of the box", wiringPi and PIGPIO are installed by default in Raspbian.
With a bit of luck you can find drivers written by users in C or C++ on Github or similar places.
What happened is that I split off posts starting at the wrong point in the thread and several older parts (but from 2018) stuck with the original thread from 2012, which is here:
viewtopic.php?f=33&t=22640
it happens when a user replies to an ancient thread that should have been locked long ago.
please don't necro old threads, but start a new one, so that moderators do not have to jump through hoops.

Re: C vs Python which has more GPIO support?

Posted: Tue Nov 27, 2018 12:42 am
by ElEscalador
DavidS wrote:
Mon Nov 26, 2018 9:04 pm
ElEscalador wrote:
Mon Nov 26, 2018 6:15 pm
If speed is not critical during program execution python will be much faster to learn and get your project working and there's tooons of tutorials around python but not quite as many for c/c++;
I hope you do not mind this qualifier:

There are tones of tuts for RPi GPIO in Python, not as many for RPi GPIO in C. As there are tones of tutorials on C itself, likely to be way more than python just do to the time the languages have been popular relatively speeking.
Totally fair and accurate. Any time I want to use a new sensor or some gpio function the tutorial is in python (or Arduino Sketch, which is kinda sorta c) and I've had to learn enough python to make c/c++ out of it. wiringpi and pigpio are great, but the overall simplicity of python I think still makes it quicker to get to the end goal even with all the available c/c++ info available.