04-21-2018, 12:35 PM
I also written some scripts for the GPIO pins first off all I wrote a script to initialize all the pins that I have connected
To test all these pins I also wrote a script
At last I wrote a script to power my fan in function of the temperature
Code:
#!/bin/sh
#RED - RGB-strip
echo 79 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio79/direction
#BIG - Case Button
echo 80 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio80/direction
#POWER - Case Led
echo 81 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio81/direction
#FAN - Case fan
echo 82 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio82/direction
#RPM_FAN - Case fan
echo 83 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio83/direction
#GREEN - RGB-strip
echo 84 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio84/direction
#SMALL - Case Button
echo 85 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio85/direction
#BLUE - RGB-strip
echo 86 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio86/direction
#HDD - Case Button
echo 87 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio87/direction
To test all these pins I also wrote a script
Code:
#!/bin/bash
#MikeD
#Test all pins in use
LOOPS=5
ON_TIME=.5
OFF_TIME=.25
echo " "
echo " _________________________ "
echo "| |"
echo "| Test script voor I/O |"
echo "| ***** BY MIKE D. **** |"
echo "|-------------------------|"
echo "| ~~ INPUTS ~~ |"
echo "| BIG =" `cat /sys/class/gpio/gpio80/value` " |"
echo "| SMALL =" `cat /sys/class/gpio/gpio85/value` " |"
echo "| RPM_FAN =" `cat /sys/class/gpio/gpio83/value` " |"
echo "| PRESS BIG button |"
while [ `cat /sys/class/gpio/gpio80/value` -gt 0 ]; do
sleep .1
done
echo "| BIG == OK ! |"
echo "| PRESS SMALL button |"
while [ `cat /sys/class/gpio/gpio85/value` -gt 0 ]; do
sleep .1
done
echo "| SMALL == OK ! |"
echo "| Rotate case fan |"
while [ `cat /sys/class/gpio/gpio83/value` -gt 0 ]; do
sleep .1
done
echo "| RPM_FAN == OK |"
echo "|-------------------------|"
echo "| ~~ ALL INPUTS OK ~~ |"
echo "|-------------------------|"
echo "| ~~ OUTPUTS ~~ |"
echo "| RED - RGB-strip |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio79/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio79/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| GREEN - RGB-strip |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio84/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio84/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| BLUE - RGB-strip |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio86/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio86/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| FAN - Case-fan |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio82/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio82/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| POWER - Case-led |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio81/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio81/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| HDD - Case-led |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio87/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio87/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "|-------------------------|"
echo "| ~~ ALL OUTPUTS OK ~~ |"
echo "|-------------------------|"
echo "| ***** BY MIKE D. **** |"
echo "|_________________________|"
echo " "
At last I wrote a script to power my fan in function of the temperature
Code:
#!/bin/bash
#MikeD Automatic fan on cpu temp
CHECK_TIME=10 #IN SEC
function pwm(){
LOOP=0
while [ $LOOP -lt $(($CHECK_TIME*75)) ]; do
echo 1 > /sys/class/gpio/gpio82/value
sleep $1
echo 0 > /sys/class/gpio/gpio82/value
sleep $2
LOOP=$(($LOOP+1))
done
}
function fanOff() {
echo 0 > /sys/class/gpio/gpio82/value
sleep $CHECK_TIME
}
function fanTweFiv() {
pwm .025 .075
}
function fanFifty() {
pwm .050 .050
}
function fanSevFiv() {
pwm .075 .025
}
function fanFull() {
echo 1 > /sys/class/gpio/gpio82/value
sleep $CHECK_TIME
}
while [ 1 ]; do
TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)
if [ $TEMP -le 20000 ]
then
fanOff
fi
if [ $TEMP -gt 20000 -a $TEMP -le 25000 ]
then
fanTweFiv
fi
if [ $TEMP -gt 25000 -a $TEMP -le 35000 ]
then
fanFifty
fi
if [ $TEMP -gt 35000 -a $TEMP -le 45000 ]
then
fanSevFiv
fi
if [ $TEMP -gt 45000 ]
then
fanFull
fi
done