# ..code needed to read from fan tacho output for rpi-4

**URL:** <https://forum.core-electronics.com.au/t/code-needed-to-read-from-fan-tacho-output-for-rpi-4/9097>\
**Category:** Raspberry Pi\
**Created:** [3 January 2021 18:10 UTC](https://forum.core-electronics.com.au/t/code-needed-to-read-from-fan-tacho-output-for-rpi-4/9097 "2021-01-03T18:10:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian86770](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@brian86770](https://forum.core-electronics.com.au/u/brian86770)\
**Post date:** [3 January 2021 18:10 UTC](https://forum.core-electronics.com.au/t/code-needed-to-read-from-fan-tacho-output-for-rpi-4/9097/1 "2021-01-03T18:10:47Z")

</div>

all i need is a basic program that can read from the yellow r.p.m output of the fan  
that uses a gpio pin/s to read the signal…  
and display in text …the fan speed in a terminal with constant refresh…thx  
either user or root permission …  
using a noctua 40x40x10 5 volt  
also if possible a twin or triple gpio pin configuration allowing for extra fans would be good…  
that i can either edit manually or on screen menu to adjust for extra fan`s …scale 0-10000

# EXAMPLE BELOW…

FAN ONE R.P.M = FAN SPEED

FAN TWO R.P.M=FAN SPEED

FAN THREE R.P.M=\<FAN SPEED

===============================================

ENGAGE FAN SELECTION selet 1 2 3 to change status

1:ON/OFF= gpio-pin=status=on

2: OM/OFF= gpio-pin=status=off

3 : ON/OFF= gpio-pin=status=off

===============================================

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [3 January 2021 21:53 UTC](https://forum.core-electronics.com.au/t/code-needed-to-read-from-fan-tacho-output-for-rpi-4/9097/2 "2021-01-03T21:53:24Z")

</div>

Hi @brian86770,  
Reading PWM frequency is a bit fraught on a Raspberry Pi since it cannot guarantee precise timing like a real-time microcontroller can ([source](https://raspberrypi.stackexchange.com/questions/9787/pwm-input-in-raspberry-pi#:~:text=The%20short%20answer%3A%20You%20CANNOT,without%20tinkering%20with%20kernel%20modules.)). _However_ the frequency you’d expect out of a fan could be low enough that it’s not a problem.

There’s a [pigpio example](https://www.raspberrypi.org/forums/viewtopic.php?t=139863) linked on another forum topic that may help you.

---

<div class="post-metadata">

**Author:** ![brian86770](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@brian86770](https://forum.core-electronics.com.au/u/brian86770)\
**Post date:** [3 January 2021 23:29 UTC](https://forum.core-electronics.com.au/t/code-needed-to-read-from-fan-tacho-output-for-rpi-4/9097/3 "2021-01-03T23:29:40Z")

</div>

accurate to 100 rpm would be ok. if any body can do this for me i see that diagram of converting it to an analog voltage reference as the sorce 4.7k and 100nf to ground then connecting it to the gpio pin…i see also on that pasge several progam codes…i will post on another forum.i dont know how to code very well…thank you for the links…

---

<div class="post-metadata">

**Author:** ![brian86770](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@brian86770](https://forum.core-electronics.com.au/u/brian86770)\
**Post date:** [6 January 2021 10:20 UTC](https://forum.core-electronics.com.au/t/code-needed-to-read-from-fan-tacho-output-for-rpi-4/9097/4 "2021-01-06T10:20:58Z")

</div>

ok so since i am not an avid coder could anybody else write me a program …pls …to the specs i want if only one fan can be shown then that is ok,

---

<div class="post-metadata">

**Author:** ![brian86770](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@brian86770](https://forum.core-electronics.com.au/u/brian86770)\
**Post date:** [8 January 2021 16:49 UTC](https://forum.core-electronics.com.au/t/code-needed-to-read-from-fan-tacho-output-for-rpi-4/9097/5 "2021-01-08T16:49:59Z")

</div>

i got this page to help with but am unshure exactly how to go about it all i need to do is read the tacho output of the fan not power it…one gpio enabled would do the trick but the program i`m unshure of…

[https://www.domoticz.com/wiki/Raspberry\_pi\_fan\_control\_and\_monitoring\_with\_bash](https://www.domoticz.com/wiki/Raspberry_pi_fan_control_and_monitoring_with_bash)

i can switch between fans with an rotary switch …manually
