User avatar
zeilotech
Posts: 12
Joined: Thu Jun 02, 2016 4:43 pm

C vs Python which has more GPIO support?

Sun Nov 25, 2018 7:30 pm

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.

LegendOfPi
Posts: 8
Joined: Mon Nov 26, 2018 1:11 pm

Re: C vs Python which has more GPIO support?

Mon Nov 26, 2018 4:18 pm

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.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: C vs Python which has more GPIO support?

Mon Nov 26, 2018 4:28 pm

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.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Heater
Posts: 13063
Joined: Tue Jul 17, 2012 3:02 pm

Re: C vs Python which has more GPIO support?

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.

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.

ElEscalador
Posts: 674
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: C vs Python which has more GPIO support?

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++;
My Autonomous Robot Project and a few of my other projects below.

https://lloydbrombach.wordpress.com/

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: C vs Python which has more GPIO support?

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.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
buja
Posts: 498
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: C vs Python which has more GPIO support?

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.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12110
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: C vs Python which has more GPIO support?

Tue Nov 27, 2018 12:19 am

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.

ElEscalador
Posts: 674
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: C vs Python which has more GPIO support?

Tue Nov 27, 2018 12:42 am

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.
My Autonomous Robot Project and a few of my other projects below.

https://lloydbrombach.wordpress.com/

Return to “C/C++”