my C1 in this period, is very hot so I decided to install a mini fan in addition to a copper heatsink. to control the fan, I realized a mini electronic circuit, using a transistor... than I wrote a simple program in C (sorry, I don't know python) in order to check the cpu temperature and to control the base of the transistor (I used a bjt) to start/stop the fan (in addition, with this system I could use a +12V fan instead a +5V... that I didn't have at home). finally I wrote a systemd service to auto-start the script at boot.
Code: Select all
[Unit]
Description=Fan Control
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/odroid/./.script/fan_control
[Install]
WantedBy=multi-user.target
Code: Select all
/*
============================================================================
Name : fan_control.c
Author : bcclsn
Version : 1.0
Copyright : null
Description : controlla l'accensione e lo spegnimento di una ventola tramite
transistor e pin gpio
============================================================================
*/
#include <wiringPi.h>
#define FTEMP "/sys/class/thermal/thermal_zone0/temp"
#define THRESHOLD 60000 // first two MSD (degree)
#define FORCED_ON 12 // 12 cycle
#define GPIO_PIN 1
int os_read_d(char *fname) { // thanks to vbextreme
FILE* fd = fopen(fname, "r");
if (fd == NULL) {
return -1;
}
char inp[64];
inp[0] = 0;
fgets(inp, 64, fd);
return strtoul(inp, NULL, 10);
}
void main(void) {
int temperature;
int counter = 0;
wiringPiSetup();
pinMode(GPIO_PIN, OUTPUT);
while(1) {
temperature = os_read_d(FTEMP);
if (temperature >= THRESHOLD) {
digitalWrite(GPIO_PIN, HIGH); // start the fan
counter = 0; // reset the counter
} else { // else if temperature is under the threshold
counter++; // start the counter
if (counter > FORCED_ON) { // after 12 cycle under the threshold (cycle * delay = one minute)
digitalWrite(GPIO_PIN, LOW); // stop the fan
}
}
delay(5000);
}
}
I compile the script using:
Code: Select all
gcc -o wpi_exam_led wpi_exam_led.c -lwiringPi -lwiringPiDev -lm -lpthread -lrt -lcrypt
now we came to the problem:
both when I start the script using systemd (or crontab) and when I start it manually (./fan) the fan starts correctly but after some time it stopps and the temperature goes up (+70 to +80 degree).
I don't understand the reason of the fan stop... I don't know how investigate the system.
can you help me?
thanks in advance
