-
-
yaazzz
-
- Posts: 18
- Joined: Fri Jan 05, 2024 7:44 pm
Sun Jan 21, 2024 10:57 am
by
yaazzz » Sun Jan 21, 2024 10:57 am
Here is the code I use to start the fan at startup. Probably usefull for all of the CM3588 users.
1 - Create a new init.d script, for example, /etc/init.d/gpio_setup:
2. Add the following content to the script:
Code: Select all
#!/bin/sh
### BEGIN INIT INFO
# Provides: gpio_setup
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set up GPIO 59 as output with value 1
# Description: Set up GPIO 59 as output and set its value to 1 during system startup.
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="GPIO setup script"
NAME=gpio_setup
DAEMON=/usr/local/bin/gpio_setup.sh
case "$1" in
start)
echo "Setting up GPIO 59 as output with value 1..."
$DAEMON
;;
stop)
# No need to stop anything in this example
;;
restart|force-reload)
echo "Restarting GPIO setup script..."
$DAEMON
;;
*)
echo "Usage: $NAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
3. Save the file and exit the text editor.
4. Now, create the script that actually sets up the GPIO. Create a file named /usr/local/bin/gpio_setup.sh:
Code: Select all
sudo nano /usr/local/bin/gpio_setup.sh
5. Add the following content to the script:
Code: Select all
#!/bin/bash
# GPIO number
GPIO_NUMBER=59
# Set GPIO 59 as output
echo $GPIO_NUMBER > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$GPIO_NUMBER/direction
# Set the value to 1
echo 1 > /sys/class/gpio/gpio$GPIO_NUMBER/value
exit 0
6. Save the file and exit the text editor.
7. Make the init.d script and the setup script executable:
Code: Select all
sudo chmod +x /etc/init.d/gpio_setup
sudo chmod +x /usr/local/bin/gpio_setup.sh
8. Register the init.d script to start during the system boot:
Code: Select all
sudo update-rc.d gpio_setup defaults