Rp4b fanshim service working but fan never Off

I have limited programming skills but use rp4b with libreelec kodi and pimoroni fanshim for cooling. I use pi as media link to my NAS. After running properly for 1 day, my new fanshim no longer cycles fan but continues to show Green LED and runs fan continuously. I reinstalled Jane’s kodi fanshim addon and the libreelec rpi-tools addon. Below is what I see using debug mode in Jane’s kodi fanshim addon:

2020-02-05 10:21:02.951 T:2761278320 NOTICE: Register - new cec device registered on cec->RPI: CEC Adapter (2708:1001)
2020-02-05 10:21:04.637 T:2702529392 NOTICE: Fan On :50 Off 42
2020-02-05 10:21:04.637 T:2702529392 NOTICE: Delay :2 Hide Led: False Debug : True
2020-02-05 10:21:04.756 T:2702529392 NOTICE: Starting FanShim Monitor
2020-02-05 10:21:06.131 T:2719314800 NOTICE: service.watchedlist: WatchedList Database Service starting…
2020-02-05 10:21:06.134 T:2719314800 NOTICE: service.watchedlist: Notification. WatchedList: begin update in 5 minutes
2020-02-05 10:21:06.820 T:2702529392 NOTICE: Fan Status: False temp:39.0 Freq 1500.345728 %=
2020-02-05 10:21:08.981 T:2702529392 NOTICE: Fan Status: False temp:37.0 Freq 600.16992 %=
2020-02-05 10:21:13.325 T:2702529392 NOTICE: Previous line repeats 1 times.
2020-02-05 10:21:13.325 T:2702529392 NOTICE: Fan Status: False temp:36.0 Freq 1500.345728 %=
2020-02-05 10:21:15.481 T:2702529392 NOTICE: Fan Status: False temp:37.0 Freq 600.117184 %=
2020-02-05 10:21:17.656 T:2702529392 NOTICE: Fan Status: False temp:36.0 Freq 1500.398464 %=
2020-02-05 10:21:19.810 T:2702529392 NOTICE: Fan Status: False temp:37.0 Freq 600.117184 %=
2020-02-05 10:21:21.986 T:2702529392 NOTICE: Fan Status: False temp:37.0 Freq 1500.345728 %=
2020-02-05 10:21:24.139 T:2702529392 NOTICE: Fan Status: False temp:37.0 Freq 600.16992 %=

I hope someone knows what to do to fix. Many Thanks, Rob

GPIO 18 , physical pin 12, is the fan control pin. It is pulled low to turn the fan off. If the fan shim isn’t making a good contact with that GPIO pin the fan won’t turn off. If you haven’t already, try removing and reattaching the fan shim.

