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() {
  pinMode(D1, OUTPUT);

void loop() {
  if (Serial.available() > 0) {
    char cmd =;
    int level = (int)(cmd - '0');
    if (level < 0 || level > 9) level = 0;
    analogWrite(D1, level/9.0*255);
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...
Installing coreutils (9.1-1) to root...
Configuring coreutils.
Configuring coreutils-stty.

Then I created a shell script in the /storage folder called

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

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

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

*/1 * * * * /storage/

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


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.

Filament Joiner Part 2 (With Display and Knob)

Thanks to the current corona-virus crisis, the parts I ordered for the filament joiner project were taking forever to arrive. But now that they have finally arrived, I can put them to good use. These were the parts ordered: 0.96" OLED display SSD1306 Rotary switch encoder KY-040 Here is the final circuit diagram: The OLED display is connected to the SDA and SCL pins of the Nano (A4 and A5 respectively), and powered by 5V and GND. The rotary switch encoder is connected as follows: VCC => 5V GND = > GND CLK => D9 DT => D8 SW => D2 My prototype board now looks like this: The updated code for driving the knob and display is available in  heater-with-display.ino in the Github repository . We now have a fairly compact (about 7cm x 5cm) and independent filament joiner (no need to connect to PC) that is driven solely by a 12V power supply. Here's how to use it to join printer filaments. More usage details in my previous post .

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