yaazzz wrote: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
Hi, i don't have this ZH1.5-2pin connector for the 5V CPU fan socket. This is why i want to use your skript with my GPIO pins.
Your skript is working fine and i adapted it to set the line 11 to LOW, and the line 12 to HIGH (those are the pins i where i want to connect my fan). Here is the output for gpioinfo gpiochip3:
gpiochip3 - 32 lines:
line 0: unnamed unused input active-high
line 1: unnamed unused input active-high
line 2: unnamed unused input active-high
line 3: unnamed unused input active-high
line 4: unnamed unused input active-high
line 5: unnamed "vcc3v3-host-32" output active-high [used]
line 6: unnamed unused input active-high
line 7: unnamed unused input active-high
line 8: unnamed unused input active-high
line 9: unnamed unused input active-high
line 10: unnamed unused input active-high
line 11: unnamed "sysfs" output active-high [used]
line 12: unnamed "sysfs" output active-high [used]
line 13: unnamed unused input active-high
line 14: unnamed unused input active-high
line 15: unnamed unused input active-high
line 16: unnamed unused input active-high
line 17: unnamed unused input active-high
line 18: unnamed unused input active-high
line 19: unnamed unused input active-high
line 20: unnamed unused input active-high
line 21: unnamed unused input active-high
line 22: unnamed unused input active-high
line 23: unnamed unused input active-high
line 24: unnamed unused input active-high
line 25: unnamed unused input active-high
line 26: unnamed unused input active-high
line 27: unnamed unused input active-high
line 28: unnamed unused input active-high
line 29: unnamed unused input active-high
line 30: unnamed unused input active-high
line 31: unnamed unused input active-high
As you can see, i am not able to set the line 11 to LOW. Do you have an idea what i can do about this?