Open main menu

Changes

X728-script

10,798 bytes added, 13 September
{{GD Template Impl}}

==Overview==
This is script installation tutorial for [[X728]] shield, it will replace [[X728-Software | X728 Software installation tutorial]], although [[X728-Software | X728 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.

<!--
The core shell script of [[X728-script]] comes from from [https://github.com/pimlie/geekworm-x-c1 pimlie/geekworm-x-c1], pimlie implements the pwm fan shell script, which does not depend on third-party python libraries at all. Thanks to pimlie.
-->
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 <code>Terminal</code>.


'''[Update]:'''

1. Use '''gpiod''' instead of obsolete interface

2. 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:
<pre>
mv x728-script x728-script-old
git clone https://github.com/geekworm-com/x728-script
cd x728-script
chmod +x *.sh
./uninstall.sh
</pre>
Then just follow the installation process below.

3. The current installation script also supports Raspberry Pi 5 hardware.

==OS that has been tested==
* Raspbian
* DietPi
* Manjaro
* Ubuntu
* myNode
* Umbrel
* Volumio
* RetroPie
* Twister
==Install==
Please follow the steps below:
===Enable I2C===
Reter to [[How to enable I2C]]

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

'''Check & review I2C address:'''
<PRE>
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: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
</PRE>
Explaination:
<PRE>
#36 - the address of the battery fuel gauging chip
#68 - the address of the RTC chip
</PRE>

===Install gpiod package===
sudo apt install -y gpiod

===Clone the script===
<pre>
git clone https://github.com/geekworm-com/x728-script

cd x728-script
chmod +x *.sh
</pre>
'''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

===Configuring Different GPIO Chip for <span class="tb_red">Raspberry Pi 5 hardware</span>===
If you are '''NOT USING''' Raspberry 5 hardware, skip this step,or run the following command to set differnt chip number.

PS: Since 2024-09-02, Raspberry Pi has finally unified the gpipchip to 0 on all Raspberry Pis(Pi, 0, 1, 2, 3, 4, 5). Previously, the gpiochip on the Raspberry Pi 5 was 4.

So we comment out the following command line.
#sed -i 's/xPWR.sh 0 5 12/xPWR.sh '''4''' 5 12/g' x728-pwr.service

===Create the x728-pwr service===
x728-pwr service will be responsible for power management and hardware safe shutdown.
<pre>
sudo cp -f ./xPWR.sh /usr/local/bin/
sudo cp -f x728-pwr.service /lib/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable x728-pwr
sudo systemctl start x728-pwr
</pre>
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===
1. Prepair xSoft.sh command.
:<pre>sudo cp -f ./xSoft.sh /usr/local/bin/</pre>
2. Then create a '''x728off''' alias command to execture safe shutdown command.
:* <span class="tb_red">for x728 v2.5 v2.3 v2.2 v2.1 v2.0</span>
:<pre>echo "alias x728off='sudo /usr/local/bin/xSoft.sh 0 '''26''' '" >> ~/.bashrc</pre>
:* <span class="tb_red">for x728 v1.2 v1.3</span>
:<pre>echo "alias x728off='sudo /usr/local/bin/xSoft.sh 0 '''16''' '" >> ~/.bashrc</pre>
: PS: The difference between them is that '''different GPIO pins''' are used for '''shutdown'''

3. Then run the following command to make the '''.bashrc''' file take effect
:<pre>source ~/.bashrc</pre>

4. Then you can run <code>x728off</code> to execute software shutdown as follows
:<pre>x728off</pre>

===Uninstall===
Run the following command to uninstall all:
./uninstall.sh
===Test safe shutdown===
'''Software safe shutdown command''':
x728off
<span class="tb_red">DON'T run the 'shutdown' linux command to shut down, otherwise the power of x728 shield will not be shut down.</span>

'''Hardware safe shutdown operation''':

You can verify the safety switch through the onboard switch, press and hold the switch for <code>3</code> 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 <code>1-2</code> seconds to reboot
* press button switch <code>3</code> seconds to safe shutdown,
* press <code>7-8</code> 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.

'''[PS]'''

The old example code uses the RPi.GPIO library, which is currently not supported in kernel 6.6.x, so you may encounter an error when running the following code
sudo python3 sample/x728-v2.x-plsd.py

Note that you need to provide a different gpiochip number on Pi 0,1,2,3,4 ('''0''') and Pi 5 ('''4''').

We recommend that you change your example program to use the libgpiod library, and libgpiod is officially recommended, and we also provide ONLY ONE example using the libgpiod library ('''x728-v2.x-plsd-gpiod.py'''), which you can run as follows:

sudo python3 sample/x728-v2.x-plsd-libgpiod.py

For other example programs that use the RPi.GPIO library, it is recommended that you change to the libgpiod version if it runs incorrectly.

In fact, you can change those sample program to shell

Each example program demonstrates a different function:

'''x728-v2.x-bat.py''': Script to read battery power and voltage;
cd ~x728-script
sudo python3 sample/x728-v2.x-bat.py

'''x728-v2.x-pld.py''': Script to AC Power supply loss dection
cd ~x728-script
sudo python3 sample/x728-v2.x-pld.py

'''x728-v2.x-asd.py''': Script to Auto shutdown when the battery voltage is lower than a certain specified value
cd ~x728-script
sudo python3 sample/x728-v2.x-asd.py
'''PS:'''

1. All 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 X728 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 [[X728-hardware#Pins_and_GPIO_used |X728 hardwar]] to check the PIN occupancy of X728 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.

===Set and Read the RTC time===
Refer to [[How to enable RTC]]

==How to Use GPIO16 to control battery charging==
1. This feature is only newly added from '''Version 2.5'''

2. This feature is only suitable for advanced players, if you are not familiar with Linux, we do not recommend you to use this feature. For beginners, it is enough to short the ''''CHG Ctrl'''' so that the X728 v2.5 shield will automatically charge when the power adapter is connected

If you want to control battery charging through GPIO, please refer to the instructions below:
<pre style="color:red">
"CHG Ctrl" - Short : battery automatic charging when powe adapter connected
"CHG Ctrl" - Open : GPIO16 output stays high: Charging enabled, GPIO16 output stays low : Charging disabled
</pre>
<pre style="color:blue">
# Sample shell command

GPIO=16

# Read the /sys/kernel/debug/gpio file to get the actual GPIO pin
GPIO=$(cat /sys/kernel/debug/gpio | grep "GPIO$GPIO" | awk -F'gpio-' '{print $2}' | awk -F' ' '{print $1}')
echo "$GPIO" > /sys/class/gpio$GPIO/export
echo "out" > /sys/class/gpio/gpio$GPIO/direction

# Enable charging
echo "1" > /sys/class/gpio/gpio$GPIO/value

# Disable charging
echo "0" > /sys/class/gpio/gpio$GPIO/value
</pre>

==Support==
Email: support@geekworm.com

==FAQ==
<html>
<details>
<summary>Q: How to login <b>volumio</b> via SSH?</summary>
<p>1. Enable SSH:</p>
<p>Visit http://volumio.local/dev/, then click <b>ENABLE SSH</b> button</p>
<p>2. URL connection is IP address, and the default user name is <b>volumio</b>, default password is <b>volumio</b></p>
</details>

<details>
<summary>Q: How to login to <b>Umbrel</b> via SSH?</summary>
A: ssh umbrel@umbrel.local (or ssh umbrel@<IP address of your Umbrel>). the default user name is <b>umbrel</b>, default password is <b>moneyprintergobrrr</b>
</details>

<details>
<summary>Q: How to login to <b>myNode</b> via SSH?</summary>

A: URL connection is IP address, and the default user name is <b>admin</b>, default password is <b>bolt</b>
</details>

<details>
<summary>Q: How to login to <b>DietPi</b> via SSH?</summary>

A: URL connection is IP address, and the default user name is <b>root</b>, default password is <b>dietpi</b>
</details>

<details>
<summary>Q: Is <b>LibreELEC</b> supported?</summary>

A: TODO
</details>

</html>

==Other resource==
* Chip-Specifications:[[File:MAX17040-MAX17041.pdf]]
*[https://www.sparkfun.com/datasheets/Components/DS1307.pdf I2C address: 0x36 for battery fuel gauging, 0x68 for RTC]
*References: [https://www.instructables.com/Raspberry-Pi-Tutorial-How-to-Use-a-Buzzer/ Raspberry Pi Tutorial: How to Use a Buzzer]

Return to [[X728]] or [[X728-hardware]]


<!--Add review function! -->
<comments />

<!--Please choose the -->
<!--Remove other categories, just keep the appropriate categories -->

[[Category:Product Manual]]
[[Category:Raspberry pi]]
[[Category:Knowledge]]