Victory! I managed wake on pin with a Pysense!
Adding a 1.2K resistor between 3V3_Sensor and the input pin resolved the situation, with the high/low voltages within range. Coupled with the PIC firmware change, and changes to the Pysense library, the PIC wakes up and the Pymodule as well!
As I am definitely not a hardware guy, I'm pretty sure this is not really the best solution, as it results in very high "low" voltages on the input pin (1.63V when the LoPy is powered, 1.23V when it's not), but at least it validates the fact that you can definitely wake on pin with Pysense.
So, here are the details:The firmware needs to be modified to (at least) clear INTF when it occurs, otherwise the ISR will be called forever.
@bucknall or @daniel, can you please release a new version of the firmware that does this? Ideally it would also set/clear a flag somewhere else that could be checked via peek_memory. In my case I don't need this as the sensor I use keeps the signal high for a few seconds at least, so I just check if the pin is up on boot, but others may need it (and it would be required for a correct "wake up reason").
Until such a firmware is released, you can start from the existing Pysense 0.0.4 firmware .dfu, and do the following:make a copy (let's call it pysense_0.0.4-patched.dfu) strip the DFU header with dfu-suffix -D pysense_0.0.4-patched.dfu change bytes 40A & 40B from 82 31 to 8B 10 (that's a BCF 0B, 01 replacing an unnecessary MOVLP 02) changes bytes 3EFE & 3EFF from A6 04 to C2 1B (that's the new application checksum for the bootloader) re-add a new DFU header with dfu-suffix -p 0xF011 -v 0x04D8 -d 0xFFFF -a pysense_0.0.4-patched.dfu Flash the new firmware onto the Pysense: power-on the Pysense with the button pressed within a few seconds, run dfu-util -D pysense_0.0.4-patched.dfu
If you don't get your timing right it may fail, just retry a couple of times and it should work.
Change the Pysense library so that the line just before sending the GO_TO_SLEEP command reads:py.poke_memory(ANSELC_ADDR, ~((1 << 7)|(1 << 1)))
This is to keep RC1 a digital input.
Either in the Pysense library, or between the calls to setup_sleep and go_to_sleep, add:py.poke_memory(0x0b, py.peek_memory(0x0b) | 0x10)
This is to enable interrupts on RC1. Register 0x0b is INTCON and bit 0x10 is INTE.
Option: you can change the edge on which you want interrupts with bit 6 (INTEDG) of 0x95 (OPTION_REG).Connect your sensor to: GND (pin 1 on the External I/O header of the Pysense) 3V3_Sensor (pin 4) EXT_IO1 (pin 6).
Also add a resistor between 3V3_Sensor and EXT_IO1. I used a 1K2 resistor, but:this will probably vary based on the sensor there's probably a much better way to do this to achieve the right voltages in all cases!
Now you can:check the status of your sensor with pin P9 or via the Pysense: py.peek_memory(0xE) & 0x02 (bit RC1 of PORTC) go to deep sleep using the Pysense library see your Pysense and LoPy wake up when the sensor sets its output high!
Again, if someone has a better way of wiring this up so that the levels are really correct whether the ESP32 is powered or not, that would be most welcome!