I have a raspberry pi zero and I am trying to change the gpio pin values. I tried using RPi.GPIO with python and the gpio command from wiringpi but I am unable to change the value for any of the pins. I am using LEDs to check if a pin is high or low and no matter I do, the pins do not become high. I also used gpio readall
to see the changes. I am able to change the mode of the pin (input or output) but not the value itself.
Interestingly an LED connected to pin 26 (BCM numbering) is always on. I tried changing the values but the LED stays on and gpio readall
shows its value as 0.
I tried reinstalling the OS but after that twice, the problem still persists. I have raspbian jessie lite.
I have been trying to fix this issue for the last two days, any help would be greatly appreciated.
EDIT: Here is the code I used. No errors were reported when running any of the commands or programs
Python
import RPi.GPIO as gp
gp.setmode(gp.BCM)
gp.setup(18,gp.OUT)
print "before on"
gp.output(18,gp.HIGH)
print "after on"
wiringpi
Output of gpio readall
before changing state
+-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 0 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | IN | 0 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 0 | 7 || 8 | 0 | ALT0 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 0 | ALT0 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | OUT | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | OUT | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 0 | IN | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 0 | IN | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 0 | 27 || 28 | 0 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 0 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 0 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+
I ran the following commands
gpio -g mode 26 out
gpio -g write 26 1
This is the output of gpio readall
after attempting to change the value
+-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 0 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | IN | 0 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 0 | 7 || 8 | 0 | ALT0 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 0 | ALT0 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | OUT | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | OUT | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 0 | IN | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 0 | IN | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 0 | 27 || 28 | 0 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 0 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 0 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | OUT | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+
gpio -g read 26
returns a value of 0. gpio -g mode 18 out
and gpio -g write 18 1
also had no effect
EDIT 2 in case anyone was wondering, the LEDs work fine. I verified that by connecting the LEDs to a different battery powered circuit.
I also changed the circuit a bit and the LED connected to pin 26 no longer lights up. the particular LED was not changed but I made my circuit similar to that of one of my earlier project here. The required LEDs still do not light up. This was the output of my testing. The circuit is connected properly.
pi@raspberrypi:~/repo/lightswitch $ ./lightswitch
LED is off
Turning on LED
pi@raspberrypi:~/repo/lightswitch $ ./lightswitch
LED is off
Turning on LED
EDIT 3 So it seems that pin 6 has the same always on state that pin 26 used to have. Interestingly, gpio readall
shows it as input and as having a value of 0.