bigtreetech / bigtreetech/SKSM

Instructions for Orange Pi 3 LTS & others(?)

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
15
Forks
1
PR merge metrics
No merged PRs in 30d

Description

I ended up writing a script that makes this work on Orange Pi 3 LTS. 
If you're trying to make this work on a different pi, this may also work for you, but adjust accordingly.
I wasn't able to get the SKSM working using the listed methods in the PDF manual, but this script does a good job from what I've seen during my testing.

I used PL8 on the orange pi for PB1 on the SKSM, and PD21 for PB0.
Currently PB2 is unused.

Other pins probably work, but I'm keeping things simple for the time being.
of course, wire GND to GND, 5v to 5v. Any GND pin will work, and either of the two 5v pins will work.
I still haven't got the reset working, it will take more time, as the orange pi 3 LTS likely needs additional work to the power button's pins to achieve the reset functionality (PB2).
For now, this script and the pinout described are adequate for at least the main function of the SKSM.
I hope this script can help someone. Maybe this can be made into a PDF on the repository, if it's deemed useful enough.
Some notes: I'm running armbian (MainSailOS). This will likely work with other operating systems, but possibly requiring adaptation.

This does require the orange pi version of wiringOP as a prerequisite, if you're not using an orange pi, look for the wiringOP version for your device. If your device doesn't have a specific wiringOP version, it may just use the generic install.
https://github.com/orangepi-xunlong/wiringOP

SSH into the pi.

I put this in my /home/pi directory to keep things simple:
sudo nano /home/pi/gpio_shutdown.sh
After saving the file, be sure to run "sudo chmod +x gpio_shutdown.sh" to make the script executable.
contents:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/bash

GPIO_PIN=16
GPIO_PIN2=13
gpio mode $GPIO_PIN2 out
gpio write $GPIO_PIN2 1
gpio mode $GPIO_PIN in

#Uncomment below to enable logging
#exec >> /home/pi/shutdown_log.txt 2>&1
echo "Starting up"
#Monitor the pin state
while true; do
    # Read the pin state
    PIN_STATE=$(gpio read $GPIO_PIN)
    # Check if the pin is low (0)
    if [ "$PIN_STATE" -eq "0" ]; then
        echo "Initiating shutdown..."
        sudo shutdown -h now
        exit 0
    fi
    sleep 1
done

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To make the script run at startup, we create this service:
sudo nano /etc/systemd/system/gpio_shutdown.service
Then we add the following:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Unit]
Description=GPIO Shutdown Script
After=network.target

[Service]
ExecStart=/home/pi/gpio_shutdown.sh
User=root
Group=root
Type=simple
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After the above service is created and saved, we run 4 lines.  In order, this is what they do. 
1. reload daemon to ensure the service is detected by it.
2. start the service.
3. enable the service at runtime.
4. check the status of the service to ensure it's running.

sudo systemctl daemon-reload
sudo systemctl start gpio_shutdown.service
sudo systemctl enable gpio_shutdown.service
sudo systemctl status gpio_shutdown.service

If the user uncomments the line:
#exec >> /home/pi/shutdown_log.txt 2>&1
then, echoes will save to "shutdown_log.txt", which on power loss will write the message "Initiating shutdown..." to the file.
If the user sees this message, that means that the SKSM has successfully detected the power loss and initiated the shutdown as a result. Note that the echoes inside the script do not appear on the terminal, they only appear in the shutdown_log.txt file.
If the user does not remove the # from the line #exec >> /home/pi/shutdown_log.txt 2>&1, all echoes will be ignored.
Please be sure to enable logging at the start, initiate a power loss, and confirm the script is working. After that, disable logging.

That's it for now. I really hope this helps someone.
Just a further note, the methods above likely work for other devices as well, and come with added flexibility as the script can be easily modified by the user for additional functionality.

Additional notes:

Please do not attempt to run the script at runtime by using /etc/rc.local, as this will result in multiple instances of the script running.
To confirm that only one instance of the script is running, please use:
pgrep -f "gpio_shutdown.sh". It should have only one result, and look something like "885".

If anyone has additional information about the orange pi 3 lts power button (SW4), please let me know, maybe together we can implement a reset solution.
Any suggestions for improvement on the above instructions are appreciated.

![sksm](https://github.com/bigtreetech/SKSM/assets/45184363/14460043-6a89-4f04-b118-67a2d8ed87d6)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the issue's gpio_shutdown.sh script and gpio_shutdown.service unit examples, then inspect the repository for an existing documentation location. Determine how this Orange Pi setup should be incorporated and verify the wiring, startup, logging, and single-process instructions. Done means the setup is documented in the repository with its limitations clearly stated.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, shell
Domain
documentation, embedded-iot
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.