2

TL;DR EDIT: to clarify this question and why it's relevant to the PI:

what is the most efficient way in term of absolute time and energy (which I guess is more related to clock cycle) to now the value of a GPIO pin (let say for a one wire sensor but same with simple GPIO etc...)?

cat /sys/bus/w1/devices/28-00000123456/w1_slave

Or

f = open('/sys/bus/w1/devices/28-00000123456/w1_slave', 'r')
lines = f.readlines()                                   # read the device details
print(lines)

Original question below:

It's been some time that I am playing around with some raspberries and I usually do whatever I want with simple bash scripts, mainly because I am used and feel comfortable with ssh/awk/sed/grep... But I may be wrong doing so.

Thus, I was wondering if there are any reasons to use python , other than that it as "A large community supports and uses the Python language as it is easy to learn and code".

For example, to read a sensor or activate a GPIO I use to cat and echo the files in /sys/devices/ or /sys/class/gpio/. But maybe the python libraries are better optimised to do so?

That maybe a naive question but I am curious and willing to change my habits if they are bad (and more if it can save a few CPU calls and energy).

closed as off-topic by joan, Ingo, Steve Robillard, Milliways, Patrick Cook Dec 21 '18 at 21:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – joan, Ingo, Steve Robillard, Milliways, Patrick Cook
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Why just these two? If you're worried about efficiency, why not open it up? Just curious because I would have said "neither". – Brick Dec 21 '18 at 20:01
  • Yes you right. Thing is that I didn't want to have to compile C each time test some sensors and went to send and receive the output of to a server etc... Bash and python sounded like the easiest way to get thing done quickly. Thus was wondering if one is better than the other. You may be right and they may be both as bad! – Simon C. Dec 21 '18 at 20:09
  • 4
    The Pi is irrelevant to the question. – joan Dec 21 '18 at 20:09
  • I think the Pi is relevant to this question insofar as the access to the GPIO pins is (or at least could be thought to be) specific to the Pi, not the scripting. @joan – Brick Dec 21 '18 at 21:02
  • 1
    The question of which if either is more efficient for gpio is relevent to the pi in my opinion. But you'd have to define a metric to decide efficiency anyway. More efficient in programmer time or clock cycles would be different questions. And since the pi doesn't have especially fast gpio compared to other options, maybe the programmer time is more relevant. And for you if you're comfortable with the shell, that's probably better for you. – T. M. Dec 22 '18 at 0:56

Browse other questions tagged or ask your own question.