Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Solved: RaspDAC OLED & Power management w/Moode 6.7.1
#11
(01-04-2021, 08:37 AM)JuanJB Wrote: In fact I'm exploring this line just now. The code is simple so it should be easy to translate it using Phyton based GPIO library.

Hi,
I have flashed a new Moode_R6.7_RaspDacMini image downloaded from https://mega.nz/file/gBpBCapQ#yagnsjvpH0...bhXZLuEUio

As python3 is installed here, I have “translated” the power management scripts into python. My setup is as follows:
 
1.- dtoverlays for GPIO17 and GPIO22 included in /boot/config.txt
2.- softshutdown.py launched from /var/local/www/comandw/restart.sh on “poweroff”
3.- softreboot.py launched from /var/local/www/comandw/restart.sh on “restart”. This was not used previously but it allows to make SPC-II board to react (via GPIO4) also to a restart from moode UI.
4.- sds.py is finally not used (and not tested also). I think that it is not needed.
 
Everything works well with this setup, I think. I have e-mail also to Audiophonics. They told me they are looking for a solution, hopefully in the near future. Maybe mine could help.

Please see also https://github.com/audiophonics/Raspberr...management

Here you have the scripts:

sds.py (not used in my setup, as I said before)
Code:
#!/usr/bin/python3
import os
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.output(4,GPIO.LOW)
GPIO.setup(17, GPIO.IN)
GPIO.setup(22, GPIO.OUT)
GPIO.output(22,GPIO.LOW)

while True:
 if GPIO.input(17) == 1:
       print ("ShutDown order received, RaspBerry pi will now enter in standby mode...")
       os.system ('sudo shutdown -h -P now')
       break
 time.sleep(0.25)

softshutdown.py
Code:
#!/usr/bin/python3
# Shutdown detection script
# Script to set GPIO 4 High for 1sec

import os
import time
import RPi.GPIO as GPIO

print ("Setting pin GPIO4 High")
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.output(4,GPIO.HIGH)
time.sleep(1)

print ("Setting pin GPIO4 Low")
GPIO.output(4,GPIO.LOW)

print ("RaspberryPi shutdown")
os.system ('sudo shutdown -h -P now')

softreboot.py
Code:
#!/usr/bin/python3
# Reboot detection script
# Script to set GPIO 4 High and Reboot
# Reboot blink will stop after Boot OK return

import os
import time
import RPi.GPIO as GPIO

print ("Setting pin GPIO4 High")
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.output(4,GPIO.HIGH)

print ("RaspberryPi Reboot")
os.system ('sudo reboot')

Best regards
Juan
Reply
#12
Hi Juan JB,

The only interest of not using the following overlay for GPIO pin 22 (but keeping one for GPIO pin 17 to handle the power button)

Code:
dtoverlay=gpio-poweroff,gpiopin=22,active_low


and keep part of sds.sh :


Code:
#!/bin/bash
# Moode for Audiophonics SPC II power management board
# Initialisation of GPIO outputs 4 (SofthutDown) and 22 (BootOK)
# Script is lauched by /etc/rc.local after moode is ready
# Power LED stops slowly blinking an lights steadily
# modded by Ph Deysine - 14/11/2020

PATH=/usr/bin:/usr/local/bin

echo "Audiophonics initialisation script starting..."
echo "Asserting pins : "
echo "SoftShutDown  : GPIO04=out, Low"
echo "BootOK        : GPIO22=out, High"

echo "Setting SoftShutDown output Low"
gpio -g mode 04 out
gpio -g write 04 0

echo "Setting BootOK output High"
gpio -g mode 22 out
gpio -g write 22 1

exit 0

is to have BootOK active (= power led to stop blinking) when Moode is ready and not just when boot is finished. 

Thank you for your Python version I will use when moving forward to Moode 7(.1 !) since WiringPi is deprecated (I still run Moode 6.7.1 on a Pi 3B+)

Regards.

Philippe
Reply
#13
Hi Philippe,
Thanks for your suggestion.
I have tested your sds (translated to python, removing the overlay for GPIO22) and it works but I have a remark: the button led stops blinking anyway before Moode is ready. About 10-15 seconds before. It is possible to let both, Moode and led, to arrive at the same time to finish line by setting a sleep time in sds.py before putting GPIO22 to 1. I know this is not, let's say, an elegant solution, but it works. It would be perfect to have a catchable signal indicating that Moode is ready. The script could then wait until this signal arrives and then put GPIO22=1.

You're welcome. Feel free to use/modify/improve the scripts.

Regards
Juan
Reply
#14
(01-05-2021, 08:12 PM)JuanJB Wrote: ...
It would be perfect to have a catchable signal indicating that Moode is ready. The script could then wait until this signal arrives and then put GPIO22=1.
...

Check out Tim's post from yesterday.

Regards,
Kent
Reply
#15
(01-05-2021, 08:24 PM)TheOldPresbyope Wrote:
(01-05-2021, 08:12 PM)JuanJB Wrote: ...
It would be perfect to have a catchable signal indicating that Moode is ready. The script could then wait until this signal arrives and then put GPIO22=1.
...

Check out Tim's post from yesterday.

Regards,
Kent

Thank you @TheOldPresbyope.

I'm not very skilled in python so it took to me a little to translate the command from @Tim Curtis (thank you too) into python statements. But finally I did. 
Now the button finishs blinking only when MoOde is really ready. 

The script is launched from /etc/rc.local by adding, before exit 0, at the end of rc.local script:

python3 /home/pi/sds.py &

This is my new sds.py script

Code:
#!/usr/bin/python3
# Moode for Audiophonics SPC II power management board
# Initialisation of GPIO outputs 4 (SofthutDown) and 22 (BootOK)
# Script is lauched by /etc/rc.local
# Power LED stops slowly blinking and lights steadily after MoOde is ready

import sys
import os
import time
import RPi.GPIO as GPIO
import subprocess

print ("Audiophonics initialisation script starting...")
print ("Asserting pins : ")
print ("SoftShutDown  : GPIO04=out, Low")
print ("BootOK        : GPIO22=out, High")

GPIO.setmode(GPIO.BCM)

print ("Setting SoftShutDown output Low")
GPIO.setup(4, GPIO.OUT)
GPIO.output(4,GPIO.LOW)

print ("Waiting for MoOde Availability")
print ("Condition is checked out every 5 seconds")
option= "-q"
sqlSelect="select value from cfg_system where param='wrkready'"

while True:
 result=subprocess.check_output(['/usr/local/bin/moodeutl',option,sqlSelect])
 if result == b'1\n':  #python3 binary value usage
 #if result[0] == "1": #python2 string value usage
   print ("Setting BootOK output High")
   GPIO.setup(22, GPIO.OUT)
   GPIO.output(22,GPIO.HIGH)
   break
 time.sleep(5)
sys.exit()

Regards,
Juan
Reply
#16
I made an updated all-in-on script that avoid to deal with 3 files. I also included the SQL verification before initializing Boot ok.
Thanks you all for supporting our product.

https://github.com/audiophonics/Raspberr...c_moode.py
Reply
#17
(01-21-2021, 04:55 PM)audiophonics Wrote: I made an updated all-in-on script that avoid to deal with 3 files. I also included the SQL verification before initializing Boot ok.
Thanks you all for supporting our product.

https://github.com/audiophonics/Raspberr...c_moode.py

Nice script. Thank you @audiophonics
Reply


Forum Jump: