I have little to no experience with any form of computer software coding/editing but I have managed to get EmulationStation working (sort of) on my Raspberry Pi 2. I have a bought a fan and plugged it into my Pi but the problem is that when I shutdown the Pi the fan will continue to spin unless I completely unplug my system. I don't want to have to plug and unplug a wire every time I use my Pi so I was wondering if there is a command that I could enter through the terminal interface somehow to make the fan turn off when I select shutdown from the EmulationStation menu. Agagin I want to emphasise that I have very little understanding of computer brains so a step by step answer would be easiest for me to understand. Thanks.
2 Answers
Depending on the fan, it could also be potentially dangerous for the Raspberry Pi the way you have it connected. If you insist on powering it from the Raspberry Pi, the proper way to do it - given the resistance of the fan is large enough to limit the current it draws; otherwise include one - would be by using a transistor, as seen in the schematic I created below (fan is represented by the coil):
After the Raspberry Pi has booted up, you should run something like this in the terminal:
echo 12 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio12/direction
echo 1 > /sys/class/gpio/gpio12/value
And once you want to turn the fan off, just before shutdown:
echo 0 > /sys/class/gpio/gpio12/value
That is one way to do it, there are of course numerous others to toggle the GPIO pins, a quick googling can give you alternatives.
- 233
- 1
- 7
You haven't said how you are powering the fan. "I have a bought a fan and plugged it into my Pi" is vague.
Given that it stays on I reckon it's safe to assume you have connected it to a 5V pin and a ground pin. These pins are not GPIO, they are not switchable, they are powered as long as the Pi is powered.
So the answer to your question is no, there is no command to switch the fan off.
- 71,852
- 5
- 76
- 108
