Teensy 4.1 Power On/Off Help Requested

Hey all,

I have two buttons on my teensy 4.1 project that I'd like to merge to one. I got it mostly working, but I am having an issue I will detail below. First, here's their functionality:

Button 1: This is a record button to start logging data to a file on the SD card. I have is configured as follows:

Code:
  pinMode(REC_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(REC_PIN), ISR_ToggleLogging, RISING);

And some simple interrupt function:

Code:
  void ISR_ToggleLogging() {
      if ((millis() - lastPress) > debounceTime) {
        if (!isLogging) {
          Serial.println("STARTING LOGGER");
          StartLogging();
          isLogging = true;
          lastPress = millis();
        }
        else if (isLogging) {
        Serial.println("STOPPING LOGGER");
        QuitLogging();
        isLogging = false;
        lastPress = millis();
        }
      }
  }

Button 2: Power On/Off. I have the Power on/off pin (I'll call this Pof) that gets pulled to GND when the button is held down.

Here is a photo of the setup (sorry it's a bit of a rat's nest right now...)

wiring.jpeg

Goal: I am trying to combine these to one button. I connected the leads from D2 and Pof to the same rail which goes through the button to GND. The record button functionality works well, I have the interrupt set to RISING as well so that when you hold the button down for 5 seconds to power off the Teensy, that works too without triggering an unwanted record before power off. When I probe these for voltage, they are both around 3V.

BUT when the power is off, I cannot get the Teensy to turn back on in this configuration. I discovered that when I probe for voltage that Pof is at something like 0.4V. So something is amiss: this seems to obviously be due to the connection with D2 brining the voltage down when the power is off (when I disconnect D2 from Pof/button, the voltage goes back to 3V and I can power on again). Since D2 is configured with the pullup resistor I think it should default to high (~3V) when off? And Pof is normally 3V when the device is off and I probe it, but when they are connected -- I'm only getting 0.4V, so I suspect this drop from 0.4V to 0V when I hit the button to connect Pof to ground is not enough to trigger the device to turn back on.

Any thoughts on how to proceed? Changing something in the circuit, or firmware to get this to work? Ideally I can make this one button configuration work.

Thanks!
 
I Have the same issue (combining the Pof with another digital pin), Did you find a fix? Im thinking of trying an external pull-up.
 
After much pondering and research I've no idea why connecting a GPIO to ON/OFF breaks the ON state. The GPIOs are supposed to default to INPUT PULL_UP state. Ive been through lots of threads and found similar issues with ON/OFF and GPIO, but no solutions...

I don't think a pullup will be a sensible solution because on powerdown there is no 3.3v source. In my use-case I have VBat connected to use the RTC, this could be a pull-up source, but if something is pulling the pin back down, then a 10k resistor will add to the already large current drain of the RTC and drain the battery.

A bonus annoyance! As I've got VBat connected, with this issue on power down, the power state is saved, with no way to turn back on... I thought i'd fried the teensy until I disconnected it from my pcb...

In both the OP's post and my scenario, the aim is to detect the pending powerdown state and do something before powerdown.

After much research I found this thread which discusses detecting the power down state, and subsequently directed me to Frank's power library. This provides the hooks into the power pin state.

My potential solution is therefore to detect the GPIO state and use the power button as the GPIO button directly.
As a bonus this frees up a GPIO.

This is all theoretical as of now, it will be a week until I can test it... watch this space.
 
Okay so ive cut the GPIO track and the teensy does now turn On/Off properley. Ill report back once i've tried Francks power lib.
 
After a few hours tikering with frank's library i got the button working perfectly. I can do long and short press for different functions then a 5 second hold to turn off the device, and 1 second to turn it back on. it all works perfectly and i've saved a gpio!

Solved!

Thank you Frank for you library!
 
Back
Top