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.

Attiny85 timer programming using Timer1

This Arduino sketch uses Timer1 to drive the LED blinker: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 /* * Program ATTiny85 to blink LED connected to PB1 at 1s interval. * Assumes ATTiny85 is running at 1MHz internal clock speed. */ #include <avr/io.h> #include <avr/wdt.h> #include <avr/sleep.h> #include <avr/interrupt.h> bool timer1 = false , led = true ; // Interrupt service routine for timer1 ISR(TIMER1_COMPA_vect) { timer1 = true ; } void setup() { // Setup output pins pinMode( 1 , OUTPUT); digitalWrite( 1 , led); set_sleep_mode(SLEEP_MODE_IDLE); // Setup timer1 to interrupt every second TCCR1 = 0 ; // Stop timer TCNT1 = 0 ; // Zero timer GTCCR = _BV(PSR1); // Reset prescaler OCR1A = 243 ; // T = prescaler / 1MHz = 0.004096s; OCR1A = (1s/T) - 1 = 243 OCR1C = 243 ; // Set to same value to reset timer1 to

3D Printer Filament Joiner

I have been looking at various ways of joining 3D printing filaments. One method involves running one end of a filament through a short PTFE tubing, melting it with a lighter or candle, retracting it back into the tubing and immediately plunging the filament to be fused into the tubing: One problem with this method is that you can't really control the temperature at which you melt the filament, so you frequently end up with a brittle joint that breaks upon the slightest bend. Aliexpress even sells a contraption that works along the same line. As it uses a lighter or candle as well, it suffers from the same weakness. I am not even sure why you need a special contraption when a short PTFE tubing will work just as well. Another method involves using shrink tubing/aluminium foil, and a heat gun: But a heat gun is rather expensive, so I wanted to explore other alternatives. The candle + PTFE tubing method actually works quite well when you happen to melt it at the rig