X708-script

From Geekworm Wiki
Revision as of 14:25, 25 March 2024 by Harry (talk | contribs) (→‎Prepair software shutdown script)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

This is script installation tutorial for X708 shield, it will replace X708 Software installation tutorial, although X708 Software installation tutorial is still available, but we strongly recommend that you use this script tutorial, which simplifies the installation process and reduces dependencies on third-party python libraries.

Now we think you have successfully flashed the OS Image into Micro SD and and power on the device, and you have also completed the operations such as creating new user required in some OS. You need to perform the following operations in Terminal.

[NOTE]:

1. The script now supports the Raspberry Pi OS BOOKWORM version. You just need to uninstall the original script and reinstall it. Please refer to the following:

OPen ternimal window, then run the following command:

mv x708-script x708-script-old
git clone https://github.com/geekworm-com/x708-script
cd x708-script
chmod +x *.sh
./uninstall.sh

Then just follow the installation process below.

OS that has been tested

  • Raspberry Pi OS
  • DietPi
  • Manjaro
  • Ubuntu
  • myNode
  • Umbrel
  • Volumio
  • RetroPie
  • Twister

Install

Please follow the steps below:

Enable I2C

Reter to How to enable I2C

NOTE: sample/x708-v2.x-bat.py or sample/x708-v1.x-bat will run with error if you don't enable I2C.

Check & review I2C address:

pi@raspberrypi:~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- 36 -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --   

Explaination:

#36 - the address of the battery fuel gauging chip

Install gpiod package

sudo apt install -y gpiod

Clone the script

git clone https://github.com/geekworm-com/x708-script

cd x708-script
chmod +x *.sh

PS: For some OS such as 'Raspberry Pi OS Lite', the git tool is not installed by default, if you get an error like error: -bash: git: command not found, please run the following command to install the git tool.

sudo apt install -y git

Create the x708-pwr service

x708-pwr service will be responsible for power management and hardware safe shutdown.

sudo cp -f ./xPWR.sh                /usr/local/bin/
sudo cp -f x708-pwr.service         /lib/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable x708-pwr
sudo systemctl start x708-pwr

Now, if you press and hold the onboard switch for 3 seconds, then the blue LED will flash slowly and the shutdown is going then all LEDs will be off until the device is completely powered off.

Prepair software shutdown script

sudo cp -f ./xSoft.sh             /usr/local/bin/

Then create a alias x708off command to execute the software shutdown

echo "alias x708off='sudo /usr/local/bin/xSoft.sh 0 13'" >>   ~/.bashrc
source ~/.bashrc

PS:

Then you can run x708off to execute software shutdown as follows

x708off

Test safe shutdown

Software safe shutdown command:

x708off

DON'T run the 'shutdown' linux command to shut down, otherwise the power of x708 shield will not be shut down.

Hardware safe shutdown operation:

You can verify the safety switch through the onboard switch, press and hold the switch for 3 seconds, then the blue LED will flash slowly and the shutdown is going then all LEDs will be off until the device is completely powered off.

  • press on-board button switch 1-2 seconds to reboot
  • press button switch 3 seconds to safe shutdown,
  • press 7-8 seconds to force shutdown.

Sample Files

The example programs are only suitable for advanced players, and you can construct your own usage scenarios according to the example programs.

Each example program demonstrates a different function:

x708-bat.py: Script to read battery power and voltage;

cd ~x708-script
sudo python3 sample/bat.py

x708-pld.py: Script to AC Power supply loss dection

cd ~x708-script
sudo python3 sample/pld.py

x708-plsd.py: Script to AC Power supply loss dection then safe shutdown

cd ~x708-script
sudo python3 sample/plsd.py

fan.py: Provides a method that can switch the fan speed.

sudo python3 sample/fan.py

Then the fan will run with high speed.

It should be noted that the x708 DOES NOT use a PWM fan, it only supports two speed modes (low speed and high speed). In the fan.py file, the speed mode of the fan is controlled by reading the temperature of the CPU in real time. You need to read the fan.py code to understand more logic.

You can control the fan running at high speed or low speed via modify the CPU temperature threshold in fan.py script file (yellow highlight line)

#!/usr/bin/env python3

import subprocess
import time

from gpiozero import OutputDevice


ON_THRESHOLD = 55  # (degrees Celsius) Fan running at high speed at this temperature.
OFF_THRESHOLD = 50  # (degress Celsius) Fan running at low speed  at this temperature.
SLEEP_INTERVAL = 5  # (seconds) How often we check the core temperature.
GPIO_PIN = 16  # Which GPIO pin you're using to control the fan. DON'T change it!


def get_temp():
    """Get the core temperature.
    Run a shell script to get the core temp and parse the output.

[PS]: If you can't understand fan.py, please ignore this step. Because the X708 fan will run at low speed by default, this cooling capacity is sufficient.

1. Al sample python files maybe depends on the third-party python library `Rpi.GPIO`. In the official Raspberry Pi OS and most third-party OS, this library is installed by default. If you run this file and get some errors, try to run the following command to install the Rpi.GPIOy library.

sudo apt-get install -y python3-smbus python3-rpi.gpio

Or you can refer to How to Install RPi.GPIO Python Library

2. The sample file based on the version number is just because different versions of x708 shield use different GPIOs, they are basically the same. You can use a file comparison tool to view it, if you get it wrong, most likely you are using the wrong version of the sample file. You can refer to X708-Hardware to check the PIN occupancy of x708 shield.

3. The sample program is only to demonstrate how to use the advanced functions of the shield, we do not provide the development function of the sample program.

Support

Email: support@geekworm.com

FAQ

Q: How to login volumio via SSH?

1. Enable SSH:

Visit http://volumio.local/dev/, then click ENABLE SSH button

2. URL connection is IP address, and the default user name is volumio, default password is volumio

Q: How to login to Umbrel via SSH? A: ssh umbrel@umbrel.local (or ssh umbrel@). the default user name is umbrel, default password is moneyprintergobrrr
Q: How to login to myNode via SSH? A: URL connection is IP address, and the default user name is admin, default password is bolt
Q: How to login to DietPi via SSH? A: URL connection is IP address, and the default user name is root, default password is dietpi
Q: Is LibreELEC supported? A: TODO

Other resource

Return to X708 or X708-Hardware


Add your comment
Geekworm Wiki welcomes all comments. If you do not want to be anonymous, register or log in. It is free.


Anonymous user #1

9 days ago
Score 0++
Is there any way to add a panel to the raspberry pi OS taskbar with the battery percentage?

Lisa

9 days ago
Score 0++
Sorry, we haven't tested it.