I have a Bash script (see below) which controls a relay via the GPIO pins. It works fine but I've noticed the CPU of the Pi gets very hot - up to 83C or so when it runs, up from around 40C when the Pi's idle.
I've looked at CPU usage and the script, which runs all the time, uses 16% of CPU.
Has anyone got any ideas why this overheating is happening?
Thanks.
#!/bin/bash
while true; do
s=$(date +%S)
if [ $s -eq 58 -o $s -eq 28 ]; then
sleep 1.9
echo "1" > /sys/class/gpio/gpio6/value
sleep 0.5
echo "0" > /sys/class/gpio/gpio6/value
sleep 1
fi
done
There are two things that I am thinking of. You are running through many more loops than you need to since it seems that you want to turn a relay on for a half a second every 30 seconds. You could sleep the whole loop 1 second doing the following
The other thing I'm thinking of is the following:
One you are checking a bunch of Most likely drawing too much current in the relay circuit. Do you have any current limiting resistors in series with the relay? That is the first thing I would check as you don't have any massive computations happening in your bash script. This is also very much overkill for a Rasperry Pi, but that's an entirely different beast.