Reputation: 11
I am using a radar sensor which provides square wave according to the speed of object it is sensing. I want to calculate speed of object with changing frequency of square wave signal. Following code gives frequency but my problem is that code keeps on printing last value even when there is no input signal at gpio pin. How to make it to zero or stop printing last value.
import time
import pigpio
import read_PWM
PWM_GPIO = 21
SAMPLE_TIME = 1.0
pi = pigpio.pi()
p = read_PWM.reader(pi, PWM_GPIO)
while True:
time.sleep(SAMPLE_TIME)
f = p.frequency()
pw = p.pulse_width()
dc = p.duty_cycle()
print(f)
Upvotes: 1
Views: 180
Reputation: 153
You could create a NOT gate that turns on when there is no signal to the GPIO pin.
then you could change your code to be like:
import time
import pigpio
import read_PWM
PWM_GPIO = 21
SAMPLE_TIME = 1.0
pi = pigpio.pi()
p = read_PWM.reader(pi, PWM_GPIO)
p2 = read_(whateverthisimplementations HIGH, LOW basic read is)
while True:
time.sleep(SAMPLE_TIME)
f = p.frequency()
pw = p.pulse_width()
dc = p.duty_cycle()
if p2 != HIGH:
print(f)
Upvotes: 1