SpellFoundry / SleepyPi2

Power Management board for Raspberry Pi
http://spellfoundry.com/sleepypi2
GNU General Public License v2.0
17 stars 15 forks source link

Sleepy Pi 2 bricked... and recovered! #9

Open daghemo opened 6 years ago

daghemo commented 6 years ago

I think I have bricked my Sleepy Pi 2 while working on my Sketch.

The Sleepy Pi 2 was connected to my Raspberry Pi while I saw I was not able to talk to the RTC:

root@black-surf(086c596):/usr/src/app# timedatectl status
      Local time: Fri 2018-10-05 22:41:40 UTC
  Universal time: Fri 2018-10-05 22:41:40 UTC
        RTC time: n/a
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: yes
RTC in local TZ: no
      DST active: n/a

Then I also saw:

root@black-surf(086c596):/data# i2cdetect -a -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f

I was not able to upload another sketch remotely using the Software Jumper because it was not working:

root@black-surf(086c596):/data# i2cset -y 1 0x24 0xfd
root@black-surf(086c596):/data# sleep 5
root@black-surf(086c596):/data# i2cget -y 1 0x24
0x00

After pressing the Reset button on the Sleepy Pi 2 I saw:

root@black-surf(086c596):/usr/src/app# i2cdetect -a -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Then, after some time:

root@black-surf(086c596):/usr/src/app# i2cdetect -a -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: -- -- 02 -- -- -- -- 07 -- 09 0a -- 0c -- -- 0f
10: 10 -- 12 -- -- 15 -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- 24 -- -- 27 28 -- 2a -- -- 2d 2e --
30: 30 -- -- -- -- 35 -- -- -- -- -- -- -- -- 3e 3f
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 -- -- -- -- -- -- 67 -- -- -- -- 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f

Again, after some other time:

root@black-surf(086c596):/data# i2cdetect -a -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f

That is, resetting the Sleepy Pi 2, rebooting the Raspberry Pi, removing the power from both the boards, also removing the battery from the Sleepy Pi 2 does not resolve the problem. I had to put the hardware jumper in place in order to upload a new Sketch.

daghemo commented 6 years ago

@SpellFoundry, I was getting the same error over and over, then I found the root case.

The following code can be used to reproduce the error:

#include "SleepyPi2.h"

unsigned long timeNow = 0, timeLast = 0;
char datetime[ 20 ];

void setup() {
    Serial.begin( 9600 );
    Serial.println( "Starting serial console..." );
    SleepyPi.rtcInit( true );
}

void loop() {
    DateTime now;
    timeNow = millis();
    now = SleepyPi.readTime();
    if ( ( timeNow - timeLast ) >= 5000 ) {
        sprintf( datetime, "%d/%02d/%02d %02d:%02d:%02d" , now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second() );
        Serial.println( datetime );      
        Serial.flush();
        timeLast = timeNow;
    }
}

Just moving SleepyPi.readTime() within the "if" will solve the problem. That is, the SleepyPi.readTime() should not be run too often! If not, it will break both the RTC on the Raspberry Pi and even its whole I2C bus.