Pi 4, Fan and 16-Channel PWM

I want to add a fan to my Pi 4 configuration witch includes Adafruit 16-channel PWM HAT and 3 16-channel PWM Bonnets. The fanShim uses one of the I2C pins so need another answer. I want to use 5vdc, 200ma fan

  1. Is there any reason I can’t plug the fan into one of the PWM HAT’s outputs using the +5v/ground to power the fan?

  2. Can I use the PWM control signal and a NPN transistor to turn the fan on/off? Seems that a duty cycle of 100% 3v3dc would be on and a duty cycle of 0% would be off. When to turn on or off is a software question - that should be easy.

What am I missing?

I would think 1 and 2 are doable, option 1 for sure.
I’m no expert but I do believe the PWM signal used for servos differs from what you’d use to say adjust the brightness of an LED. Just keep that in mind when your researching it and setting it up. It sounds like your probably already ahead of me on that front though.
I have a full Pan Tilt kit, but the Pan Tilt Hat does all the PWM magic for me.

I haven’t tried what you want to do but keep in mind that these fans were designed to run DC and you would be effectively running them AC (monophasic). You might want to consider putting a capacitor (either inline or in series) on the fan to even out the pulses.

The voltage never actually goes negative but I get where your coming from. It’s pulsed DC.
In the true sense AC current reverses polarity. It might sound like nit picking, thats not my intention, its just that I’m a retired electronic technician. ;)
In this case the average voltage that the fan sees will go down as the pulse width decreases. Same thing will happen with less pulses.
Also, what voltage is the PWM pulse, the Pi uses 3V logic. If the PWM pulse is 3V max you will never get full fan speed. Not if you drive the fan directly from the PWM pin.

Hey, I’m a retired tech too. Biomedical equipment.

My meaning was that it would alternate between 0 and 3.3v. I just was wondering whether the fan, designed for flat DC, would tolerate the quick changes in voltage. It might age faster. Maybe a 3.3v capacitor across the fan could flatten the voltage.

RE #2 I think I was not clear. What I intended to say was to apply the PWM control signal to the base of a NPN transistor to turn the 5vdc on/off.

I had not though about using a capacitor to smooth out the control signal. Would also remove any spikes tough I would guess the fan could handle those.

If I read correctly there are two ways to control the PWM control signal output by the PCA9685 on the Adafruit HAT/Bonnet.
a) The :dim a LED example use one library to control the duty cycle 0 to 0xffff (which I was thinking to use to control the fan)
b) To control a servo, a 1-2ms pulse ever ~20ms is used
Although it is not clear, I think I can control one channel of the PCA9685 with duty-cycle and the other 15 to drive servos.
Even with a capacitor I don’t think the 5 to10% duty-cycle of the servo control signal will provide enough difference to turn the 5vdc on/off without critical design - which I am not up to.

Using one of the channels from the PWM HAT has the real advantage of pulling the 5vdc @200ms from a separate 5vdc source and doesn’t load down the Pi 5vdc. It also gets everything to the fan/mounting board with a single plug… If all else fails I can use one of the few GPIO pins I have left to turn the 5vdc on/off.

Thanks for your additional thoughts.

I’m not sure if it will hurt it? It’s just a DC motor. I’d likely go with 5v 1000uf, if I was going to do it.

I was responsible for maintaining and repairing the ground based infrastructure used in civil aviation. Communications and navigation.

How you do it all depends on what you want to do?
If you just let the fan run continuous all you need is +5V and Ground. Easy way to do it.

If you want to turn it on and off, any GPIO Pin and your transistor will do that. No PWM needed. Get the temp of the CPU and decide what temp you want the fan on and off at and code up some python. I do believe that hat brings out some of the GPIO pins for other uses.

If you want to actually control the speed, then your going to want to use PWM, and likely your transistor too, to get 5V to the fan.

@alphanumeric 1000uf cap. Thanks

Yes continuous run is of course an option - boring, but an option. With little effort I can get the Pi 4 temperature up to 65 degrees C, the hard limit for internal throttling of CPU frequency/power. BUT control on/off of fan and monitoring temp and frequency - because I can. I am “re-purposing” the library for the FanShim for my application. The design includes a push button on a GPIO pin (manual/auto mode - press&hold and manual on/off - short press) with displaying status on Unicorn HAT HD using a few LEDs (4-5 step elevator for temp, plus other status).

The only reason to use the PWM vs a GPIO pin is neatness of wiring: external +5vdc, ground and control all on one plug from the HAT… Could do the same thing using a GPIO pin and taking the +5 from the Pi (as the FanShim does), but I am running out of pins. Currently I am using both I2C & SPI interfaces and 13 of the GPIOs. By my count there are 5 more easily available.

I had a Fan Shim on my Pi 4. I initially setup the Daemon to turn the fan on off based on temperature. Eventually I just ran it without any of the software and let the fan run continuous. My temps are a pretty constant around 40c. The LED I don’t use, I had a BLINKT showing temps. I eventually switched that to show CPU load. The Button by default will boot the Pi up if it was shut down and left powered. It grounds GPIO 3 when pressed. I also did a config.txt edit to have it also do a proper shutdown when pressed.
dtoverlay=gpio-shutdown,gpio_pin=17,active_low=1,gpio_pull=up

Later on I added a pull down resistor to GPIO 18 on the fan shim to turn the fan off by default. If I do a shutdown with the button the fan now turns off. without the pull down resistor it just keeps running until you unplug the power supply. Not what i wanted. The downside is it now has to be commanded on. That I did with another config.txt edit.
dtoverlay=gpio-fan,gpiopin=18,temp=35000
It turns on at 35c now.

EDIT: I said “had” because that Pi 4 in now in a SmartiPi V2 case, that comes with a cooling fan. I found it a bit on the noisy side and connected it to 3.3V instead of 5V. I hardly notice it now and my temps are just a tad over 40c. I am considering switching the stock fan out for the fan shim though.

Just FYI, the Fan Control Pin on the Fan Shim is pulled “low” to turn it “off”. Keep that in mind when using the fan shim code etc. I think it was done this way so the default failsafe condition is fan on. The Damon pulls that pin low to turn the fan off. The downside, for me anyway, is when you shutdown the fan starts up, even if it was off when you shutdown. And stays running until you unplug your power supply. It also starts up right away when you power up the Pi, and keeps running until the daemon loads and takes control.

I should also mention, that adding that 1000uf capacitor will slow down the response to speed changes. It will slow down changes in voltage levels. Just don’t be surprised that speed changes are delayed abit when your testing your code.