9/20/2023 0 Comments Fancontrol linux![]() # Export pwm0 if it's not available if then echo 0 > /sys/class/pwm/pwmchip0/export #!/bin/bash # Device references dev_temp =/sys/class/thermal/thermal_zone0/temp If you want to include RPM monitoring you'll need to install a GPIO library, such as WiringPi, and modify the script to count RPM pulses, and report these to Domoticz in a separate virtual sensor.Īssuming you have followed the instructions for activating the PWM hardware clock at boot, all you need to do is copy the script below into a new file on your Pi, change the "fan_idx" to the index of the Domoticz alert sensor you want to use for monitoring, and make it executable: Since it's not possible to do this from a Bash script, this functionality is not currently supported by the script featured here. Optionally, if you want to monitor the fan's rotational speed, connect a wire from an input pin on the Pi to the RPM pin on the stripboard, and activate its internal pull-up resistor. If it's a 5 V model, you can probably get away with powering it from the 5 V pin on the Pi, provided it has a sufficiently powerful PSU - in this case connect the GND input to one of the ground pins on the Pi, and VDC to the Pi's 5 V pin. If your fan is a 12 V model you'll need a separate 12 V power supply, which you connect to the GND and VDC inputs. To connect it up, run a wire from the PWM output pin on the Pi (the default is GPIO_18 for pwm0, though you can change this in /boot/config.txt) to the PWM input connector on the stripboard. You can connect this to an input pin on the RasPi if you want to read it, but you'll need to enable the internal pull-up resistor for it to work (the tachometer output on PC fans is an open collector). The "RPM" line is just a straight through connection, in case you want to use a 3-pin fan with tachometer output. You can build this on an 8x4 piece of stripboard: ![]() Nothing too complicated going on there Q1 will be switched on/off by the PWM signal from the Pi, C1 & D1 smooth out transients, while R1 keeps the MOSFET gate from floating. So we will need some external cicuitry to give it a bit more brawn: But an output pin on a Raspberry Pi is not powerful enough to directly drive a fan, nor is the voltage sufficient for most PC type fans, which tend to run on 12 V DC (though 5 V varieties also exist). Otherwise, you can hook up an LED with a small series resistor (270 Ω) between the PWM pin and a GND pin by modifying the "duty_cycle" value above you should see the light intensity change. If you have access to an oscilloscope, correct functioning of the hardware PWM can be verified by hooking it up to the pin you chose when enabling the overlay (pwm0 defaults to GPIO_18). Call it "Fan Status" for example, and make note of its index number (shown on the "Devices" page in Domoticz). To be able to monitor the fan status in Domoticz, you need to create a "virtual sensor" of the type "Alert". ![]() ![]() # Duty cycle can be changed while running echo 999999 > pwm0/duty_cycle # Export PWM channel 0 echo 0 > export # Set the period in nanoseconds echo 1000000 > pwm0/period # cd to the device location cd /sys/class/pwm/pwmchip0 Once you have installed and activated the pwm-with-clk.dtbo overlay linked to above, you should be able to test the PWM by doing (in a root shell): You could of course use a "soft" PWM instead, but these eat up precious CPU cycles, which seems unnecessary when you just want to change the speed of a fan - so this guide assumes the hardware PWM route. There is however an alternative Device Tree Overlay, which activates the hardware PWM clock for general use, see the following guide for how to install it: Using the Raspberry Pi hardware PWM timers. It is launched and runs independently, so that if Domoticz should stop running, for whatever reason, the script will continue to quietly do its thing, keeping your system cool.įirst you'll need to get the PWM activated, which unfortunately isn't as straightforward as one might think the hardware PWM clock is not initialised at boot, and by default only starts up when the on-board soundcard is in use. Note that this script is not dependent on Domoticz in any way other than for monitoring. The fan's status is monitored and logged in Domoticz (and in the syslog). If you're not using the on-board audio, you can take advantage of the hardware Pulse Width Modulation capabilities of the Raspberry Pi to control the speed of a small PC fan, based on the system temperature.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |