I’m currently working on a project, where if a button is normally pressed down mechanically, but when it is released, it should wake up the Photon. While this would normally cause a falling edge, the wiring diagram is as follows to make sure that the pressed state is low and the released state is high:
With this schematic, what should happen is that when the button is released, a rising edge signal is sent to the WKP pin, which should wake the Photon from standby mode. However, this is not happening.
In one test I did, I created a timeout function that put the Photon to standby mode after ten seconds. Leading up to the ten second mark, I held down the button, so it should be at a low signal. After the ten second mark, when the device was put to sleep by a timeout function, I released the button, which means that the signal should be at high. While this rising edge should cause the Photon to wake up, nothing happened.
I’m not testing with any code apart from the timeout function. Since it’s waking from standby mode, it wouldn’t be running any code. Here is the timeout function:
Globals:
struct CB_Timer {
long start;
int delay;
int (*callback)();
};
Setup Function:
CB_Timer awake_time = { millis(), 30000, put_to_sleep };
Timeout Function:
int put_to_sleep() {
strip.clear();
strip.show();
System.sleep(SLEEP_MODE_DEEP);
return 1;
}
In my loop function, I call an check function to see if any of my timers are up, and if so call the callback function. The timeout function seems to be running fine thought I don’t believe that’s the source of the problem.
Unfortunately this is an incomplete snippet of a circuit - however if I have to make some assumptions
VIN = 3V3
WKP is a pin on your Photon
How did you calculate the 10M value for the resistor and what is the purpose of the diode? In this configuration WKP will never change state?
How is the WKP pin defined on the Photon?
It is always better to post a compilable code sample that exhibits the problem - and a full schematic - that way folks don’t have to guess your intentions?
On the Photon there are pins namedVin (5V supply either via USB or externally into that pin) and WKP (aka A7).
That should (probably) prevent cross talk between A3 and A4 which share the connection to WKP/A7.
Although the two diodes may well cause WKP to float while the buttons are pressed.
Not convinced in this schematic it will work. You would need to have the photon pin defined as INPUT_PULLDOWN (or external pulldown) - secondly with the 10M resistor - this allows 330 nA to flow from Vin - I am not sure it will forward bias the diode enough.
Another thing if you have two switches to the same WKP pin and no other connections - how do you know which one was pushed?
SO back to my point about above saying “complete information” or we are all guessing
System.sleep() overrides the set pinMode() to the respective default depending on the selected sleep mode.
An external pull-down is probably the better choice but with the 10M pull-up finding a suitable value may be difficult.