LowPowerLab Forum

Hardware support => ATXRaspi => Topic started by: Elluminatus on May 25, 2018, 12:25:18 PM

Title: Have Problem to run ATXRaspi with an BananaPi M3
Post by: Elluminatus on May 25, 2018, 12:25:18 PM
Hi there,

I have purchased a couple of ATXRaspi Version 2.8 to put them on my SBC (Raspberry Pi 3+ ans Banana Pi M3)

I started with a test to check if the boards are failure free:

Quote
To verify you have a good ATXRaspi please completely disconnect it from your Pi. You can test it by itself. Just turn it ON using the button as normally. At that point the output side will have 5V. Simulate a Pi boot OK by connecting the BOOTOK to the 5V output (with a jumper wire) - the LED next to BOOTOK will turn ON. Now hold the button for 3 seconds. That should assert the SHUTDOWN signal and turn the LED next to it, also the LED connected (if any)  to your button will start pulsing. Give it a few seconds and then disconnect the BOOTOK signal from 5V. At that point the BOOTOK LED turns off and the pulsing will be faster on the button LED. After another few seconds power will be cut off.

Result is they did exactly what written. 100% working. So soldering where okay too. Reset Button, Latch Button (yes I solderd the bridge on the ATXRaspi) and LED are working fine.

I have a small problem I have to use GPIO 7 and 8 for other things so i tried to change it to 6 and 12 like written here in the forum.
Quote
https://lowpowerlab.com/forum/atxraspi/how-to-use-other-gpio-pins/

So let me give you infos about the Banana Pi M3 running with an ubuntu 16.04 LTS. I installed gpio für banana pi on it. I can use the gpio readall command to see the gpio status. gpio -v shows me version 2.44. I installed the script in this order:

Code: [Select]
sudo wget https://raw.githubusercontent.com/LowPowerLab/ATX-Raspi/master/shutdownchecksetup.sh
sudo bash shutdownchecksetup.sh
sudo rm shutdownchecksetup.sh
sudo reboot

these is my /etc/shutdownirq.py (chmod 755)
Code: [Select]
#!/usr/bin/python
# ATXRaspi/MightyHat interrupt based shutdown/reboot script
# Script by Tony Pottier, Felix Rusu
import RPi.GPIO as GPIO
import os
import sys
import time

GPIO.setmode(GPIO.BCM)

pulseStart = 0.0
REBOOTPULSEMINIMUM = 0.2 #reboot pulse signal should be at least this long (seconds)
REBOOTPULSEMAXIMUM = 1.0 #reboot pulse signal should be at most this long (seconds)
SHUTDOWN = 6 #GPIO used for shutdown signal
BOOT = 12 #GPIO used for boot signal

# Set up GPIO 12 and write that the PI has booted up
GPIO.setup(BOOT, GPIO.OUT, initial=GPIO.HIGH)

