Is there a way to pull up HIGH a pin while sleeping the photon?
Makes sense on the efficiency - I remember reading that it was ~75-90%
I will re-measure the amps, but I remember measuring 0.04 (40 mA) in both cases - which agreed, does not make sense.
EDIT: Looked up:
"Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This means that they can provide a substantial amount of current to other circuits. STM32 pins can source (provide positive current) or sink (provide negative current) up to 20 mA (milliamps) of current to other devices/circuits."
^ so now I know for a fact the no matter what I measured - the digital pins can't provide that :), and if anything - it ends up being even lower.
So it really comes down to powering via 5V Vin, and then finding a way to inverse the pin into "HIGH" through the step-up converter for the 5V needed to "control" the heater and turn it off. Any ideas? (other than cutting it, which I am trying to reserve as a last resort solution)
Not in deep sleep. In deep sleep all pins (excep WKP) go hi-Z. That's where external pull resistors come into play.
DMMs are no good tool for measuring switched signals and that's what a buck/boost converter produces in the process.
Did you not believe it when I wrote it? Where do you think we take our info from?
Several but they'd be way more complicated (to do and to explain, which I'm reluctant to do) than cutting the trace. Anyway, you can always resolder the cut to revert the change.
You'd have a running system already by now.
Ok - so this is key. Essentially, as long as the photon is awake, I can low the control pin, and thus have the heater on.
Sorry, I didn't even see it if you mentioned it above. I was trying to look up anything and everything on sleep states+power, and the OUTPUT vs INPUT vs PULLS in hopes of discovering something.
I also picked up a few mosfet n and p channel switches (just to have them). I think the P one would actually be useful here if the pin's didn't work as you described.
I am going to try this out tomorrow and report back.
Again - thank you for all of the info + your time. Greatly appreciated!
int heater = D5;
int gasSensorData = A0;
void setup() {
Serial.begin(9600);
pinMode(heater, OUTPUT);
pinMode(gasSensorData, INPUT);
WiFi.off();
}
void loop() {
// Turn off power to control pin, which turns ON the heater
digitalWrite(heater, LOW);
// Wait 8 seconds - for the heater to heat up.
delay(8000);
// Read gas value.
int gas = analogRead(gasSensorData);
Serial.printlnf("===> %d", gas);
if(gas > 550) {
WiFi.on();
while(!WiFi.ready()) {
delay(250);
if (WiFi.ready()) {
Particle.publish("gas-value", String(gas), PRIVATE);
}
}
}
// Put into deep sleep - which will toggle Digital pins to HIGH until it comes back.
System.sleep(SLEEP_MODE_DEEP, 60);
}
With this part you may have some troubles.
For one, while it might be rather unlikely, it is imanignable that your two WiFi.ready() checks might just miss the fact when the module gets ready just between the inner if() and the while() condition.
For that I'd rather use waitUntil() or waitFor().
And when you intend to use Particle.publish() just connecting WiFi and only checking for the network to be ready is not enough. You need to call Particle.connect() and wait for Particle.connected().
When not permanently using WiFi and cloud, I'd opt for SYSTEM_MODE(SEMI_AUTOMATIC) and SYSTEM_THREAD(ENABLED) isn't a bad thing either.
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
int heater = D5;
int gasSensorData = A0;
void setup() {
Serial.begin(9600);
pinMode(heater, OUTPUT);
pinMode(gasSensorData, INPUT);
}
void loop() {
// Turn off power to control pin, which turns ON the heater
digitalWrite(heater, LOW);
// Wait 8 seconds - for the heater to heat up.
delay(8000);
// Read gas value.
int gas = analogRead(gasSensorData);
Serial.printlnf("===> %d", gas);
//Particle.publish("gas", String(gas), PRIVATE);
if(gas > 600) {
Particle.connect();
waitUntil(Particle.connected);
Particle.publish("gas-alert", String(gas), PRIVATE);
}
// Put into deep sleep - which will toggle Digital pins to HIGH until it comes back.
System.sleep(SLEEP_MODE_DEEP, 600);
}
ps: For anyone reading this and discovering waitUntil/waitFor (like me) -- here's the difference:
Use waitUntil to delay the application indefinitely until the condition is met.
Use waitFor to delay the application only for a period of time or the condition is met.
@ScruffR - Can you provide me with some more information about "hi-Z"?
I found some information that "hi-Z" (high-Z and low-Z) has to do with impedance.
Assuming this holds true for the Photon:
Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This means that they can provide a substantial amount of current to other circuits.
But I can't tell if that ^ is during deep sleep.
The high-impedance would mean the pin is configured as an input then?
If I am understanding this correctly, hi-Z would mean that the pins are configured as inputs, and can wakeup the device on any low current? From somewhere I thought if configured as an output, they will keep that configuration in deep sleep -- so wouldn't they be low-Z essentially then? (if so - is my assumption correct on low-z about output?)
I take the below explanation to mean that a GPIO pin set as an output and set to LOW will remain LOW when put into Deep Sleep. I’m learning along with you though
@RWB - so if I configure the pin as an OUTPUT + HIGH and then deep sleep, it will be the [let's call it first state] of HIGH?
(vs if I configure as an OUTPUT + LOW, it will be the [let's call it second] state of LOW)
The part that confuses me from this is that it sounds like there's no voltage while off:
When activated into its third state it disables or turns “OFF” its output producing an open circuit condition that is neither at a logic “High” or “Low”, but instead gives an output state of very high impedance, High-Z, or more commonly Hi-Z. Then this type of device has two logic state inputs, “0” or a “1” but can produce three different output states, “0”, “1” or ” Hi-Z ” which is why it is called a “Tri” or “3-state” device.
Note that this third state is NOT equal to a logic level “0” or “1”, but is an high impedance state in which the buffers output is electrically disconnected from the rest of the circuit. As a result, no current is drawn from the supply.
My understanding is that the pin starts floating at basically 0v if the pin you're connecting it to has no bias.
So if you have a pin set as Output - LOW it will essentially remain low when the Photon goes into Deep Sleep.
If you have a pin set as OUTPUT - High it will then go 0V when the Photon goes into Deep Sleep which means there is no voltage available.
I have read other threads on the forum where they set a GPIO pin as Output - LOW to control an Enable pin on a circuit and when the Photon was put into Deep Sleep mode the Enable pin was still considered Low for an Adafruit Ultimate GPS unit so it stayed sleeping when the Photon was put into deep sleep.
So basically the pin goes into a floating state during Deep Sleep where nothing is feeding that pin, so as they say it's neither Hi or Low but Floating but I take that as the pin has zero voltage potential.
I'm not sure what the best way to keep a pin High during Deep Sleep or if it's even possible without external circuitry. I'm sure somebody has already asked this question a few times on the forum.
I'm no expert so we will see what the seasoned pros have to say about this.
No, it does not! What you may be thinking of is Stop Mode Sleep, but deep sleep the pins go hi-Z (= tristate).
INPUT pins are also hi-Z but that is not the same thing here as during deep sleep does no signal sampling going on (apart from WKP).
Also not. Floating means "no distinct potential" whatever charge is floating round in the air will influence the signal and you would read random values.
The answer was provided multiple times in this thread already: External pull-up
This exactly is the part that seems backwards to me. I would understand turning something on with voltage (and thus turning it on by applying a HIGH to En), but the En pin needing voltage to keep something off seems strange to me given you would want low power mode.
I can check this tonight with the multimeter to see what's happening.
But as you said - I am assuming members like @ScruffR know this in their sleep
When outputs are tri-stated (in the Hi-Z state) their influence on the rest of the circuit is removed, and the circuit node will be "floating" if no other circuit element determines its state. Circuit designers will often use pull-up or pull-down resistors (usually within the range of 1–100 kΩ) to influence the circuit when the output is tri-stated.
So does this mean I need to set the pin to "INPUT_PULLUP"?
Similar issue as mine, but instead they needed it LOW and to stay LOW.
From the GPS module (not the gas sensor I am using), the En is:
EN is the Enable pin, it is pulled high with a 10K resistor. When this pin is pulled to ground, it will turn off the GPS module. This can be handy for very low power projects where you want to easily turn the module off for long periods
^ Now this makes sense to me.
However, on the gas sensor it seems to be the opposite:
You can use the EN pin to power it off (pull it high to 5V to turn off) to conserve energy.
^ This simply does not make sense to me. It should be the opposite (same as the GPS module)
So the question to summarize the question I am not understanding: without cutting anything, and without adding external circuits, is there a way to deliver any low voltage (where 0 < V < 3) on a pin while the photon is in a sleep state, where that voltage can be turned off on wakeup/run (that is, not like the dedicated Vin or dedicated 3v3 pin)?
@ScruffR ^ this last part is what I don't currently understand.
Good to have this verified. As I said I'm no expert on all this.
I was specifically referring to deep sleep mode.
So even though others have successfully kept a pin LOW that was set as Output LOW before going into Deep Sleep to keep as mentioned in the link below to keep a Adafruit Ultimate GPS module in sleep mode while the Photon was in Deep Sleep mode that some static electricity has the potential to push that Hi-z pin-up past the voltage that the Ultimate GPS module considers low and the only way to guarantee it stays low is to use a pull-down resistor?
That makes sense to me.
I was just assuming that the Output Pin set LOW during a Hi-Z Sleep state would normally stay close enough to where it was before going into deep sleep that the connected device would still consider it LOW and remain OFF, which it does for some devices. To assume this would be true in all cases would be a mistake and to make sure the Enable pin stays low one should use a Pull Down resistor?
Am I on the right track with that line of thinking?
The simple way to understand tri-state Hi-Z is this: Hi-Z = disconnected
This is not quite true (after all it’s hi-z not infinite z), but for all intents and purposes, you can think of it that way. So, it’s just like you disconnected your wire from that pin. If your enable pin is connected to a Photon GPIO pin, then it will be floating when the Photon is asleep, hence the need for the pullup resistor. Floating is bad; in that state, you don’t know what voltage is on the pin, and it might change randomly.[quote=“ventz, post:40, topic:38398”]
This simply does not make sense to me. It should be the opposite (same as the GPS module)
[/quote]
It really doesn’t matter, from the stand point of what you need to do, whether the enable pin is active high or active low; the only difference is whether you need a pull-down resistor to ground, or a pull-up resistor to 5v. Even if the enable pin worked the way that makes sense to you, you would still need that external resistor, because when the Photon is asleep, and the GPIO pin is in the Hi-Z mode, it is neither LOW, nor HIGH, it’s floating.[quote=“ventz, post:40, topic:38398”]
is there a way to deliver any low voltage (where 0 < V < 3) on a pin while the photon is in a sleep state, where that voltage can be turned off on wakeup/run (that is, not like the dedicated Vin or dedicated 3v3 pin)?
[/quote]
No. The solution is simple, and @ScruffR has already given it to you; cut the trace, connect the enable pin to one of the Photon’s GPIO pins, and add a 10k pull-up resistor from enable to 5v.