Spark Core didn't go to sleep

Dear Sparks
I’m trying to use the sleep mode on the Spark Core, but it didn’t go to sleep when I supplied it with the power through the wall power jack, while it goes to sleep mode when I supplied it with power through the PC. I tried to change the USB cable, and the power jack with no luck Any suggestion please? @satishgn
Thanks in advance.
Ahmed.

Have you looked at these?
Pin pullup not waking cores from sleep (Waking by itself)
Having trouble using Sleep() with wakeUpPin
[SOLVED] Not able to put my core in stop mode (it just wakes up)

Can you show your code and give some info about the hardware setup?

With your rather minimalistic error description I’d guess on a floating wake pin.

1 Like

Have you looked at these?



You will find an example that is working…

1 Like

Hey @ScruffR
I did the bootloader upgrade, and I’m using the stop mode triggered pin with rising pin, so I don’t need to use a resistor as I read in the community. I’m using D0 in my code, and it was going to sleep (with wall power jack) before two days, but not for yesterday. I don’t know why it goes to sleep with the USB power supply, while it didn’t go to sleep with wall power jack.

Here is the code that I’m using(it was working just fine before two days):

//#include "application.h"
#include "Serial2/Serial2.h"
const int wakePin = D0;  // use Serial2 RX pin as wake pin

char szReceive[64] = { '\0' };
int idx = 0;
uint32_t ms;
uint32_t msPublish;
uint32_t msLastSerial;
bool frameStart = false;

void setup()
{
    pinMode(wakePin, INPUT_PULLDOWN);
    Serial.begin(9600);
    Serial2.begin(9600);
    msLastSerial = millis();
}

void loop()
{
    ms = millis();
    
    Serial2.flush();
    idx = 0;
    while (idx < 4 && millis() - ms < 1000 )
    {
        if(Serial2.available())
        {
            msLastSerial = millis();
            
            char c = Serial2.read();
            Serial.write(c);

            if (c == 'S')
            { 
                frameStart = TRUE;
                idx = 0;
            }

            if (frameStart)
            {
                szReceive[idx++] = c;
                szReceive[idx] = '\0';
            }
        }
    }
    Serial.println("Fallen out of while");

    if (idx >= 4 && millis() - msPublish > 1000)
    {
        Serial.println(szReceive);
        Spark.publish("Carpet1", szReceive, PRIVATE);
        msPublish = millis();
        idx = 0;
        frameStart = FALSE;
    }
    else
        Serial.println(" Timed out");

if (millis() - msLastSerial > 5000)   // stay awake 5 sec after last serial byte
     Spark.sleep(wakePin, RISING);
     }

Thanks @itayd100
I’ll read them.

I tried to change the pin to D1 instead of D0 with no success. I disconnected the board from the external input(another PCB board that has PIC18), and it is still didn’t go to sleep when I supplied it from the wall power jack.

If you consistently have problems with the wall wart and no problems via an USB port, I’m inclined to blame the wall wart.
Cheapo wall warts don’t always provide properly filtered DC and some even only provide pulsed DC (have a look at the type label, if you see a solid line with a dashed line underneath, that’s your reason).

Try a quality wall wart or add some proper filtering yourself.

1 Like

Thanks @ScruffR
As you said, I noticed the dashed line on the wall warts that I have. I’ll try to find a better one to work with.
I appreciated your help.

1 Like