ElCorbat
Posts: 4
Joined: Wed Nov 29, 2023 9:07 am

GPIO Pin 4 always HIGH

Wed Nov 29, 2023 9:23 am

Hello,

My problem is that GPIO Pin 4 is always physically HIGH. Here is what I did trying to fix the problem:

First to determine the physical state of the Pin, everytime I mesured the voltage on the Pin.
- Set the Pin LOW with python code (Still high)
- Set the Pin LOW with the command line "gpio -g write 4 0" (Still high)
- Set the Pin as an INPUT, then OUTPUT (This works)
- Read the pin state with the command line "gpio readall" (Sometimes It says it's LOW sometimes HIGH, but is physically HIGH)

For more details, I use a waveshare motor stepper hat plugged on the RPi https://www.waveshare.com/wiki/Stepper_Motor_HAT to run 2 stepper motor.
My project was running just fine with my code
I unplugged the HAT to verifie the voltage sent to the motor (Current OFF)
Verifie and set the voltage right.
Replugged the HAT (Current OFF)
Run the code that was ok before and did'nt touch it.
The problem appeared

User avatar
neilgl
Posts: 7488
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: GPIO Pin 4 always HIGH

Wed Nov 29, 2023 12:23 pm

We note that "gpio readall" is provided by the old WiringPi library. So something has been installed....
You might have some code that is setting it high ? (or setting GPIO state on boot)
Are we sure we are reading GPIO4 not physical pin 4 ?
On a standard Bullseye install (on a pi3) with nothing on any GPIO this python code sets it low:

Code: Select all

import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
print ("GPIO4 level is:",GPIO.input(4))

User avatar
DougieLawson
Posts: 42848
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: GPIO Pin 4 always HIGH

Wed Nov 29, 2023 12:58 pm

ElCorbat wrote:
Wed Nov 29, 2023 9:23 am
- Read the pin state with the command line "gpio readall" (Sometimes It says it's LOW sometimes HIGH, but is physically HIGH)
Since WiringPi is deprecated since 2019, try using pinctrl (in raspi-utils in Bookworm, doesn't look like it's in Bullseye).

Code: Select all

pi@challenger:~ $ pinctrl
 0: ip    -- | hi // ID_SDA/GPIO0 = input
 1: ip    -- | hi // ID_SCL/GPIO1 = input
 2: a0    -- | hi // SDA1/GPIO2 = SDA1
 3: a0    -- | hi // SCL1/GPIO3 = SCL1
 4: ip    -- | hi // GPIO_GCLK/GPIO4 = input
 5: ip    -- | hi // GPIO5 = input
 6: ip    -- | hi // GPIO6 = input
 7: op -- -- | hi // SPI_CE1_N/GPIO7 = output
 8: op -- -- | hi // SPI_CE0_N/GPIO8 = output
 9: a0    -- | lo // SPI_MISO/GPIO9 = SPI0_MISO
10: a0    -- | lo // SPI_MOSI/GPIO10 = SPI0_MOSI
11: a0    -- | lo // SPI_SCLK/GPIO11 = SPI0_SCLK
12: ip    -- | lo // GPIO12 = input
13: ip    -- | lo // GPIO13 = input
14: ip    -- | lo // TXD1/GPIO14 = input
15: ip    -- | hi // RXD1/GPIO15 = input
16: ip    -- | lo // GPIO16 = input
17: ip    -- | lo // GPIO17 = input
18: ip    -- | lo // GPIO18 = input
19: ip    -- | lo // GPIO19 = input
20: ip    -- | lo // GPIO20 = input
21: ip    -- | lo // GPIO21 = input
22: ip    -- | lo // GPIO22 = input
23: ip    -- | lo // GPIO23 = input
24: ip    -- | lo // GPIO24 = input
25: ip    -- | lo // GPIO25 = input
26: ip    -- | lo // GPIO26 = input
27: ip    -- | lo // GPIO27 = input
28: ip    -- | lo // NC/GPIO28 = input
29: op -- -- | hi // LAN_RUN_BOOT/GPIO29 = output
30: ip    -- | lo // CTS0/GPIO30 = input
31: ip    -- | lo // RTS0/GPIO31 = input
32: a3    -- | hi // TXD0/GPIO32 = TXD0
33: a3    -- | hi // RXD0/GPIO33 = RXD0
34: a3    -- | lo // SD1_CLK/GPIO34 = SD1_CLK
35: a3    -- | hi // SD1_CMD/GPIO35 = SD1_CMD
36: a3    -- | hi // SD1_DATA0/GPIO36 = SD1_DAT0
37: a3    -- | hi // SD1_DATA1/GPIO37 = SD1_DAT1
38: a3    -- | hi // SD1_DATA2/GPIO38 = SD1_DAT2
39: a3    -- | hi // SD1_DATA3/GPIO39 = SD1_DAT3
40: a0    -- | lo // PWM0_OUT/GPIO40 = PWM0
41: a0    -- | lo // PWM1_OUT/GPIO41 = PWM1
42: a0    -- | lo // ETH_CLK/GPIO42 = GPCLK1
43: a0    -- | lo // WIFI_CLK/GPIO43 = GPCLK2
44: ip    -- | hi // SDA0/GPIO44 = input
45: ip    -- | hi // SCL0/GPIO45 = input
46: ip    -- | hi // SMPS_SCL/GPIO46 = input
47: op -- -- | hi // SMPS_SDA/GPIO47 = output
48: a0    -- | lo // SD_CLK_R/GPIO48 = SD0_CLK
49: a0    -- | hi // SD_CMD_R/GPIO49 = SD0_CMD
50: a0    -- | hi // SD_DATA0_R/GPIO50 = SD0_DAT0
51: a0    -- | hi // SD_DATA1_R/GPIO51 = SD0_DAT1
52: a0    -- | hi // SD_DATA2_R/GPIO52 = SD0_DAT2
53: a0    -- | hi // SD_DATA3_R/GPIO53 = SD0_DAT3
Beware of using GPIO04 as it's defined as the 1-wire pin by default.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

ElCorbat
Posts: 4
Joined: Wed Nov 29, 2023 9:07 am

Re: GPIO Pin 4 always HIGH

Wed Nov 29, 2023 1:55 pm

neilgl wrote:
Wed Nov 29, 2023 12:23 pm
We note that "gpio readall" is provided by the old WiringPi library. So something has been installed....
You might have some code that is setting it high ? (or setting GPIO state on boot)
Are we sure we are reading GPIO4 not physical pin 4 ?
On a standard Bullseye install (on a pi3) with nothing on any GPIO this python code sets it low:

Code: Select all

import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
print ("GPIO4 level is:",GPIO.input(4))
Thank you for your answer,
Yes, wiring pi is installed
Even if some code i'm not aware of is setting my Pin High, would'nt it turn LOW when I ask it to ?
We are talking about GPIO 4, Pin 7, with gpioread all, all my pins are set on LOW, only the GPIO 4 is sometimes HIGH, sometimes LOW.
for the code, I want the Pin to be in OUTPUT, so pull_up_down can't work, I use GPIO.output(4, LOW).
I used a voltmeter on the Pin, it's always at 3.3v even if gpio readall says it's LOW
DougieLawson wrote:
Wed Nov 29, 2023 12:58 pm
ElCorbat wrote:
Wed Nov 29, 2023 9:23 am
- Read the pin state with the command line "gpio readall" (Sometimes It says it's LOW sometimes HIGH, but is physically HIGH)
Since WiringPi is deprecated since 2019, try using pinctrl (in raspi-utils in Bookworm, doesn't look like it's in Bullseye).

Code: Select all

pi@challenger:~ $ pinctrl
 0: ip    -- | hi // ID_SDA/GPIO0 = input
 1: ip    -- | hi // ID_SCL/GPIO1 = input
 2: a0    -- | hi // SDA1/GPIO2 = SDA1
 3: a0    -- | hi // SCL1/GPIO3 = SCL1
 4: ip    -- | hi // GPIO_GCLK/GPIO4 = input
 5: ip    -- | hi // GPIO5 = input
 6: ip    -- | hi // GPIO6 = input
 7: op -- -- | hi // SPI_CE1_N/GPIO7 = output
 8: op -- -- | hi // SPI_CE0_N/GPIO8 = output
 9: a0    -- | lo // SPI_MISO/GPIO9 = SPI0_MISO
10: a0    -- | lo // SPI_MOSI/GPIO10 = SPI0_MOSI
11: a0    -- | lo // SPI_SCLK/GPIO11 = SPI0_SCLK
12: ip    -- | lo // GPIO12 = input
13: ip    -- | lo // GPIO13 = input
14: ip    -- | lo // TXD1/GPIO14 = input
15: ip    -- | hi // RXD1/GPIO15 = input
16: ip    -- | lo // GPIO16 = input
17: ip    -- | lo // GPIO17 = input
18: ip    -- | lo // GPIO18 = input
19: ip    -- | lo // GPIO19 = input
20: ip    -- | lo // GPIO20 = input
21: ip    -- | lo // GPIO21 = input
22: ip    -- | lo // GPIO22 = input
23: ip    -- | lo // GPIO23 = input
24: ip    -- | lo // GPIO24 = input
25: ip    -- | lo // GPIO25 = input
26: ip    -- | lo // GPIO26 = input
27: ip    -- | lo // GPIO27 = input
28: ip    -- | lo // NC/GPIO28 = input
29: op -- -- | hi // LAN_RUN_BOOT/GPIO29 = output
30: ip    -- | lo // CTS0/GPIO30 = input
31: ip    -- | lo // RTS0/GPIO31 = input
32: a3    -- | hi // TXD0/GPIO32 = TXD0
33: a3    -- | hi // RXD0/GPIO33 = RXD0
34: a3    -- | lo // SD1_CLK/GPIO34 = SD1_CLK
35: a3    -- | hi // SD1_CMD/GPIO35 = SD1_CMD
36: a3    -- | hi // SD1_DATA0/GPIO36 = SD1_DAT0
37: a3    -- | hi // SD1_DATA1/GPIO37 = SD1_DAT1
38: a3    -- | hi // SD1_DATA2/GPIO38 = SD1_DAT2
39: a3    -- | hi // SD1_DATA3/GPIO39 = SD1_DAT3
40: a0    -- | lo // PWM0_OUT/GPIO40 = PWM0
41: a0    -- | lo // PWM1_OUT/GPIO41 = PWM1
42: a0    -- | lo // ETH_CLK/GPIO42 = GPCLK1
43: a0    -- | lo // WIFI_CLK/GPIO43 = GPCLK2
44: ip    -- | hi // SDA0/GPIO44 = input
45: ip    -- | hi // SCL0/GPIO45 = input
46: ip    -- | hi // SMPS_SCL/GPIO46 = input
47: op -- -- | hi // SMPS_SDA/GPIO47 = output
48: a0    -- | lo // SD_CLK_R/GPIO48 = SD0_CLK
49: a0    -- | hi // SD_CMD_R/GPIO49 = SD0_CMD
50: a0    -- | hi // SD_DATA0_R/GPIO50 = SD0_DAT0
51: a0    -- | hi // SD_DATA1_R/GPIO51 = SD0_DAT1
52: a0    -- | hi // SD_DATA2_R/GPIO52 = SD0_DAT2
53: a0    -- | hi // SD_DATA3_R/GPIO53 = SD0_DAT3
Beware of using GPIO04 as it's defined as the 1-wire pin by default.
I can't decide wich Pin I use, I follow the datasheet of the waveshare stepper motor HAT, Pin for is for Motor 2.
Can it be a hardware problem ? Some component burnt and can't control the pin correctly ? If so, I think I will cut the Pin and wire my HAT with cable.

User avatar
DougieLawson
Posts: 42848
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: GPIO Pin 4 always HIGH

Wed Nov 29, 2023 11:46 pm

ElCorbat wrote:
Wed Nov 29, 2023 1:55 pm
I can't decide wich Pin I use, I follow the datasheet of the waveshare stepper motor HAT, Pin for is for Motor 2.
Can it be a hardware problem ? Some component burnt and can't control the pin correctly ? If so, I think I will cut the Pin and wire my HAT with cable.
Pick a pin from https://pinout.xyz/ that will tell you what each pin does and what function can be assigned to each pin.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

ElCorbat
Posts: 4
Joined: Wed Nov 29, 2023 9:07 am

Re: GPIO Pin 4 always HIGH

Fri Dec 01, 2023 9:02 pm

Hello,

I have an update, I use a Waveshare stepper motor hat, when the hat is not on the raspberry, the GPIO 4 is normally LOW, with 0.6V I can switch it as an output, but can't set it high, with the hat on, it's normally HIGH, with 3.3V but can't set it LOW, I tested the other pins with the python code:

Import RPi.GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(X, GPIO.OUT)
GPIO.output(X, GPIO.HIGH)

Where X is the pin I wanted to test (Only 4 don't respond to the code)
(I'm talking about GPIO4/Physical 7)

User avatar
DougieLawson
Posts: 42848
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: GPIO Pin 4 always HIGH

Fri Dec 01, 2023 10:00 pm

GPIO04 is the default pin for 1-wire. Have you ensured that 1-wire is disabled?
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

ElCorbat
Posts: 4
Joined: Wed Nov 29, 2023 9:07 am

Re: GPIO Pin 4 always HIGH

Sat Dec 02, 2023 2:26 am

DougieLawson wrote:
Fri Dec 01, 2023 10:00 pm
GPIO04 is the default pin for 1-wire. Have you ensured that 1-wire is disabled?
Yes, from the setting of the raspberry pi, I even deleted the line on the config.txt that was commented

User avatar
DougieLawson
Posts: 42848
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: GPIO Pin 4 always HIGH

Sat Dec 02, 2023 9:11 pm

ElCorbat wrote:
Sat Dec 02, 2023 2:26 am
DougieLawson wrote:
Fri Dec 01, 2023 10:00 pm
GPIO04 is the default pin for 1-wire. Have you ensured that 1-wire is disabled?
Yes, from the setting of the raspberry pi, I even deleted the line on the config.txt that was commented
Then you've probably damaged GPIO04 by feeding 5V into it.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

aBUGSworstnightmare
Posts: 9268
Joined: Tue Jun 30, 2015 1:35 pm

Re: GPIO Pin 4 always HIGH

Sun Dec 03, 2023 7:38 am

DougieLawson wrote:
Fri Dec 01, 2023 10:00 pm
GPIO04 is the default pin for 1-wire. Have you ensured that 1-wire is disabled?
the pin is just an input by default, not configured for 1wire until selected by the user,

Uses i.e. 'gpioinfo' to see that it's just the label causing confusion

Code: Select all

..
line   4:  "GPIO_GCLK"       unused   input  active-high 

User avatar
DougieLawson
Posts: 42848
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: GPIO Pin 4 always HIGH

Sun Dec 03, 2023 9:32 am

1-wire is a INPUT protocol.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

Return to “Troubleshooting”