I have no way to run linux tools in LibreElec so at best I was able to find a Kodi Addon for GPIO Pin monitoring. It shows that pin 12 is inactive. I didn’t find any voltage on pin 12 using a Fluke multimeter and grounding to USB metal case. The Fan continues to run and the LED is Green. If I limit the airflow to the fan a little red led does light next to the bright green so it seems there is some temp monitoring going on. I’m 71 yrs old and have come from high tech (Intel, various startups, Citrix) on operations side so plunging into Linux and Python and Kodi add-on programming).
What is puzzling me is that the fanshim worked for about a day and then quit working (fan was off when cpu temp was below minimum setting in Jane’s Kodi fanshim addon. Then suddenly it doesn;t work. I have powered down and removed and replaced fanshim. I have uninstalled and reinstalled libreelec’s rpi-tools and Jane’s fanshim addon. This has not affected fanshim failure to turn fan off. I welcome any suggested troubleshooting. Oh, I use WinSCP from my PC to look at the raspberry pi 4b running LibreElec and Kodi. I can see in the Log File that the fanshim monitor is loaded and it has the correct turn on, turn off temperatures.

Do you have a spare Micro SD card? If yes, install Raspbian on it, run the fan shim installer, setup the daemon, and see what happens. If it still doesn’t work you’ll know its likely a hardware issue. If it does work you know its a software issue in LibreElec.
If you have a 10 kilo ohm resistor handy, connect it from GPIO 18 to ground and see if the fan stops. Just touch the leads for testing.
The default fail safe mode for the fan is on. It will just run continuously with no software installed. To turn the fan off the daemon pulls GPIO 18 low, then high again to turn it on. I often shut down but don’t unplug the power supply. It bugged me that the fan kept running so I added a pull down resistor to GPIO 18 on the Fan Shim. Default is now off instead of on. Software control of the fan works just as it did without the resistor so I’m good to go now. I press the button on the fam shim and mu Pi shuts down, and the fan stops. press it again and the Pi boots up. Fan starts when the temp hits my set point.

Great Idea, Thank you. I will find microSD card and learn how to use Raspian and the fan shim installer (you meant the official python-based Pimoroni one, not the Jane Kodi addon, correct?). I will also find a 10k ohm resistor… sure regret the loss of Radio Shack in America as we used to be able to run over and pick up such items with ease.

Another symptom I forgot to add is that the button now does nothing. Before it switched the fan. Maybe this is a clue that my GPIO isn’t working correctly.

Yes, use the Pimoroni Fan Shim installer. From a terminal window run the following

git clone https://github.com/pimoroni/fanshim-python
cd fanshim-python
sudo ./install.sh
cd examples
sudo ./install-service.sh --on-threshold 65 --off-threshold 55 --delay 2

Then reboot. The fan should then turn on at 65c and off again at 55c. You can change those values in that last line above if you want. The LED will show color based on the temp of the CPU. The Button will boot the Pi up if its off but has power. Add dtoverlay=gpio-shutdown to your config.txt file and pressing the button will do a proper shutdown.

If you want to just do a quick test in Raspbiian, just add the following line to your config.txt file.
And reboot. The fan should then turn on at 55c, and no need to install any of the Pimoroni software. Just change the 55000 to what ever you want, 35000 is 35c for example and what I have mine set to. I’m currently not using the Pimoroni software. I gave it a try to make sure it all worked etc, but latter on simplified things based on how I use my Fan Shim.

EDIT: Um, maybe don’t try this, not unless you add the pull down resistor. Without it it won’t tell you much as the fan will just run on boot up and never stop. That didn’t occur to me until after I posted it. For me, with the resistor installed, on boot up the my fan is off until the trip temp is reached. And it just keeps running until I shut down. That works for me but may not be what you or others want. Installing the Pimoroni daemon will get you the on off function though. Sorry to maybe confuse things.

I am learning a lot after following up on your suggestions. Again, Thank you.

I created Raspbian on another microSD and installed into my pi4b and booted and upgraded everthing. Then I loaded the fanshim service with settings. I got a very very bright green LED (so the software is working on that part as the default is very very bright and I didn’t add a Dim number). Anyhow, the fan was ON immediately and stayed On.
I then long pressed the fanshim button and after a moment got a Blue LED flicker and let go of the button. Nothing changed, fan still On. I tried a short button push, no change.
I’m wondering if this means my pi 4b is damaged or if the fanshim is defective for that BCM pin 18 (physical pin 12)? At a complete loss how to tell. Using my voltmeter, I never see voltage on pin 18. Oh, I haven’t found a local source for that resistor yet, still will try to find it.
And, I didn’t find a command for the fanshim service to force fan OFF. Do you know what it is so I could try inputting just an Off command to see if BCM Pin 18 actually does something?


I just found some information on fanshim on GitHub that may explain how to turn on and off the fan. I will try this tomorrow.


You should first set up an instance of the FANShim class, eg:

from fanshim import FanShim fanshim = FanShim()


Turn the fan on with:


Turn it off with:


You can also toggle the fan with:


You can check the status of the fan with:

fanshim.get_fan() # returns 1 for ‘on’, 0 for ‘off’

In Raspbian, with the daemon installed, during boot up the fan will run.
Once the daemon loads and takes control of the fan, it should stop.
Assuming that the SOC is cool and its temperature is below the trip point.
Then as it warms up and hits the trip point the fan will start.
And stop again once the temperature drops below the other trip point.

The fan shim button isn’t programed to do anything via the Pimoroni software. Thats left up to you. However, the Raspberry Pi has a feature that if you shut down and don’t remove power, momentarily grounding GPIO 3 will make the Pi boot up. The fan shim switch is wired to GPIO 3 and grounds it when pressed.
If you want to use it to turn the fan on off you’ll have some coding to do. I clipped the following from the GitHub page as a crib sheet for my fan Shim.

git clone https://github.com/pimoroni/fanshim-python
cd fanshim-python
sudo ./install.sh

install service

cd examples
sudo ./install-service.sh --on-threshold 65 --off-threshold 55 --delay 2

chage service

sudo systemctl stop pimoroni-fanshim.service
sudo ./install-service.sh --on-threshold 75 --off-threshold 60 --delay 5

disable service

sudo systemctl stop pimoroni-fanshim.service
sudo systemctl disable pimoroni-fanshim.service

enable again

sudo systemctl enable pimoroni-fanshim.service
sudo systemctl start pimoroni-fanshim.service


from fanshim import FanShim
fanshim = FanShim()

Turn the fan on with:
Turn it off with:
You can also toggle the fan with:
You can check the status of the fan with:
fanshim.get_fan() # returns 1 for ‘on’, 0 for ‘off’

Fan Shim includes one RGB APA-102 LED.
Set it to any colour with:
fanshim.set_light(r, g, b)
Arguments r, g and b should be numbers between 0 and 255 that describe the colour you want.
For example, full red:
fanshim.set_light(255, 0, 0)

Fan Shim includes a button, you can bind actions to press, release and hold events.
Do something when the button is pressed:
def button_pressed():
print(“The button has been pressed!”)
Or when it has been released:
def button_released(was_held):
print(“The button has been pressed!”)
Or when it’s been pressed long enough to trigger a hold:

def button_held():
print(“The button was held for 2 seconds”)

The function you bind to on_release() is passed a was_held parameter, this lets you know if the button was held down for longer than the configured hold time. If you want to bind an action to “press” and another to “hold” you should check this flag and perform your action in the on_release() handler:
def button_released(was_held):
if was_held:
print(“Long press!”)
print(“Short press!”)
To configure the amount of time the button should be held (in seconds), use:
If you need to stop Fan Shim from polling the button, use:
You can start it again with:

It sounds like either the fan shim pad for GPIO 18 isn’t making contact with that GPIO pin.
Or the circuit that controls the fan has failed.
You could try tilting the fan shim slightly while its running to see if the fan starts working correctly (stops running when its supposed to). Or ever so slightly bend the GPIO 18 pin to one side.
The 10k resistor will tell you if the circuit has failed. If you use it to pull the pad on the fan shim to ground, and the fan doesn’t stop, the circuit has failed.
You could also remove the Fan Shim and just use jumpers to wire up +5V and Ground. Female (Pi GPIO) to male (Fan Shim pads / holes) should work. You could then just ground GPIO 18 with a wire. Doing this with the fan shim on the Pi may damage the GPIO circuit.

Until I find a resistor I am going to experiment by moving the fanshim to my old pi 3b and use the microSD card which now has Raspian and the Pimoroni python tool installed.
Hopefully the pins work the same and if the fan does stop when service boots, then I know my new pi4b is broken or is missing some piece of software. If it continues same behavior of continuous running, then I can suspect the fanshim board has a defective circuit.
Shall we go ahead and close this discussion? I have learned a lot so far from your suggestions and am now thinking we are at a good point to stop. After all, I can just leave the fan running continuously as I don’t power down my home theater pi4b so it is availble to pull from my NAS media library upon demand.

Just let me know what you find when all is said and done. ;)

