flow sensor inconsistent wake up on occasional deepsleep mode use #11627
Replies: 4 comments
-
First re-format your code. <```py> What is `flow_sensor_pin = ADC(Pin(36))' doing? Are you trying to take an ADC reading? |
Beta Was this translation helpful? Give feedback.
-
Sorry about that that is my my first discussion entry. I connected a bridge from flow sensor's signal cable to GPIO36, when detect HIGH signal, esp32 wakes up. but whether I connect or not that bridge it did that.
|
Beta Was this translation helpful? Give feedback.
-
Ideas to try:
I don't know how this can work, so I assume the source you posted is incomplete. Also note that the ESP32 will need 1-2 seconds to boot from deepsleep. Pulses coming in during this time will be lost. Edit: Even when Pin(36) is a wakeup source, you aren't counting this initial pulse. |
Beta Was this translation helpful? Give feedback.
-
The code formatting suggestion wasn't helpful. Ignore the <> around the characters, so at the beginning 3 backticks with py and then 3 backticks at the end. It is not likely to be a formatting error but it makes it easier for other people to read when one can see the indentations, etc. Good luck. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
That code normally do this; it stay at deepsleep mode until it detected water flow after that wake up and start counting liter when water flow stoped it write the final value to new line at data.tx and go to deep sleep again. But sometimes it is wakes up read 0 write 0 LT/min to data.txt and go to deepsleep after and after. sometime it works as it should. it is confusing. Can you help me find where the problem is?
`from machine import Pin, ADC, deepsleep, RTC
import time
import esp32
import machine
from time import sleep
if machine.reset_cause() == machine.DEEPSLEEP_RESET:
print('woke up from a deep sleep')
rtc = RTC(
year, month, day, _weekday, hours, minutes, seconds, subseconds = rtc.datetime()
print(hours)
print(minutes)
print(day)
print(month)
print(year)
push_button = Pin(14, mode = Pin.IN) #setting push_button as wake up source
esp32.wake_on_ext0(pin = push_button, level = esp32.WAKEUP_ANY_HIGH) #initializing wake up
flow_sensor_pin = ADC(Pin(36))
calibration_factor = 7.5
flow_count = 0
flow_rate = 0
total_mililiter = 0
previous_millis = time.ticks_ms()
def flow_sensor_callback(p):
global flow_count
flow_count += 1
flow_sensor = Pin(36, Pin.IN)
flow_sensor.irq(trigger = Pin.IRQ_RISING, handler = flow_sensor_callback)
if flow_count <= 0 :
sleep(1)
while True:
current_millis = time.ticks_ms()
if flow_count > 0 : # Check if flow_count has been updated
if time.ticks_diff(current_millis, previous_millis) >= 1000:
flow_rate = (flow_count * calibration_factor) / (time.ticks_diff(current_millis, previous_millis))
total_mililiter += flow_rate
`
Beta Was this translation helpful? Give feedback.
All reactions