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

Adding "Stereo Mixer" to Windows 7 with Conexant sound card

This procedure worked for my laptop (Thinkpad E530) with a Conexant 20671 sound card, but I suspect it will work for other sound cards in the Conexant family. I was playing with CamStudio to do a video capture of a Flash-based cartoon so that I can put it on the WDTV media player and play it on the big screen in the living room for my kids. The video capture worked brilliantly, but to do a sound capture, I needed to do some hacking. Apparently, there was this recording device called "Stereo Mixer" that was pretty standard in the Windows XP days. This allowed you to capture whatever was played to the speaker in all its digital glory. Then under pressure from various organizations on the dark side of the force, Microsoft and soundcard makers starting disabling this wonderful feature from Windows Vista onwards. So after much Googling around, I found out that for most sound cards, the hardware feature is still there, just not enabled on the software side. Unfortunately, to

Hacking a USB-C to slim tip adapter cable to charge the Thinkpad T450s

This hack is inspired by this post . A year ago, I bought an adapter cable for my wife's Thinkpad X1 Carbon (2nd Gen) that allows her to power her laptop with a 60W-capable portable battery (20V x 3A). A USB-C cable goes from the battery into the adapter, which converts it to the slim tip output required by the laptop. Everything works out of the box, so I didn't give much thought about it. Recently, I decided to buy a similar cable for my Thinkpad T450s. I know technically it should work because the T450s can go as low as 45W (20V x 2.25A) in terms of charging (though I have the 65W charger - 20V x 3.25A).  I went with another adapter cable because it was cheaper and also I prefer the single cable design. So imagine my surprise when the cable came and I plugged it into my laptop and it didn't work! The power manager just cycle in and out of charging mode before giving up with an error message saying there is not enough power. After much research and reading the Thinkwiki

Using Google Dashboard to manage your Android device backup

I used to use AppBrain/Fast Web Install to keep track of which apps I have installed on my phone, and to make it easier to reinstall those apps when the phone gets wiped or replaced. But AppBrain had been going down the tubes, and Fast Web Install had always been a hit-and-miss affair. Android's own "backup to the cloud" system had previously been even more unusable. There isn't a place where you can see what has been backed up. And when you setup a new phone with your Google account, you just have to wait and pray that your favorite apps will be restored to the phone. Typically all the stars have to be aligned just right for this to happen. More often than not, after waiting for an hour or so and nothing happens, you just curse under your breath and proceed to install your favorites apps manually via the Play Store. But I just looked again recently and was pleasantly surprised that things are much more civilized now. Firstly there is a place now where you can loo