You could use RPI.GPIO to pull that pin low. No having to install any software. Just do it on the Pi 3B with the fan shim attached. The fan should stop when you do it.
A quick Google search found this.

And @Crowbot posted this in another thread
You could run this on the Pi 4 to see if it has any issues.

If the Micro SD card in that Pi 3B is running Buster, you can just swap it over to the Pi 4 to do some checks. Then swap it back to the 3B when done without having to reimage it.

1 Like

Hi, The 3b worked perfectly with the fanshim and pimoroni service. So now I fear it is my 4b that is broken. I will switch the sd card to the 4b and see if everything works. Yeah! Feeling pretty good having navigated around in Raspian and GitHub per all your help!

If the sd card with Raspian and pimoroni fanshim program does work in my 4b, then I presume the Kodi addon program (https://github.com/jane-t/rpi-fanshim) isn’t working. I
f it does not work, then my 4b gpio is broken for BCM pin 18.
Should know shortly (no pun intended).

Ah, making good progress, hopefully its just a software glitch.

Sigh! The test fails. My 4b just won’t work being tested using the sd card from the working 3b.

I’m thinking the issue is that my 4b BCM pin18 circuit is either damaged or not set up properly. The fan just runs happily so I’ll leave it until I talk myself into buying another 4b. I just don’t yet have the tools to figure out more on the gpio side. Note: I did try to run wiring pi utility to test the gpio pins but it didn’t like that I had a 4b so apparently it is not yet updated beyond the pi3 series.

Several folks running 4b with the Jane kodi addon are reporting it is working so I presume her software isn’t the problem. But I will wait and see if the user community finds my issue and a software fix.

Thank you all so much for the assistance.

There is a lot of software out there that doesn’t “yet” work on Buster, unfortunately. You usually don’t find out until you try to install and or run it.

Just to double check, the 4B booted up with the card from the 3B?
But the fan shim didn’t turn on off like it should.

There is another thread here on getting the Fan Shim Running in Kodi, you’d have to do a search to find it. I posted in it a while back. I believe the author of that addon posted in it?

EDIT: Found it.

Yes, that’s the addon I have installed on the 4b from jane_t. Others report it works but mine only worked for one day. That’s why I’m afraid something is wrong with my 4b in the end.

+++++Add on for Kodi on Raspberry Pi to control the Pimoroni Fanshim allowing the CPU temperature to be used to turn the Fan on and off. - jane-t/rpi-fanshim

@alphanumeric and @crowbot, Thank you for all your help. I’ve learned a lot while investigating my GPIO problem. I concluded that the raspberry pi 4b I purchased has a defective GPIO circuit for pin 12 (BCM18) and as it probably involved the SOC, I have requested an RMA/Replacement from the Vendor.

@alphanumeric and @crowbot,
I am happy to let you know that my vendor (Labists) replaced the defective raspberry pi 4b. What a great vendor.

The new unit worked immediately and correctly so now I’m getting full value from the GPIO pins as well as the fanshim.

This set of support comments may now be closed.