Skip to main content

Cooling mod for the X96 Air #2

Previously, I added a USB cooling fan to the X96 Air TV box. The problem with this mod is that the fan is always running, and it runs at full speed. Ideally, the fan should kick in only when the CPU temperature is above a certain threshold. It would be even better if there is a way to control the fan speed.

Dan McDonald left me a comment pointing to his project on Github. He basically connected the fan to a USB relay that can be controlled by Python script. His project inspired me to make a similar mod that would make use of the spare D1 Mini boards I have lying around.

The plan is to hook up the fan to a MOSFET (2N7000) and control it via PWM. Here's the very simple circuit:

The code simply reads a single character from the serial port (0 - 9). 0 will turn the fan off, while 1 - 9 will generate a proportional PWM to drive the fan, with 1 being the lowest and 9 being the highest.

Here's the Arduino code:
#include <Arduino.h>

void setup() {
  Serial.begin(9600);
  pinMode(D1, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    char cmd = Serial.read();
    int level = (int)(cmd - '0');
    if (level < 0 || level > 9) level = 0;
    analogWrite(D1, level/9.0*255);
  }
  delay(100);
}
The code was verified to work correctly with a breadboard circuit and the serial monitor.

Here's the prototype board that I put together in a hurry:


I re-used the same fan, but connected a 2-pin JST header to it instead.


Here it is sitting under the X96 Air:


Printed a 3D casing for the prototype board:


This is with everything hooked up:


I did hit a little snufu when I tried to get it working on the X96 Air box itself. The D1 Mini uses the CH340 USB-to-serial module, which I had problems getting to work on the box (CoreELEC 19.4). The D1 Mini was receiving gibberish from the box, and I spent many hours trying to fix it. Eventually I concluded it was the CH340 driver included with this kernel, because it had zero problems working with the CP210X.

I had 2 options: recompile the kernel with an updated CH340 driver, or find a board that uses the CP210X. Luckily, I have a D1 Mini Pro lying around that uses the CP2104, and it was pin-compatible with the D1 Mini. So I simply did a board swap, and everything suddenly worked smoothly!

List all the USB devices connected to the X96 Air:
CoreELEC:~ # lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
Bus 001 Device 003: ID 1915:af11 Nordic Semiconductor ASA Wireless Receiver
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Unfortunately, setserial does not work to configure the USB-serial port:
CoreELEC:~ # setserial /dev/ttyUSB0
setserial: can't get serial info: Inappropriate ioctl for device
We need to install stty, but to do that, we need to install Entware support:
CoreELEC:~ # installentware
...
...
Would you like to reboot now to finish installation (recommended) [y/N]? y

After reboot, we can install the stty package:

CoreELEC:~ # opkg install coreutils-stty
Installing coreutils-stty (9.1-1) to root...
Downloading http://bin.entware.net/aarch64-k3.10/coreutils-stty_9.1-1_aarch64-3.10.ipk
Installing coreutils (9.1-1) to root...
Downloading http://bin.entware.net/aarch64-k3.10/coreutils_9.1-1_aarch64-3.10.ipk
Configuring coreutils.
Configuring coreutils-stty.

Then I created a shell script in the /storage folder called cpufan.sh:

#!/usr/bin/sh
$(stty -F /dev/ttyUSB0 9600 cs8 -cstopb -parenb)
val=$(/usr/bin/cputemp | /usr/bin/sed 's/[^0-9]*//g')
if [ $val -ge 55 ]
then
  echo -n 5 > /dev/ttyUSB0
else
  echo -n 0 > /dev/ttyUSB0
fi

At the moment, the script is very simple. It configures the serial port to 9600/8N1, and retrieves the CPU temperature using cputemp. If the CPU temperature is >= 55c, it sets the fan speed to 5. Otherwise, it turns it off.

Remember to make the script executable by using:

chmod a+x cpufan.sh

Finally, I run the script every minute by adding it to crontab:

*/1 * * * * /storage/cpufan.sh

This command is very helpful to check if the script is being run by cron, and whether there are any execution errors:

systemctl status cron

This command is useful for stressing the CPU quickly and raising its temperature:

stress-ng --matrix 0 -t 5m

Comments

Post a Comment

Popular posts from this blog

Update: Line adapter for Ozito Blade Trimmer

Update (Dec 2021): If you access to a 3D printer, I would now recommend this solution , which makes it super easy to replace the trimmer line. I have been using it for a few months now with zero issue.

Line adapter for Ozito Blade Trimmer

This is an adapter for Ozito 18V battery trimmer (and possibly some Bosch trimmers as well) that uses a plastic blade for cutting. It lets you insert a 2.4mm trimmer line (about 8cm long) and use that for cutting. Simply cut a length of trimmer line and briefly heat up one end with a lighter so that a little bulb is formed. Then insert the trimmer line into the adapter and slot that into the trimmer as per normal. Make sure the trimmer line is not so long that it touches the safety guard. If that is the case, simply trim off any excess with a cutter or scissors. This part is best printed using PETG, which is a tougher and more flexible material. PLA is more rigid and breaks more easily. However, even with PETG, it will still break when it hits something really hard. Since this takes only 0.5m of material and 15 minutes to print, I will usually print a batch of nine at a time at very little cost. The blades that they sell do not break when it hits a hard object, but ...

Cooling mod for the X96 Air

I realized after my Ugoos box died that overheating is a big problem with cheap Android TV boxes. A teardown of the Ugoos box shows that it does not have any heatsink or fan at all!  The X96 Air does have a heatsink, but the heatsink is located at the bottom of the casing with no ventilation. In this default configuration, with the ambient room temperature at 25c and playing a 1080p video, I was seeing the CPU temperature at 67c. I drilled a couple of holes at the bottom of the casing. The CPU temperature fell to 59c with the box raised about 2cm with plastic blocks. I retrieved an old 5V laptop fan: Then cut and strip away a spare USB cable: Solder the red and black wires on the fan and the cable: Secure the fan to the bottom of the casing with double-sided tape, then plug the fan into the box's USB connector. Here's a view of the box with some 3D-printed risers installed at the bottom to give the mounted fan sufficient clearance: The CPU now runs at 43c, a huge drop from the ...