Posts: 9
Joined: Tue Jan 30, 2018 4:16 pm

Sleepy Pi 2 Communicating with the Pi3

Tue Jan 30, 2018 4:25 pm


I have a Pi 3 Model B with a SleepyPi2 attached to it. It is currently turning itself off after it performs a task, and 'wakes up' every five minutes. This is performing as expected and is all fine however, if I connect to the pi via SSH the pi will 'restart' after 5 minutes, every 5 minutes even if the Pi is on.

I've thought about changing a pin to communicate with the pi signaling that it shouldn't reboot and I've looked into SleepyPi WakeOnPin example to do something similar. Where if the pin has changed from 0 to 1 it will go into an isr function, set a global variable activeSSH = true then it would not continue the countdown to bootup.

My issue I'm having is I can't figure out how I'd be able to set the GPIO pin on the pi which would correspond to the arduino pin to be able to communicate. Maybe I'm not understanding this right.

Does anyone have any experience in this?


Posts: 1
Joined: Sun Mar 19, 2017 2:37 am

Re: Sleepy Pi 2 Communicating with the Pi3

Fri Feb 16, 2018 4:19 pm

If You setup Sleepy Pi 2 with its setup script and use Sleepy Pi 2 Arduino library and examples, than You have have to look at both sides to modify the way wakeup/shutdown acts to meet your needs.

For the standard method, based on pins status check, two pins of Raspberry are used, pin 24 and 25.
There is also another method that checks the current, look Sleepy Pi 2 examples

During Raspberry setup is installed, and configured to run at boot, a Python script "".
In this script RPi pin 25 is configured as output pin and set to high (used by Arduino code to know that RPi is running) and RPi pin 24 is configured as input and used to monitor for a high signal from Arduino, if the value is high than RPi shutdown procedure is started. ...

Code: Select all

GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.OUT)
GPIO.output(25, GPIO.HIGH)
print ("[Info] Telling Sleepy Pi we are running pin 25")

while True:
	if (GPIO.input(24)):
		print ("Sleepy Pi requesting shutdown on pin 24")
		os.system("sudo shutdown -h now")
You could add some code in the script hereabove to check if SSH is active and than not start shutdown, but that will be prevent the RPi awitch off. Infact on the other side, Arduino Sleepy Pi 2, with the code derived from periodic wakeup example, will simply cut the power after a while.

So there are several alternatives, for example,
- modify the Arduino code to not cut power of RPi pin 25 doesn't go low (RPi shutdown completed). But if RPi is hang than it will stay always on
- monitor an additional pin, as You wrote, than You could delay shutdown till this additional pin is high
- ...

On the Arduino side check the Sleepy Pi 2 library, it will be more clear how it works, and also how You can implement your pin check solution ... epyPi2.cpp

This is part of the code of piShutdown function with some additiona comments

Code: Select all

               digitalWrite(CMD_PI_TO_SHDWN_PIN,HIGH); // <---- HERE is setting RPi pin 24 to high => RPy starts shutdown (code in
		// Wait for the Pi to shutdown 
		timeStart = millis();
		testTime = 0;
		handShake = digitalRead(PI_IS_RUNNING); 
		while((handShake > 0) && (testTime < kFAILSAFETIME_MS)){ // <----- HERE checking RPi pin 25 to go low 
			handShake = digitalRead(PI_IS_RUNNING);  
			timeNow = millis();
			testTime = timeNow - timeStart;
		// Switch off the Pi
		delay(5000); // delay to make sure the Pi has finished shutting down
		SleepyPiClass::enablePiPower(false); // <----- HERE electrical power to RPi is removed 
If You don't want to use Python RPi GPIO, or want an alternative, for RPi pins control, than You can take a look at WiringPi

Posts: 9
Joined: Tue Jan 30, 2018 4:16 pm

Re: Sleepy Pi 2 Communicating with the Pi3

Mon Feb 26, 2018 3:00 pm

Thanks MJAB! For the past while I've been trying to monitor an additional pin but I can't seem to find the mapping of gpio pins to Arduino pins as I am also monitoring the standard 24 and 25.
Do you know where I can find this?

Return to “HATs and other add-ons”