A little bit late, but as can be found here: http://wiringpi.com/download-and-install/ simply type
sudo apt-get install wiringpi
This installs the gpio command.
A little bit late, but as can be found here: http://wiringpi.com/download-and-install/ simply type
sudo apt-get install wiringpi
This installs the gpio command.
sudo pip install won't work, because it is NOT a Python program.
The following answer explains how to install it and also how to get the missing man pages. https://raspberrypi.stackexchange.com/a/51378/8697
bash: gpio: command not found - Raspberry Pi Forums
[SOLVED] RPI.GPIO won't work after fresh install
bash - GPIO command for raspberry not working via crontab - Stack Overflow
linux kernel - Not able to access GPIO pins on my Raspberry Pi 5 - Stack Overflow
I'm going to preface this in that I never use the pi's GPIO except for this one small instance. Pis are overpriced here so I always use an external microcontroller instead which works just fine for 99 percent of things. For some reason in this instance where I thought I would use a pin of the pi it just didn't seem to work. Thinking maybe it was maybe an an issue with the device I was using I swapped it out for a simple LED and resistor and then later tried a python script that worked fine.
Can someone help where i'm being stupid?
So far I can eliminate the following:
- Hardware issues
currently it's just a yellow led and a 100ohm resistor. The polarity is fine
-pin numbering
I am using BCIM pinout for pin 23 or in case i'm wrong about that it's 8 pins from the top left with the hdmi ports facing towards you and then the ground right beside.
so the following bash commands should have worked am i right? I shouldn't even need to be root but that wouldn't hurt I wouldn't think
pi@raspberrypi:~ $ sudo gpio -g mode 23 out
pi@raspberrypi:~ $ sudo gpio -g write 23 1
but no... no life. So I tried every possible combination of bash comand I could think of to get this pin working.
pi@raspberrypi:~ $ sudo gpio -g mode 4 out
pi@raspberrypi:~ $ sudo gpio -g write 4 1
pi@raspberrypi:~ $ sudo gpio mode 4 out
pi@raspberrypi:~ $ sudo gpio write 4 1
pi@raspberrypi:~ $ sudo gpio -g mode 23 out
pi@raspberrypi:~ $ sudo gpio -g write 23 1
pi@raspberrypi:~ $ sudo gpio mode 23 out
pi@raspberrypi:~ $ sudo gpio write 23 1
pi@raspberrypi:~ $ sudo gpio -g mode 16 out
pi@raspberrypi:~ $ sudo gpio -g write 16 1
pi@raspberrypi:~ $ sudo gpio mode 16 out
pi@raspberrypi:~ $ sudo gpio write 16 1
still nothing....
so I did a python script as below and voila... working.
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
GPIO.output(23, 1)
But why didn't the bash work? What incredibly stupid obvious thing did I miss?
Note that when you execute something from crontab, it will not necessarily have the same environment variables set.
Most important env. variable for you is PATH. I think that under cron your PATH does not contain directory in which your gpio command is located.
You can add line like this as first line of your crontab:
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
and this should fix your issue, if gpio is located in one of directories listed above.
Typical way to debug crontab issues is to make sure that env. variables are what you expect them to be. Add line like this into first line of the script to debug:
set > /path/to/log/file # be sure that this file is writable
Run it once manually, copy logfile aside. Then, run it again from cron, compare output - you will see what makes them different.
Yes, I have had the same problem (using gpio commands in crontab). A quick fix that worked for me was to prepend an 'sudo' to the gpio commands like: sudo gpio write 0 1
When I went though my bash script and prepenneded the 'sudo's to all of my gpio commands everything works fine.
The previous answer suggested by mvp is the 'better' way to fix these types of problems with crontab. Hope this helps
if your kernel version is higher than 6.6, you can't request GPIO pin with traditional pin number. The base gpio number is no longer pinned as doing so is deprecated in the kernel.
check the correct number of the required GPIO pin in /sys/kernel/debug/gpio
Assuming you have kernel version higher 6.6 and higher, gpio pins are numbered differently. Instead of value 4 for GPIO PIN 4 use 516, for GPIO PIN 17 use 529. All gpio pin numbers can be found in /sys/kernel/debug/gpio