1

I am having trouble detecting a level change on pin 16 (or any other pin). My script is as follows:

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.IN, pull_up_down = GPIO.PUD_UP)

while True:
    if GPIO.input(16)==0:
         print("High")
    else
         print("Low")
    sleep(0.1)

After running this code snippet I get "Low" being printed out constantly, even if I connect pin 16 directly to pin 1 (3.3V) using a jumper wire.

To try and figure out why I was not seeing any change I installed pigpio to run monitor.py which monitors GPIO for level changes.

After running the script I get:

G=14 l=0 d=159303
G=14 l=1 d=5
G=14 l=0 d=90

Why is a change being detected on Broadcom GPIO 14 which corresponds to physical pin 8, instead of Broadcom GPIO 23 which corresponds to physical pin 16?

Any pointers on what I could be doing wrong are greatly appreciated.

  • GPIO14 is TXD. Perhaps something is using the serial link or the line is floating. – joan Jul 20 '18 at 12:18
  • Yes, strangely only when I place or remove the jumper wire from the 3.3V do I see GPIO14 changing state. I am also seeing changes in GPIO 8 which is SPI. This started happening when I connected the jumper wire to physical pin 17 instead of physical pin 1. (3.3V) – Rrz0 Jul 20 '18 at 12:27
  • 1
    I'd set all the GPIO internal pulls so that the GPIO don't float, e.g. for ((i=2; i<28;i++)); do pigs pud $i d; done. I would then do a quick test such as pigs p 23 60 to start PWM on GPIO23. Switch off using pigs p 23 0. – joan Jul 20 '18 at 12:36
  • Does GPIO.setup(16, GPIO.IN, pull_up_down = GPIO.PUD_UP) use Physical Pin number or BCM Pin Number or WiringPi Pin number? – MaNyYaCk Jul 20 '18 at 12:39
  • @joan thanks for your suggestion. Please excuse this basic question but where should I write the above code you mentioned? Also, Pin number since I specified this in the line before it. – Rrz0 Jul 20 '18 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.