How to use a low-signaling sensor to trigger wake interrupt

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

How to use a low-signaling sensor to trigger wake interrupt

Post by kwiley » Wed May 20, 2020 2:00 am

I would have posted this in the ESP8266 forum, but it's really more of an electronics question, and probably a really basic one at that, given that I'm a software person with minimal electronics wherewithal.

The ESP8266 and its support boards (such as the ESP-01S) can go into deep sleep and then awaken in various ways, such as an alarm at a later time, or in the case of this post, on an interrupt on a particular pin. The ESP8266 has a reset pin that is held high even in deep sleep. If you connect it to ground, the board immediately resets (if it is awake) or immediately boots up (if it is asleep). So if a trigger sensor, such as an IR proximity sensor with an incorporated binary threshold (as opposed to using the sensor's smooth analog distance reading) sudden triggers, it can be used to ground the reset pin and boot the chip.

But the IR sensor I'm working with (one of the common ones you see everywhere, https://www.aliexpress.com/item/32321964595.html) has off-high/on-low logic. While output is high, indicating no proximity, I need the reset pin to be left alone. When the signal goes low, I need the reset pin to suddenly go low. At first, this seemed perfect to me. I would just feed the signal output directly into the reset pin. While the signal was high, the reset would hold high. When the signal went low, the reset would go low and trigger a wakeup. But this doesn't work. I suspect it is the difference between a high/low "signal" and a high/low direct connection to the primary ground of the main power circuit. Is the low signal not the same ground circuit as the chip's main power circuit? I would have thought so since I'm powering the sensor from the board's power supply, but it doesn't work. A multimeter confirms this signal voltage but the reset fails to occur, so I'm perplexed. I know that directly grounding the reset pin with a wire or a simple momentary switch works exactly as expected, but utilizing the sensor's output in this straightforward fashion fails to reset the chip, so I'm misunderstanding something probably really basic here.

At any rate, I figured I'd switch it with a transistor instead. I have a 2n7000 NPN transistor that I attempted to use as a switch, with the source/drain connecting the reset pin to ground and the gate connecting to the signal, but since the signal's logic is inverted, it obviously doesn't work right. The transistor is presumably on when it should be off and vs/va due to the sensor's inverted signal logic. I presume it would do exactly what I want it to do if the sensor was off-low/on-high, right?

I'm probably making this all needlessly complicated. What is the right way to have a sensor of this type pull the reset pin to ground to trigger the chip to wake up? I would prefer a solution that doesn't involve ordering and waiting for new parts (I'm suspicious of the possibility that the solution to my problem is the opposing transistor type, but I don't have any lying around).

Curiously, if I send the control signal straight into the CHPD pin instead, to effectively turn the board off, that works perfectly, but the reset pin doesn't do the same thing.

Thanks.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: How to use a low-signaling sensor to trigger wake interrupt

Post by jimmo » Wed May 20, 2020 7:05 am

kwiley wrote:
Wed May 20, 2020 2:00 am
At any rate, I figured I'd switch it with a transistor instead. I have a 2n7000 NPN transistor that I attempted to use as a switch, with the source/drain connecting the reset pin to ground and the gate connecting to the signal, but since the signal's logic is inverted, it obviously doesn't work right. The transistor is presumably on when it should be off and vs/va due to the sensor's inverted signal logic. I presume it would do exactly what I want it to do if the sensor was off-low/on-high, right?
You need a p-channel mosfet. (Or a PNP BJT).

Or if all you have is 2n7000 mosfets, then you can make a NOT gate out of one, and use that to drive the second.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How to use a low-signaling sensor to trigger wake interrupt

Post by pythoncoder » Wed May 20, 2020 8:43 am

It seems to me that the board should be reset with a direct connection. Is the problem that, when an object is detected, the reset pin is held low for all the time that the object is in place? This will stop the device from running until the object is removed, which is probably not what you want.
Peter Hinch
Index to my micropython libraries.

kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

Re: How to use a low-signaling sensor to trigger wake interrupt

Post by kwiley » Wed May 20, 2020 2:28 pm

I agree, and I'm aware of the behavior in which the board would not fully reset until after the sensor returns to its initial state. For some reason I'm not getting any reset behavior by sending the signal straight into reset regardless of whether the sensor settles down a moment later. I don't get it. Thank you for agreeing that it's strange.

kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

Re: How to use a low-signaling sensor to trigger wake interrupt

Post by kwiley » Wed May 20, 2020 2:30 pm

Thanks for confirming my hunch that I probably just need the opposing transistor type. I suppose I could string two together as you suggested, although I admit that seems unnecessarily convoluted. Thanks again.

kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

Re: How to use a low-signaling sensor to trigger wake interrupt

Post by kwiley » Thu May 21, 2020 6:48 am

I solved some of the mystery. I had directly tied GPIO16 to RESET to enable RTC wakeup. Apparently, doing this renders the sensor inoperable. By connecting the sensor's output directly to RESET with RESET connected to GPIO16, the sensor no longer triggers a reset. In fact the sensor no longer works (its own on-board LED no longer turns on and off in the presence and absence of an IR detection, so some sort of "reverse voltage" (?!) going up the signal line is rendering the sensor inoperable).

So, I can't use the sensor to wake up the board under these circumstances. On to my next problem. Without D0 connected directly to RESET, so the only connection on the entire board is the sensor output into RESET, I get the desired behavior, with the exception that it only works on every other reset, precisely every other reset. If I have the board put itself to sleep after a few seconds, I can fire the sensor to trigger a reset. The first time it will reset properly and then go to sleep. The second time, it will not properly reset, the program doesn't start running. The third time, it resets properly, then the fourth it doesn't, and so on.

Obviously, the board only comes back up after the sensor is no longer sending a signal, since its signal keeps the RESET line low, but when I release the sensor's distance measurement so its output goes high again, the board attempts to wake up, but on every other attempt, it's just a feeble wake up that doesn't fully kickstart the board. Send the board back down again by triggering the sensor lets it make another attempt to wake up, and on the subsequent attempt, it will work, always work/broken/work/broken in a perfect tick tock fashion.

Thoughts?
Last edited by kwiley on Thu May 21, 2020 11:59 pm, edited 2 times in total.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: How to use a low-signaling sensor to trigger wake interrupt

Post by dhylands » Thu May 21, 2020 7:28 pm

You didn't mention it, but you also have to have GND connected between the sensor and the board.

kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

Re: How to use a low-signaling sensor to trigger wake interrupt

Post by kwiley » Thu May 21, 2020 11:57 pm

Well, I'm powering the sensor from the board's own lines if that's what you mean. The IR sensor has three pins: VCC, GND, and signal. I'm feeding the sensor's power and ground from the ESP-01S's VIN and GND pins. Is that what you were asking?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: How to use a low-signaling sensor to trigger wake interrupt

Post by dhylands » Fri May 22, 2020 12:09 am

Yeah - without ground, the signal can't be interpreted properly.

kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

Re: How to use a low-signaling sensor to trigger wake interrupt

Post by kwiley » Fri May 22, 2020 7:37 am

What do you mean "without ground". The sensor has a VCC and a GND line. Those are connected to the ESP board's VIN and GND lines. Then I connected the sensor's signal line to the RESET line. I'm sorry, but I'm not understanding what you're trying to explain about my setup.

Post Reply