jetson-pwm-fan-control-10.ino
Controls fan speed via PWM signal based on the Jetson module's CPU temperature.
Uses the dedicated PWM connector on the Xerxes Nano. Install 'Jetson.GPIO' or ensure 'RPi.GPIO' is configured for Jetson pin numbers. The script reads system thermal temperature and adjusts the duty cycle. Check the polarity and voltage (3.3V or 5V) of the fan connector used.
jetson-pwm-fan-control-10.ino
import RPi.GPIO as GPIO
import time
import subprocess
import re
# Configuration PWM
# Sur Jetson, les broches GPIO sont mappées différemment.
# Supposons l'utilisation de la bibliothèque Jetson.GPIO ou RPi.GPIO compatible.
# Le connecteur PWM de la Xerxes Nano est généralement lié à un pin spécifique.
PWM_PIN = 18 # Ajuster selon le schéma Xerxes Nano pour le header PWM
def get_cpu_temp():
# Lecture via thermal zone
try:
with open('/sys/class/thermal/thermal_zone0/temp', 'r') as f:
temp = int(f.read()) / 1000.0
return temp
except:
return 0.0
def set_fan_speed(pwm_pin, duty_cycle):
try:
GPIO.output(pwm_pin, duty_cycle)
except Exception as e:
print(f"Erreur PWM: {e}")
if __name__ == "__main__":
GPIO.setmode(GPIO.BCM)
GPIO.setup(PWM_PIN, GPIO.OUT)
pwm = GPIO.PWM(PWM_PIN, 20000) # 20kHz PWM
pwm.start(0)
try:
while True:
temp = get_cpu_temp()
# Logique de contrôle simple
if temp < 40.0:
duty = 20 # 20%
elif temp < 60.0:
duty = 50 # 50%
elif temp < 75.0:
duty = 80 # 80%
else:
duty = 100 # 100%
set_fan_speed(PWM_PIN, duty)
print(f"Temp: {temp:.1f}C | Fan Duty: {duty}%")
time.sleep(2)
except KeyboardInterrupt:
pass
finally:
pwm.stop()
GPIO.cleanup()