P1 does not wake up after timer elpses or on interrupt

@mdma, I am using sleep mode on the P1 as below, but the P1 does not wake after 30 seconds or on a falling interrupt. I am hoping that you can help me out? I’m using 0.4.5 firmware.

I tested the same code on a photon and the photon functions as it should. (code is below) I also verified that the interrupt on pin D5 on the P1 is working too.

System.sleep(D5, FALLING, 30)

Thanks,

#include "application.h"
#include "MMA7660.h"

#define TFT_RST 20 //Place holder not used
#define YP A0  // must be an analog pin, use "An" notation!
#define XM A1  // must be an analog pin, use "An" notation!
#define TFT_CS A2 //Chip select pin for display
#define VoltagePin A6 //Determines system/battery voltage
#define Buzzer A7 //Buzzer for sound notification
#define TFT_LED D2 //Screen brightness control
#define TFT_DC D3 //Screen control pin
#define centerPin D4 //Center switch for tray alignment
#define acclInterrupt D5 // Acclemeter interrupt pin -
#define XP D6  // can be a digital pin
#define YM D7  // can be a digital pin
#define Charger RX //Open drain on LiPo charger, High when complete or disabled, low charging, flashing timer fault
#define LidSensorPin TX //Button to detect when lid is fully on
MMA7660 accelemeter;
int8_t x;   //accelemter x direection
int8_t y;   //accelemter y direction
int8_t z;   //accelemter z direction
float ax,ay,az; //accelemter x,y,z acceleration from -1 to 1

//boolean readTilt = false;
unsigned char tiltRegRead[8];

boolean sleep = false;
boolean loopStart = true;
unsigned long sleepBeginMillis = 0;
unsigned long sleepMillis = 60000;

void wakeUp();
unsigned char getTilt();
void sleepNow();

void setup(){
  Serial.begin(9600);
  pinMode(acclInterrupt, INPUT_PULLUP);
  accelemeter.init(); //Start MMA7660 accelemeter
  delay(15);
  attachInterrupt(acclInterrupt, wakeUp, FALLING);
  RGB.control(true);
  RGB.color(255, 0, 255);
  delay(400);
  RGB.control(false);
  //sleepBeginMillis = millis();
}


//LOOP***************************************************************************************************************
void loop() {
  if(loopStart){
    sleepBeginMillis = millis();
    loopStart = false;
  }
  accelemeter.getAcceleration(&ax,&ay,&az); //Get readings from the accel
  Serial.print("Sleep timer: ");
  Serial.println(millis() - sleepBeginMillis);
  delay(50);

  if(millis() - sleepBeginMillis > 10000){
    RGB.control(true);
    RGB.color(0, 255, 255);
    delay(300);
    //sleepBeginMillis = millis() + 2000000;
    sleep = true;
  }



/*  if(readTilt){
    Serial.print("Interrupt: ");
    Serial.println(Time.timeStr());
    readTilt = false;
    sleep = false;
    sleepBeginMillis = millis();
  }*/

  if(sleep){
    sleepNow();
  }

}

void wakeUp(){
  RGB.control(true);
  RGB.color(255, 255, 0);
    //readTilt = true;
    sleep = false;

    sleepBeginMillis = millis();
}

unsigned char getTilt(){
  Wire.begin();
  Wire.beginTransmission(MMA7660_ADDR);
  Wire.write(0x03);  // register to read
  Wire.endTransmission();
  Wire.beginTransmission(MMA7660_ADDR);
  Wire.requestFrom(MMA7660_ADDR,1); // read a byte
  byte count = 0;
   while(Wire.available()){
     if(count < 9){
       tiltRegRead[count] = Wire.read();
     }
     count++;
   }
   Wire.endTransmission();
}

void sleepNow(){
  RGB.control(true);
  RGB.color(255, 0, 0);
  delay(200);
  sleep = false;
  //sleepBeginMillis = millis() + 2000000;
  Serial.println("SLEEP MODE ENABLED");
  //Serial.print("  SLEEP Time: ");
  //Serial.println(sleepMillis);
  delay(100);
  System.sleep(acclInterrupt, FALLING, 30);
  sleepBeginMillis = millis();

}

Can you reduce this to a minimal test case please. Thanks!

@mdma, sure I’ll test the minimal case tonight then get back to you.

@mdma, below is my minimal code. Using this the P1 still does not wake up after 15 seconds.


//#include "application.h"

#define acclInterrupt D5 // Acclemeter interrupt pin -

boolean sleep = false;
unsigned long sleepBeginMillis;

//void wakeUp();
//unsigned char getTilt();
//void sleepNow();

void setup(){
  Serial.begin(9600);
  pinMode(acclInterrupt, INPUT_PULLUP);
  attachInterrupt(acclInterrupt, wakeUp, FALLING);
  sleepBeginMillis = millis();
}


void loop() {
  if(millis() - sleepBeginMillis > 15000){
    sleep = true;
    RGB.control(true);
    sleepBeginMillis = millis();
  }

  if(sleep){
    sleepNow();
  }
}

void wakeUp(){
  Serial.print("Interrupt triggered");
  sleep = false;
  sleepBeginMillis = millis();
}

void sleepNow(){
  Serial.print("Going to sleep");
  System.sleep(acclInterrupt, FALLING, 15);
  sleep = false;
  sleepBeginMillis = millis();
  RGB.control(false);
}

1 Like

@mdma, do you know if waking the P1 works for you? I am still unable to wake it up.

Thanks,

@mdma, Just wondering if you’ve been able to verify the P1 sleep functions? My P1’s never wake up, I’m using 0.4.6.

I guess this is related to this issue

I just found this on a todo list from last year - I realize this is an old thread - did you get this resolved?

@mdma, for the most part, I think there is another thread related to the spare pins that cant wake up the P1

Thanks for check in!

1 Like