Changes

Jump to navigation Jump to search

X728-script

1,543 bytes added, 2 April
-->
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==
#68 - the address of the RTC chip
</PRE>
 
===Install gpiod package===
sudo apt install -y gpiod
===Clone the 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 Raspberry Pi 5 hardware===
If you are not using Raspberry 5 hardware, skip this step,or run the following command to set differnt chip and pwm number.
sed -i 's/xPWR.sh 0 5 12/xPWR.sh 4 5 12/g' x728-pwr.service
sed -i 's/xSoft.sh 0 26/xSoft.sh 4 26/g' install-sss.sh
sed -i 's/xSoft.sh 0 16/xSoft.sh 4 16/g' install-sss-v1.sh
===Create the x728-pwr service===
x728-pwr service will be responsible for power management and hardware safe shutdown.
<pre>
sudo cp -f ./x728-pwrxPWR.sh /usr/local/bin/
sudo cp -f x728-pwr.service /lib/systemd/system
sudo systemctl daemon-reload
===Prepair software shutdown script===
Run the folloing command:
Please check the version of X728 shield and select the appropriate file, <code>* for x728-v2.x-softsd.sh</code> fiel for <code>x728 5 v2.3/v2.2/v2.1 shield</code>v2.0 sudo cp -f ./x728-v2.x-softsd.sh /usr/local/bin/x728install-softsdsss.shOR (* for <code>x728 v1.2/v1.3 shield</code>) sudo cp -f ./x728install-sss-v1.x-softsd.sh /usr/local/bin/x728-softsd.shCreate a alias <code>x728off</code> command to execute the software shutdown<pre>echo "alias x728off='sudo /usr/local/bin/x728-softsd.sh'" >> ~/.bashrcsource ~/.bashrc</pre>
Then you can run <code>x728off</code> to execute software shutdown as follows
x728off
===Uninstall===
Run the following command to uninstall all:
./uninstall.sh
===Test safe shutdown===
'''Software safe shutdown command''':
===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:
'''read_fan_speed.py''': Read the pwm fan running speed; cd ~x728-script sudo python3 sample/read_fan_speedv2.py '''pldx-bat.py''': AC Power supply loss dection scriptScript to read battery power and voltage;
cd ~x728-script
sudo python3 sample/pldx728-v2.pyx-bat.py
'''plsdx728-v2.x-pld.py''': Auto shutdown when Script to AC power Power supply loss or power adapter failure script;(Added auto shuntdown function base pld.py)dection
cd ~x728-script
sudo python3 sample/plsdx728-v2.x-pld.py
'''buzzerx728-v2.x-asd.py''': demonstrates how Script to Auto shutdown when the buzzer will sound when power supply battery voltage is lost, which is very important in some usage scenarios.lower than a certain specified value
cd ~x728-script
sudo python3 sample/buzzerx728-v2.x-asd.py'''PS:'''
The above 1. All sample python file 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]]
===Enable OLED display===Refer 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 [[How to enable OLED displayX728-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===
PS: We Refer to [[How to enable RTC]] ==How to Use GPIO16 to control battery charging==1. This feature is only test this step on Raspberry Pi OS;newly added from '''Version 2.5'''
12. To enable RTC moduleThis feature is only suitable for advanced players, first add <code>dtoverlay=i2c-rtcif you are not familiar with Linux,ds1307</code> we do not recommend you to /boot/configuse this feature.txt under [all] or For beginners, it is enough to short the ''''CHG Ctrl'''' so that the end of file and reboot: sudo nano /boot/configX728 v2.txtSave and exit. In nano, you do that by hitting CTRL + X, answering Y and hitting Enter 5 shield will automatically charge when prompted.the power adapter is connected
2. Run the commands If you want to control battery charging through GPIO, please refer to disable the instructions below:<pre style="fake hwclockcolor:red" which interferes with the 'real' hwclock> sudo apt"CHG Ctrl" -get -y remove fake-hwclockShort : battery automatic charging when powe adapter connected sudo update"CHG Ctrl" -rc.d -f fake-hwclock remove sudo systemctl disable fake-hwclockOpen : GPIO16 output stays high: Charging enabled, GPIO16 output stays low : Charging disabled3. Then run the following command to comment out 7-12 line in file <code>/lib/udev/hwclock-set</codepre>: sudo nano /lib/udev/hwclock-set<!--[[File:X728-7.png|none]]-->?<syntaxhighlight langpre style="python" line highlight="7-12color:blue">#!/bin/sh# Reset the System Clock to UTC if the hardware clock from which it# was copied by the kernel was in localtime.Sample shell command
devGPIO=$116
#if [ -e Read the /sys/runkernel/systemddebug/system ] ; thengpio file to get the actual GPIO pin# exit 0#fi##GPIO=$(cat /sys/kernel/sbindebug/hwclock gpio | grep "GPIO$GPIO" | awk -F'gpio-rtc=' '{print $dev 2}' | awk --systzF' ' '{print $1}')#echo "$GPIO" > /sbinsys/hwclock --rtc=class/gpio$dev --hctosysGPIO/export?<echo "out" > /sys/class/syntaxhighlight>gpio/gpio$GPIO/direction
PS: Inserting a `# `at the beginning of a line means to comment the lineEnable chargingecho "1" > /sys/class/gpio/gpio$GPIO/value
4. Reboot the Raspberry Pi# Disable charging sudo rebootecho "0" > /sys/class/gpio/gpio$GPIO/value5. Run the command to verify the time is correct. Plug in Ethernet or WiFi to let the Pi sync the right time from the Internet date6. Run the command to write the time sudo hwclock -w7. Run the command to read the time sudo hwclock -rOnce the time is set, make sure the batteries are inserted so that the time is saved. You only have to set the time once. That's it! Next time you boot the time will automatically be synced from the shield.</pre>
===Other===
<code>pwm_fan_control.py</code> is no longer used, and are reserved here for research and use by python lovers only.
==Support==
Email: support@geekworm.com
==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]
References: *Return to [[X728]] or [[https://www.instructables.com/Raspberry-Pi-Tutorial-How-to-UseX728-a-Buzzer/ Raspberry Pi Tutorial: How to Use a Buzzerhardware]]
Return to [[X728]] or [[X728-hardware]]
<!--Add review function! -->

Navigation menu