I am receiving a signal train of alternate high low pulses and trying to read it on Raspberry Pi Zero W. I have enabled the one wire pin(GPIO-4) and used that pin to read the pulses. I am reading the external pulse that I have connected to GPIO4. I have checked in the oscilloscope and so when I am reading the same through raspberry pi it seems like it is skipping some durations.

Below is my code in Python and the screenshot of the oscilloscope:

import RPi.GPIO as GPIO
import time

# Pin configuration
input_pin = 4  # Use the GPIO pin number you're connecting to

# Initialize GPIO settings
GPIO.setup(input_pin, GPIO.IN)

# Main loop to receive data
    while True:
        GPIO.wait_for_edge(input_pin, GPIO.FALLING)
        low_start_time = time.time()
        GPIO.wait_for_edge(input_pin, GPIO.RISING)
        low_duration = (time.time() - low_start_time)*1000
        print("low", low_duration)
        high_start_time = time.time()
        GPIO.wait_for_edge(input_pin, GPIO.FALLING)
        high_duration = (time.time() - high_start_time)*1000
        print("high", high_duration)
except KeyboardInterrupt:

The low and high durations are totally different from what I receive in the oscilloscope. There is a long pulse of low_duration of more than 50ms and so I am comparing it that way by taking the long pulse into consideration.

I am not able to figure out why am I skipping pulse, or is there something else that I am missing?

  • What does enabling the 1-wire pin mean? If you have enabled the 1-wire bus on GPIO4 the system will generate 1-wire traffic on GPIO4. Are you trying to monitor the system generated 1-wire traffic or are you generating signals externally? Please EDIT your question to clarify.
    – joan
    Commented Aug 24, 2023 at 12:28
  • I have edited my question. i have enabled 1 wire interface in raspberry pi config, and i am giving external signal to it. I just want to know the durations. should i disable the one wire interface and then measure?
    – John Mist
    Commented Aug 24, 2023 at 13:06
  • 1
    You should not enable the 1-wire bus unless you have connected a 1-wire device.
    – joan
    Commented Aug 24, 2023 at 13:47
  • What voltages are these pulses?
    – CoderMike
    Commented Aug 24, 2023 at 17:41
  • 1
    This has become a signal conditioning question. So off topic here. Run monitor.py or piscope
    – joan
    Commented Aug 25, 2023 at 7:15


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.