Fan HAT mais ne tourne pas

Bonjour
J’ai acheté une jolie carte ventilateur régulé avec affichage, le Fan HAT de Waveshare entreprise chinoise garantie. J’ai l’affichage mais le ventilateur ne veut pas tourner. Vu que l’installation n’est proposée que pour les RaspberrypiOS et que l’utilisation faite est sous ubuntu 22.04 (pour cause ROS2) le sav a été désolé de m’annoncer qu’il ne pouvait rien pour moi.
Il y a deux programes, l’un en c main.c et l’autre en python main.py et les deux comportent l"originalité d’avoir la même erreur de test de température
si temp >40 alors

sinon si temp > 50 alors

sinon si temp > 55 alors


Ce qui fait qu’on peut avoir quelques doutes sur le reste de l’écriture.
Donc une fois le test de température remis dans le bon ordre et qu’on a verifié que le programme passe bien à la bonne commande PWM on ne peut que constater que le ventilo ne tourne jamais.
ci-dessous le programme en c et en python

moi@rpi4b-u2204d-turtlebot4:~/Fan_HAT/c$ cat examples/main.c
#include <stdio.h> //printf()
#include <stdlib.h> //exit() atoi()
#include <signal.h> //signal()
#include <time.h>

#include « …/lib/Config/DEV_Config.h »
#include « …/lib/PWM/PCA9685.h »
#include « …/lib/Device/OLED.h »
#include « …/lib/GUI/GUI_Paint.h »

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>

#define MAXLINE 1024
int Get_ip(char *buf)
{
char result_buf[MAXLINE];
char command[MAXLINE];
int rc = 0;
FILE *fp;

snprintf(command, sizeof(command), « ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk ‹ {print $2} ›|tr -d "addr:" »);

fp = popen(command, « r »);
if(NULL == fp) {
perror(« popen failed! »);
exit(1);
}

while(fgets(result_buf, sizeof(result_buf), fp) != NULL) {
if(‹ \n › == result_buf[strlen(result_buf)-1]) {
result_buf[strlen(result_buf)-1] = ‹ \0 ›;
}
// printf(« %s\r\n », result_buf);
}

rc = pclose(fp);
if(-1 == rc) {
perror(« close failed »);
exit(1);
}

strcpy(buf, result_buf);
// printf(« buf = %s\r\n », buf);
return rc;
}

#define TEMP_PATH « /sys/class/thermal/thermal_zone0/temp »
#define MAX_SIZE 32
static double Get_CPU_Temp(void)
{
int fd;
double temp = 0;
char buf[MAX_SIZE];

// open /sys/class/thermal/thermal_zone0/temp
fd = open(TEMP_PATH, O_RDONLY);
if (fd < 0) {
fprintf(stderr, « failed to open thermal_zone0/temp\n »);
return -1;
}

// read value
if (read(fd, buf, MAX_SIZE) < 0) {
fprintf(stderr, « failed to read temp\n »);
return -1;
}

temp = atoi(buf) / 1000.0;
close(fd);
return temp;
}

void Handler(int signo)
{
//System Exit
printf(« \r\nHandler:exit\r\n »);
// DEV_ModuleExit();
PCA9685_setPWM(0, 0);

exit(0);
}

