Problem with low Power Mode

Hi there,

im using CubeCell GPS 6502 in latest Hardwareversion together with an 18650 LiIon. Almost everything is working, like suggestet, but low Power.

as Basic I use LoRaWanMinimal sample little modified. The device stays active and is send to LowPower with long userkey pressed or with too low Battery:

  while(digitalRead(INT_GPIO) == 0)
  {
      if (millis()-starttime > 10000)
      {
          display.clear();
          display.setFont(ArialMT_Plain_16);
          display.setTextAlignment(TEXT_ALIGN_LEFT);
          display.drawString(2, 25, "Taste loslassen!");
          display.display();
          TimerStop(&Cycle);
          TimerStop(&DistanceTimer);  
          onSleep();              
          break;
      }
  }
  
  if (((int)((float)BoardGetBatteryLevel_V2()/255*100))<10)
  {
      display.clear();
      display.setFont(ArialMT_Plain_16);
      display.setTextAlignment(TEXT_ALIGN_LEFT);
      display.drawString(0, 8, "Akku leer");
      display.drawString(0, 32, "Schlafen!");
      display.display();
      TimerStop(&Cycle);
      TimerStop(&DistanceTimer);  
      delay(30000);
      onSleep();                 
  }

onSleep(): (defined Userkey interupt to wake up)

void onSleep()
{
    while(digitalRead(INT_GPIO) == 0)
    {
      delay(100);
    }
    GPS.end();
    display.clear();
    display.display();
    display.setFont(ArialMT_Plain_16);
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.drawString(2,25, "Schlafen");
    display.display();
    delay(2000);
    display.clear();
    display.display();
    display.stop();
    VextOFF(); //oled power off 
    attachInterrupt(INT_GPIO,onWakeUp,FALLING);
    State = DEVICE_STATE_SLEEPCHARGE;
}

And onWakeUp:

void onWakeUp()
{    
  detachInterrupt(INT_GPIO);
  VextON();// oled power on;
  delay(10); 
  display.init();
  display.clear();
 
  display.setFont(ArialMT_Plain_16);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(2, 25, "Starte!");
  display.display(); 
  delay(2000);
  State = DEVICE_STATE_START_GPS;   
}

When part with sleepmode at too low Battery commented out, lowpower is working, can get Device into lowpower and wake it up with User-key, but with low battery part and sending it manually to low Power it goes into onSleep() and wakes up instant with onWakeUp(). No Lowpower inbetween.

Have no idea, why this is happening. Any Suggestions?

here the whole main loop:

void loop()
{
  switch( State )
  {
    case DEVICE_STATE_START_GPS:
    {
      Serial.println("DEVICE_STATE_START_GPS START");
      GPS.begin(9600);
      GPS.setmode(MODE_GPS_GLONASS);
      State = DEVICE_STATE_INIT;
      Serial.println("DEVICE_STATE_START_GPS END");
      break;
    }
    case DEVICE_STATE_INIT:
    {
      Serial.println("DEVICE_STATE_INIT START"); 
      LoRaWAN.begin(LORAWAN_CLASS, ACTIVE_REGION);
      //Enable ADR
      LoRaWAN.setAdaptiveDR(true);
      State = DEVICE_STATE_JOIN;
      Serial.println("DEVICE_STATE_INIT END"); 
      break;
    }
    case DEVICE_STATE_JOIN:
    {
      Serial.println("DEVICE_STATE_JOIN START"); 
      LoRaWAN.joinABP(nwkSKey, appSKey, devAddr);
      State = DEVICE_STATE_CYCLE;
      Serial.println("DEVICE_STATE_JOIN END"); 
      break;
    }
    case DEVICE_STATE_CYCLE:
    {
        Serial.println("DEVICE_STATE_CYCLE START"); 
        txDutyCycleTime = appTxDutyCycle + randr( 0, 1000 );
        TimerSetValue(&Cycle, txDutyCycleTime);
        TimerStart(&Cycle);
        State = DEVICE_STATE_SLEEP;
        Serial.println("DEVICE_STATE_CYCLE END");
        break;    
    }
    case DEVICE_STATE_SEND:
    {
      Serial.println("DEVICE_STATE_SEND START");
      prepareTxFrame(1);
      while(!LoRaWAN.send(appDataSize, appData, 1, false));
      Lat_old = GPS.location.lat();
      Lon_old = GPS.location.lng(); 
      State = DEVICE_STATE_CYCLE;
      Serial.println("DEVICE_STATE_SEND END");  
      break;          
    } 
    case DEVICE_STATE_SLEEPCHARGE:
    {
      lowPowerHandler();
      break;
    }    
    case DEVICE_STATE_SLEEP:
    {
      Serial.println("DEVICE_STATE_SLEEP START");
      uint32_t starttime = millis();
      while( (millis()-starttime) < 500 )
      {
        while (GPS.available() > 0)
        {
          GPS.encode(GPS.read());
        }
      }
      Distance = distance_m(Lon_old, Lat_old, GPS.location.lng(),GPS.location.lat());
      display.clear();
      displayGPSInof();
      if (GPS.hdop.hdop() < 2 ) {
        TimerStart(&DistanceTimer);
      }
      //printGPSInof();
      delay(500);
      //LoRaWAN.sleep();
      starttime = millis();
            
      while(digitalRead(INT_GPIO) == 0)
      {
          if (millis()-starttime > 10000)
          {
              display.clear();
              display.setFont(ArialMT_Plain_16);
              display.setTextAlignment(TEXT_ALIGN_LEFT);
              display.drawString(2, 25, "Taste loslassen!");
              display.display();
              TimerStop(&Cycle);
              TimerStop(&DistanceTimer);  
              onSleep();              
              break;
          }
      }
      
      if (((int)((float)BoardGetBatteryLevel_V2()/255*100))<10)
      {
          display.clear();
          display.setFont(ArialMT_Plain_16);
          display.setTextAlignment(TEXT_ALIGN_LEFT);
          display.drawString(0, 8, "Akku leer");
          display.drawString(0, 32, "Schlafen!");
          display.display();
          TimerStop(&Cycle);
          TimerStop(&DistanceTimer);  
          delay(30000);
          onSleep();                 
      }
      
      Serial.println("DEVICE_STATE_SLEEP END"); 
      break;      
    }      
    default:
    {
      State = DEVICE_STATE_CYCLE;
      break;
    }    
  }  
}

What is with pull up Resistor?

Just worked it out, have to give lowPowerHandler more Time to power down. In Loop after While(digitalREad…) i put an IF(DEVICE_STATE_SLEEPCHARGE) {break;}; and it worked. Too much code between