# Set up GPIO 6  as interrupt for the shutdown signal to go HIGH
GPIO.setup(SHUTDOWN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

print "\n=========================================================================================="
print "   ATXRaspi shutdown IRQ script started: asserted pins (",SHUTDOWN, "=input,LOW; ",BOOT,"=output,HIGH)"
print "   Waiting for GPIO", SHUTDOWN, "to become HIGH (short HIGH pulse=REBOOT, long HIGH=SHUTDOWN)..."
print "=========================================================================================="
try:
while True:
GPIO.wait_for_edge(SHUTDOWN, GPIO.RISING)
shutdownSignal = GPIO.input(SHUTDOWN)
pulseStart = time.time() #register time at which the button was pressed
while shutdownSignal:
time.sleep(0.2)
if(time.time() - pulseStart >= REBOOTPULSEMAXIMUM):
print "\n====================================================================================="
print "            SHUTDOWN request from GPIO", SHUTDOWN, ", halting Rpi ..."
print "====================================================================================="
os.system("sudo poweroff")
sys.exit()
shutdownSignal = GPIO.input(SHUTDOWN)
if time.time() - pulseStart >= REBOOTPULSEMINIMUM:
print "\n====================================================================================="
print "            REBOOT request from GPIO", SHUTDOWN, ", recycling Rpi ..."
print "====================================================================================="
os.system("sudo reboot")
sys.exit()
if GPIO.input(SHUTDOWN): #before looping we must make sure the shutdown signal went low
GPIO.wait_for_edge(SHUTDOWN, GPIO.FALLING)
except:
pass
finally:
GPIO.cleanup()

and this is the /etc/shutdowncheck.sh (chmod 755)
Code: [Select]
# ATXRaspi/MightyHat interrupt based shutdown/reboot script
# Script by Felix Rusu

#This is GPIO 7 (pin 26 on the pinout diagram).
#This is an input from ATXRaspi to the Pi.
#When button is held for ~3 seconds, this pin will become HIGH signalling to this script to poweroff the Pi.
SHUTDOWN=6
REBOOTPULSEMINIMUM=200      #reboot pulse signal should be at least this long
REBOOTPULSEMAXIMUM=600      #reboot pulse signal should be at most this long
echo "$SHUTDOWN" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$SHUTDOWN/direction
#Added reboot feature (with ATXRaspi R2.6 (or ATXRaspi 2.5 with blue dot on chip)
#Hold ATXRaspi button for at least 500ms but no more than 2000ms and a reboot HIGH pulse of 500ms length will be issued
#This is GPIO 8 (pin 24 on the pinout diagram).
#This is an output from Pi to ATXRaspi and signals that the Pi has booted.
#This pin is asserted HIGH as soon as this script runs (by writing "1" to /sys/class/gpio/gpio8/value)
BOOT=12
echo "$BOOT" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$BOOT/direction
echo "1" > /sys/class/gpio/gpio$BOOT/value

echo -e "\n=========================================================================================="
echo "   ATXRaspi shutdown POLLING script started: asserted pins ($SHUTDOWN=input,LOW; $BOOT=output,HIGH)"
echo "   Waiting for GPIO$SHUTDOWN to become HIGH (short HIGH pulse=REBOOT, long HIGH=SHUTDOWN)..."
echo "=========================================================================================="

#This loop continuously checks if the shutdown button was pressed on ATXRaspi (GPIO7 to become HIGH), and issues a shutdown when that happens.
#It sleeps as long as that has not happened.
while [ 1 ]; do
  shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
  if [ $shutdownSignal = 0 ]; then
    /bin/sleep 0.2
  else 
    pulseStart=$(date +%s%N | cut -b1-13) # mark the time when Shutoff signal went HIGH (milliseconds since epoch)
    while [ $shutdownSignal = 1 ]; do
      /bin/sleep 0.02
      if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMAXIMUM ]; then
        echo -e "\n====================================================================================="
        echo "            SHUTDOWN request from GPIO", SHUTDOWN, ", halting Rpi ..."
        echo "====================================================================================="
        sudo poweroff
        exit
      fi
      shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
    done
    #pulse went LOW, check if it was long enough, and trigger reboot
    if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMINIMUM ]; then
      echo -e "\n====================================================================================="
      echo "            REBOOT request from GPIO", SHUTDOWN, ", recycling Rpi ..."
      echo "====================================================================================="
      sudo reboot
      exit
    fi
  fi
done

Because im not a pro in Linux, maybe someone can help me finding a solution for this questions:

How can I see if the programm is running correctly (which command?) I see the ATXRaspi shutdown script started... in the start sequence in rc.local (6 = input, LOW and 12= output, HIGH - waiting for 6 to become HIGH)
But when I try to check if there is an folder with the gpio number under /sys/class/gpio/ i can see no further folders with the special gpio12 (for example) folder.

When I try to start sudo bash /etc/shutdowncheck.sh by hand i got the follwing output:

Quote
/etc/shutdowncheck.sh: line 32: [: =: unary operator expected
/etc/shutdowncheck.sh: line 36: [: =: unary operator expected
cat: /sys/class/gpio/gpio6/value: No such file or directory
/etc/shutdowncheck.sh: line 32: [: =: unary operator expected
/etc/shutdowncheck.sh: line 36: [: =: unary operator expected
cat: /sys/class/gpio/gpio6/value: No such file or directory

So thats all for the moment.

Can you help me please to get this cool hardware running?

Thank you in advance!

Elluminatus


Title: Re: Have Problem to run ATXRaspi with an BananaPi M3
Post by: Elluminatus on June 05, 2018, 11:06:47 AM
Hi can no one help me?
Seems like it is not possible to make any entries like

echo "$BOOT" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$BOOT/direction
echo "1" > /sys/class/gpio/gpio$BOOT/value

for example echo 6 > /sys/class/gpio/export
on he command line returns me

bash: echo: write error: Invalid argument

Please help me with any hint

Thanks in advance...

Greetings Elluminatus
Title: Re: Have Problem to run ATXRaspi with an BananaPi M3
Post by: Felix on June 05, 2018, 02:15:36 PM
Unfortunately I am not familiar with Banana Pi and its distributions.
I can only support RaspberryPi which is the platform this board was intended for.
The script can of course be adapted to other platforms as the board can drive many amps of current without problems. But you will have to find your way on your custom platform.

On your Banana Pi you may be missing some libraries or functionality used by the script. You may need to rewrite the script to toggle/read GPIO using different calls than those used on Raspbian.