Page 1 of 1

Sleepy Pi 2 Communicating with the Pi3

Posted: Tue Jan 30, 2018 4:25 pm
by peggyopal
Hello!

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?

Thanks!

Re: Sleepy Pi 2 Communicating with the Pi3

Posted: Fri Feb 16, 2018 4:19 pm
by MJAB
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 https://github.com/SpellFoundry/Sleepy-Pi-Setup is installed, and configured to run at boot, a Python script "shutdowncheck.py".
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.

https://github.com/SpellFoundry/Sleepy- ... wncheck.py

Code: Select all

#
...
GPIO.setmode(GPIO.BCM)
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")
		break
time.sleep(0.5)
...
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 https://github.com/SpellFoundry/SleepyP ... 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 shutdowncheck.py)
		
		// 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);  
			delay(50);
			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 
             digitalWrite(CMD_PI_TO_SHDWN_PIN,LOW); 
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 http://wiringpi.com/

Re: Sleepy Pi 2 Communicating with the Pi3

Posted: Mon Feb 26, 2018 3:00 pm
by peggyopal
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?