The following code is running on PI3 and is working perfectly fine. I try to provide a short description of what the code does. In this code I first set the BCM 12 as the pin of interest for my sensor which is a proximity sensor. Normally the pin is 1 unless I put something close to sensor in which case pin becomes 0. I pasted main parts of the code for your reference down here (I did not paste the whole code here). Now question is when I use the same code in PI4, it acts differently. Even without anything close to the proximity sensor, the pin is 0. In fact the pin always stays at zero. Expected behavior is: pin BCM 12 should stay 1 unless I put something next to sensor and in that case it should change into 0. But on PI4, it always stays at 0.
import RPi.GPIO as GPIO # pylint: disable=import-error PROXIMITY_SENSOR_GPIO_CHANNEL = 12 LED_GPIO_CHANNEL = 20 GPIO.setmode(GPIO.BCM) GPIO.setup(PROXIMITY_SENSOR_GPIO_CHANNEL, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(LED_GPIO_CHANNEL, GPIO.OUT) # this function checks whether the pin is triggered def is_sample_present(): return GPIO.input(PROXIMITY_SENSOR_GPIO_CHANNEL) == 0 def setup_proximity_callback(): GPIO.add_event_detect( PROXIMITY_SENSOR_GPIO_CHANNEL, GPIO.RISING, proximity_sensor_callback, bouncetime=1 )