1

I am continuously measuring some parameters using Raspberry Pi. I am using Python. When the measured value is higher than a particular value, I want to set a GPIO pin high (for some LED indicator) and the measurement should be paused for next 10 seconds. I used time.sleep(10) function. After 10 seconds, measurement should continue. I noticed that even after 10 seconds, the PIN keeps HIGH level (even though measured value was lower than limit value). When I removed the time.sleep(10), everything works fine. I am using pigpio module. any suggestions please


newMeasurement=[]
lastMeasurement=[]
while True:
            mesurement = []
            time.sleep(1.0)
#pin 18 to control LED
            pi.write(18,0)


            for i in range(4):
                newMeasurement[i] = cb[i].tally()  # function to do measurement               
                mesurement.append(newMeasurement[i]-lastMeasurement[i])
                lastMeasurement[i]= newMeasurement[i]


            if (mesurement[0] > 100 or mesurement[1] > 110 or mesurement[2] > 120 or mesurement[3] >130 ):
                pi.write(18,1)                                           
                print("ON LED")
                time.sleep(10.0)  # sleep function
                pi.write(18,0)    #set LED back to LOW. It doesn't work!!!
            else:
                pi.write(18,0)
                print("LED OFF")

  • 1
    mesurement.append((newMeasurement[i]) makes me think that you only ever check the first 4 measurements. This line also seem to have unbalanced braces, so it's not your actual code, is it? – Dmitry Grigoryev May 22 at 14:22
  • Agree with Dmitry - there are other clues that this isn't your real code. Please post the real code - suspect your bug lies elsewhere. – Mark Smith May 22 at 14:23
  • That is true, I removed some parts to show. But i just printed the values. Then i realized that the measured value was almost 10 times than actual value. so during sleep time, the values were adding up!!! – dayDreamer May 22 at 14:27
  • @DmitryGrigoryev please check the new code – dayDreamer May 22 at 14:32
  • @MarkSmith please check the new code – dayDreamer May 22 at 14:47

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.