int main(void)
{
printf(« fan hat\r\n »);

// Exception handling:ctrl + c
signal(SIGINT, Handler);
DEV_ModuleInit();
DEV_I2C_Init();

PCA9685_Init(1000);
PCA9685_setPWM(0, 100);

printf(« oled init\r\n »);
OLED_Init();
OLED_Clear();

//Create a new image cache
UBYTE *Image;
UWORD Imagesize = SSD1306_WIDTH * SSD1306_HEIGHT;
printf(« image cache need size = %d byte\r\n », Imagesize);
if((Image = (UBYTE *)malloc(Imagesize)) == NULL) {
printf(« Failed to apply for black memory…\r\n »);
return -1;
}
Paint_NewImage(Image, SSD1306_WIDTH, SSD1306_HEIGHT, 0, BLACK);
Paint_SetRotate(ROTATE_180);
Paint_Clear(BLACK);

//get ip
char IP_buf[20];// xxx.xxx.xxx.xxx

//get temp
double temp = 0;
char str[5];

Paint_DrawString_EN(1, 15, IP_buf, &Font12, BLACK, WHITE);
OLED_Display(Image);
while(1){
Paint_Clear(BLACK);

  Get_ip(IP_buf);
  Paint_DrawString_EN(0, 0, "IP:", &Font12, BLACK, WHITE);
  Paint_DrawString_EN(25, 0, IP_buf, &Font12, BLACK, WHITE);
  
  temp = Get_CPU_Temp();	
  sprintf(str, "%.2f", temp);
  Paint_DrawString_EN(0, 15, "Temp:", &Font12, BLACK, WHITE);
  Paint_DrawString_EN(36, 15, str, &Font12, BLACK, WHITE);
  Paint_DrawString_EN(75, 15, "o", &Font8, BLACK, WHITE);
  Paint_DrawString_EN(80, 15, "C", &Font12, BLACK, WHITE);
  
  OLED_Display(Image);
  if(temp > 65){
  	PCA9685_setPWM(0, 100);
  }else if(temp > 60){
  	PCA9685_setPWM(0, 90);
  }else if(temp > 55){
  	PCA9685_setPWM(0, 75);
  }else if(temp > 50){
  	PCA9685_setPWM(0, 50);
  }else if(temp > 40){
  	PCA9685_setPWM(0, 40);
  }else{
  	PCA9685_setPWM(0, 0);
  }
  DEV_Delay_ms(1000);

}

printf(« stop\r\n »);

//System Exit
DEV_ModuleExit();
return 0;
}

moi@rpi4b-u2204d-turtlebot4:~/Fan_HAT/c$

.

moi@rpi4b-u2204d-turtlebot4:~/Fan_HAT/python$ cat main.py
#!/usr/bin/python

-- coding:utf-8 --

import SSD1306
import PCA9685
import time
import traceback
import socket
import threading
import os
from PIL import Image,ImageDraw,ImageFont

try:
oled = SSD1306.SSD1306()

pwm = PCA9685.PCA9685(0x40, debug=False)
pwm.setPWMFreq(50)
pwm.setServoPulse(0,100)

Initialize library.

oled.Init()
oled.ClearBlack()

Create blank image for drawing.

image1 = Image.new(‹ 1 ›, (oled.width, oled.height), « WHITE »)
draw = ImageDraw.Draw(image1)
font = ImageFont.load_default()
while(1):
draw.rectangle((0,0,128,32), fill = 1)
# get ip
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((‹ 8.8.8.8 ›, 80))
localhost = s.getsockname()[0]
print(« ip:%s » %localhost)
draw.text((0,0), « IP: », font=font, fill = 0)
draw.text((20,0), localhost, font=font, fill = 0)

  # get temp
  draw.text((0,16), "Temp(Celsius):", font=font, fill = 0)
  file = open("/sys/class/thermal/thermal_zone0/temp")  
  temp = float(file.read()) / 1000.00  
  temp = float('%.2f' % temp)
  file.close()
  print("temp : %.2f" %temp)
  draw.text((85,16), str(temp), font=font, fill = 0)
  
  if(temp > 65):
  	pwm.setServoPulse(0,100)
  elif(temp > 60):
  	pwm.setServoPulse(0,90)
  elif(temp > 55):
  	pwm.setServoPulse(0,75)
  elif(temp > 50):
  	pwm.setServoPulse(0,50)
  elif(temp > 40):
  	pwm.setServoPulse(0,40)
  else:
  	pwm.setServoPulse(0,0)
  #show
  oled.ShowImage(oled.getbuffer(image1.rotate(180)))
  time.sleep(1)

except IOError as e:
oled.Closebus()
print(e)

except KeyboardInterrupt:
print(« ctrl + c: »)
oled.Closebus()
moi@rpi4b-u2204d-turtlebot4:~/Fan_HAT/python$

Les deux programmes une fois lancés affichent ip du raspberrypi et température CPU

J’ai refait l’installation comme indiquée dans https://www.waveshare.com/wiki/Fan_HAT et ça fonctionne
conclusion : j’ai encore une fois loupé une marche.

Bonjour,
Bonne nouvelle.
Amusez vous bien.
A+