To use ATXRaspi with a NanoPi Neo2:-
- Wire the NanoPi Neo2 to the ATXRaspi
- Install OS onto a micro-SD card
- Tweak the card's OS and filesystem
- Power up the ATXRaspi and run some tests
WIRINGIf you are using the ATXRaspi in conjunction with a PowerBoost 1000C, wire pin #7 of the Neo2 to the PB1000C's LBO pin.
Wire pin 13 of the Neo2 to the BOOTOK pin of the ATXRaspi.
Wire pin 10 of the Neo2 to the SHUTDOWN pin of the ATXRaspi.
Wire pin 11 of the Neo2 to the SoftBtn pin of the ATXRaspi.
For extra points, create a factory reset button by wiring pins 16 and 6 of the Neo2 to a momentary switch (or whatever it is called).
Don't forget to wire a momentary switch to the ATXRaspi's on/off button pins.
Wire an LED (preferably pins 3 and 4) to the ATXRaspi's status LED pins. The LED's pins look like this: short (1), long (2), longest (3), short (4).
Consider wiring pins 1 and 2 of the LED to pins 23 and 22 of the Neo2 respectively.
SOFTWAREDownload FriendlyCore Linux OS from
https://drive.google.com/open?id=1bS2_AgH0pOjuGxXjqFxQi6xdkUZEBjVH. Copy it to a micro-SD card ('dd' is your friend). Mount it using another Linux PC, thusly (assuming the micro-SD card was detected at /dev/sda; YMMV):-
# mkdir /tmp/a
# mount /dev/sda2 /tmp/a
# mount /dev/sda1 /tmp/a/boot
# chroot /tmp/a
Within the 'chroot' of /tmp/a, run these commands:-
# systemctl enable ssh
# apt-get -y remove hostapd
# apt -y update
# apt-get -y dist-upgrade
# apt -y install dosfstools usbutils pciutils util-linux parted apt-utils python-pip python3-pip busybox-static avahi-daemon
# systemctl enable avahi-daemon
# pip install wheel
# pip3 install wheel
# apt -y remove plymouth libreoffice* wolfram* || true
# apt -y install git-core python-dev python-smbus python-serial cmake busybox-static
# sed -i s/exit\ 0// /etc/rc.local
# echo -en "touch /tmp/.yesibootedok\nexit 0\n" >> /etc/rc.local
# echo -en "tmpfs /tmp tmpfs defaults 0 0\n" >> /etc/fstab
# cd /root
# git clone https://github.com/friendlyarm/BakeBit.git
# cd BakeBit/Script
# bash install.sh
# cd /root/WiringNP
# ./build
# cd /root
# mv old older || mkdir -p old
# mv RPi*GPIO* old/
# git clone https://github.com/chainsx/RPi.GPIO.NP.git
# cd RPi.GPIO.NP
# rm -Rf build; python2 setup.py install; sudo python2 setup.py install
# rm -Rf build; python3 setup.py install; sudo python3 setup.py install
Next, save this file to /usr/local/bin/shutdownirq.py:-
#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
import sys
import os
PB1000C_LBO = 7
BOOTOK = 13
POWEROFF = 11
ATXRASPI_SOFTWARESHUTDOWN = 10
FACTORYRESET = 16
BLUE22 = 22
YELLOW23 = 23
WHITE, GREEN, PURPLE, RED = ('white', 'green', 'purple', 'red')
def setup_gpio():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BLUE22, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(YELLOW23, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(BOOTOK, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(ATXRASPI_SOFTWARESHUTDOWN, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(POWEROFF, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(PB1000C_LBO, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(FACTORYRESET, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def show_led_color(s):
dct = {'white': (0,0), 'green':(0,1), 'purple':(1,0), 'red':(1,1)}
a, b = dct[s]
GPIO.output(BLUE22, a)
GPIO.output(YELLOW23, b)
############################## MAIN ########################
print("shutdownirq.py is running. Yay.")
setup_gpio()
GPIO.output(BOOTOK, 1)
GPIO.output(ATXRASPI_SOFTWARESHUTDOWN, 0)
lbo_is_irrelevant = True if GPIO.input(PB1000C_LBO) == 0 else False
os.system('echo "%s" >> /out.out' % ('Waiting for POWEROFF (a.k.a. Shutdown) signal from #%d\n' % POWEROFF))
while not os.path.exists("/tmp/.yesibootedok"):
show_led_color(GREEN)
time.sleep(.2)
show_led_color(PURPLE)
time.sleep(.2)
show_led_color(GREEN)
print("shutdownirq.py is waiting for you to push the Shutdown button on the ATXRaspi thingy. Yay.")
while GPIO.input(POWEROFF) == 0 and GPIO.input(ATXRASPI_SOFTWARESHUTDOWN) == 0 and (lbo_is_irrelevant or GPIO.input(PB1000C_LBO) != 0):
time.sleep(.2)
if GPIO.input(FACTORYRESET) == 1:
os.system('/usr/local/bin/factoryreset.py')
print("shutdownirq.py notes that you have pushed the Shutdown button. Yay.")
os.system('''echo "$(date) %s" >> /out.out''' % ('POWER OFF' if GPIO.input(POWEROFF) != 0 else 'S/W SHUTDOWN' if GPIO.input(ATXRASPI_SOFTWARESHUTDOWN) != 0 else 'LOW BATTERY WARNING'))
show_led_color(PURPLE)
os.system('python3 /usr/local/bin/softshutdown.py')
Save this file to /usr/local/bin/softshutdown.py:-
#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
import sys
import os
PB1000C_LBO = 7
BOOTOK = 13
POWEROFF = 10
ATXRASPI_SOFTWARESHUTDOWN = 11
FACTORYRESET = 16
BLUE22 = 22
YELLOW23 = 23
WHITE, GREEN, PURPLE, RED = ('white', 'green', 'purple', 'red')
def setup_gpio():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BLUE22, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(YELLOW23, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(BOOTOK, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(ATXRASPI_SOFTWARESHUTDOWN, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(POWEROFF, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(PB1000C_LBO, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(FACTORYRESET, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def show_led_color(s):
dct = {'white': (0,0), 'green':(0,1), 'purple':(1,0), 'red':(1,1)}
a, b = dct[s]
GPIO.output(BLUE22, a)
GPIO.output(YELLOW23, b)
############################## MAIN ########################
os.system('''echo "$(date) softshutdown.py called" >> /out.out''')
setup_gpio()
GPIO.output(ATXRASPI_SOFTWARESHUTDOWN, 1)
GPIO.output(BOOTOK, 0)
show_led_color(RED)
os.system('''echo "$(date) softshutdown.py is calling shutdown -h" >> /out.out''')
os.system('sudo shutdown -h now')
Save this file to /usr/local/bin/daemon_shutdownirq.sh:-
#!/bin/bash
doit() {
while true ; do
echo "$(date) Starting shutdownirq.py" >> /out.out
/usr/local/bin/shutdownirq.py >> /out.out 2>> /out.out
echo "$(date) Restarting shutdownirq.py ..." >> /out.out
sleep 30
done
}
doit &
Save this file to /usr/local/bin/factoryreset.py:-
#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
import sys
import os
PB1000C_LBO = 7
BOOTOK = 13
POWEROFF = 10
ATXRASPI_SOFTWARESHUTDOWN = 11
FACTORYRESET = 16
BLUE22 = 22
YELLOW23 = 23
WHITE, GREEN, PURPLE, RED = ('white', 'green', 'purple', 'red')
def setup_gpio():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BLUE22, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(YELLOW23, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(BOOTOK, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(ATXRASPI_SOFTWARESHUTDOWN, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(POWEROFF, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(PB1000C_LBO, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(FACTORYRESET, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def show_led_color(s):
dct = {'white': (0,0), 'green':(0,1), 'purple':(1,0), 'red':(1,1)}
a, b = dct[s]
GPIO.output(BLUE22, a)
GPIO.output(YELLOW23, b)
############################## MAIN ########################
os.system('''echo "$(date) factoryreset.py called" >> /out.out''')
setup_gpio()
os.system('''echo "$(date) QQQ INFERNAL PORPOISES" >> /out.out''')
Save this file to /etc/systemd/system/sayhello.service:-
[Unit]
Description=Show spinny thingy while loading
DefaultDependencies=no
[Service]
Type=forking
ExecStart=/usr/local/bin/daemon_shutdownirq.sh
#WorkingDirectory=/root/NanoHatOLED/BakeBit/Software/Python
#ExecStart=/root/NanoHatOLED/BakeBit/Software/Python/bakebit_nanohat_oled.py
#ExecStop=/usr/local/bin/softshutdown.py
[Install]
WantedBy=sysinit.target
Then run these commands:-
# systemctl enable sayhello
# chmod +x /usr/local/bin/*
# passwd # <== set your root password
# passwd -i pi # <== set your user password
# exit
# mount /tmp/a/boot /tmp/a
Remove the micro-SD card. Insert it into the Neo2.
TESTINGPower up the ATXRaspi. Log into the Neo2 via ssh. Check /out.out (yes, the log file is saved to the root directory; that's easy enough to fix); use 'tail -f /out.out' to watch it. Then, push the on/off button briefly. Watch to see if everything shuts down properly.
KNOWN PROBLEMS- Soldering onto the Neo2's GPIO pins isn't easy and it isn't fun. I've had good results with single-core 24awg wire.
- The FriendlyCore NPI/RPIO/etc. libraries can be finicky.
- To work around a flaw in God-knows-what, I've made the script treat any short-push (of the button) shutdowns as reboots. For some reason, those reboots become shutdowns. This means (i) it all works out in the end and (ii) you can't do reboots.
And that's it.