Along the OrangePi 5b I got myself a case with a fan:

20230517_opi5_case.png

Now about this fan...

The Good

It cools things down.

The Bad

It's always on, no PWM (Pulse Width Modulation, ie fan speed control) so it's either always on, or you've got to power off the whole board.

The Ugly

It is.. loud. I mean, not very loud, but I've got this pi on my desktop and it's louder than my desktop computer.

The Solution

Simple script:

  • when the temperature raises above MAX_THRESHOLD: start the fan
  • when the temperature drops under MIN_THRESHOLD: stop the fan

This requires 2 piece of information:

  1. where to read temperature
  2. where to "write" the fan on and off

The Journey Is The Fun Part

Temperature Readouts

A quick google search yields /sys/class/thermal/thermal_zone0/temp and /etc/armbianmonitor/datasources/soctemp as reliable data sources for CPU temperature, in 10^-3 celcius. Good.

Fan Pins

Now to write the right pin on and off, this is going to take a little more research. Let's first look at the manual for the opi. It mentions using wiringOP to get someting like this:

20230517_wiringop_from_opi_manual.png

Thing is, I overwrote the wiringOP from the default android OS when I installed armbian. That's fine, searching for it online it's easy to find the github repo it comes from. Let's build it.

git clone https://github.com/orangepi-xunlong/wiringOP.git
cd ./wiringOP/
# support for the orangePi5 is in that branch
git checkout next
./build clean
./build
# builds for a few seconds...
sudo ./gpio/gpio readall

We get this interesting diagram:

+------+-----+----------+--------+---+   OPI5   +---+--------+----------+-----+------+
 | GPIO | wPi |   Name   |  Mode  | V | Physical | V |  Mode  | Name     | wPi | GPIO |
 +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+
 |      |     |     3.3V |        |   |  1 || 2  |   |        | 5V       |     |      |
 |   47 |   0 |    SDA.5 |     IN | 1 |  3 || 4  |   |        | 5V       |     |      |
 |   46 |   1 |    SCL.5 |     IN | 1 |  5 || 6  |   |        | GND      |     |      |
 |   54 |   2 |    PWM15 |     IN | 1 |  7 || 8  | 0 | IN     | RXD.0    | 3   | 131  |
 |      |     |      GND |        |   |  9 || 10 | 0 | IN     | TXD.0    | 4   | 132  |
 |  138 |   5 |  CAN1_RX |     IN | 1 | 11 || 12 | 1 | IN     | CAN2_TX  | 6   | 29   |
 |  139 |   7 |  CAN1_TX |     IN | 1 | 13 || 14 |   |        | GND      |     |      |
 |   28 |   8 |  CAN2_RX |     IN | 1 | 15 || 16 | 1 | IN     | SDA.1    | 9   | 59   |
 |      |     |     3.3V |        |   | 17 || 18 | 1 | IN     | SCL.1    | 10  | 58   |
 |   49 |  11 | SPI4_TXD |     IN | 1 | 19 || 20 |   |        | GND      |     |      |
 |   48 |  12 | SPI4_RXD |     IN | 1 | 21 || 22 | 1 | ALT1   | GPIO2_D4 | 13  | 92   |
 |   50 |  14 | SPI4_CLK |     IN | 1 | 23 || 24 | 1 | IN     | SPI4_CS1 | 15  | 52   |
 |      |     |      GND |        |   | 25 || 26 | 1 | IN     | PWM1     | 16  | 35   |
 +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+
 | GPIO | wPi |   Name   |  Mode  | V | Physical | V |  Mode  | Name     | wPi | GPIO |
 +------+-----+----------+--------+---+   OPI5   +---+--------+----------+-----+------+

I let you put them side by side (no really, pelican won't let me, I can't do it here), but they're the same info!

20230517_wiringop_from_opi_manual.png 20230517_26pin_headers.png

Another view from the manual this one:

20230517_26pin_headers_from_manual.png

The problem is that as you can see, the top right headers are the 5V ones we plug the fan to, and they don't have a GPIO entry number to control them. No way to turn that thing on and off then :/

All other pins seem to be 3.3V. So I would need to connect the 5V pin to something that I would control using another pin. Basically this is reimplementing having a 3rd PIN as with a PWM device. At this point, getting a PWM 5V fan like this one is the most straightforward path IMO.


Published

Category

blog

Tags