WiringPi Pin = WPP
Fonction | WPP | Name | Header | Name | WPP | Fonction | |
---|---|---|---|---|---|---|---|
mlx90614 pwr | 3.3v | 1 | 2 | 5v | |||
mlx90614 SDA (pull up on pi board) | 8 | SDA | 3 | 4 | 5v | ||
mlx90614 SCL (pull up on pi board) | 9 | SCL | 5 | 6 | 0v | ||
7 | GPIO7 | 7 | 8 | TxD | 15 | ||
mlx90614 gnd | 0v | 9 | 10 | RxD | 16 | ||
0 | GPIO0 | 11 | 12 | GPIO1 | 1 | ||
2 | GPIO2 | 13 | 14 | 0v | |||
3 | GPIO3 | 15 | 16 | GPIO4 | 4 | ||
3.3v | 17 | 18 | GPIO5 | 5 | |||
12 | MOSI | 19 | 20 | 0v | |||
13 | MISO | 21 | 22 | GPIO6 | 6 | ||
14 | SCLK | 23 | 24 | CE0 | 10 | ||
0v | 25 | 26 | CE1 | 11 |
//gcc mlx90614.c -o mlx90614 -l bcm2835 #include <stdio.h> #include <bcm2835.h> #include <stdlib.h> #include <fcntl.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <time.h> #define AVG 1 //averaging samples # include <termios.h> char getch(){ char buf=0; fflush(stdout); if(read(0,&buf,1)<0) perror("read()"); return buf; } int main(int argc, char **argv) { unsigned char buf[6]; unsigned char i,reg; double temp=0,calc=0, skytemp,atemp,sky_temp_average_double,sky_temp_sum_double=0; unsigned int G_nb_sample_uint16=0; char c_command; //pas d'attente et pas d'echo sur getch struct termios old={0}; if(tcgetattr(0, &old)<0) perror("tcsetattr()"); old.c_lflag&=~ICANON; old.c_lflag&=~ECHO; old.c_cc[VMIN]=0; old.c_cc[VTIME]=0; if(tcsetattr(0, TCSANOW, &old)<0) perror("tcsetattr ICANON"); bcm2835_init(); bcm2835_i2c_begin(); bcm2835_i2c_set_baudrate(25000); // set address bcm2835_i2c_setSlaveAddress(0x5a); printf("x : exit\nr : RAZ moyenne\nconnected to MLX90614 \n"); while(c_command != 'x') { calc=0; reg=7; for(i=0;i<AVG;i++) { bcm2835_i2c_begin(); bcm2835_i2c_write (®, 1); bcm2835_i2c_read_register_rs(®,&buf[0],3); temp = (double) (((buf[1]) << 8) + buf[0]); temp = (temp * 0.02)-0.01; temp = temp - 273.15; calc+=temp; } skytemp=calc/AVG; calc=0; reg=6; for(i=0;i<AVG;i++){ bcm2835_i2c_begin(); bcm2835_i2c_write (®, 1); bcm2835_i2c_read_register_rs(®,&buf[0],3); temp = (double) (((buf[1]) << 8) + buf[0]); temp = (temp * 0.02)-0.01; temp = temp - 273.15; calc+=temp; } atemp=calc/AVG; if (c_command == 'r') {sky_temp_sum_double=0; G_nb_sample_uint16=0;} sky_temp_sum_double += skytemp; G_nb_sample_uint16++; sky_temp_average_double = sky_temp_sum_double/G_nb_sample_uint16; printf("Ambient Temp=%04.2f Object Temp=%04.2f Moyenne Object Temp=%04.2f\r", atemp,skytemp,sky_temp_average_double); c_command = getch(); sleep(1); } //restore setting of getch old.c_lflag|=ICANON; old.c_lflag|=ECHO; if(tcsetattr(0, TCSADRAIN, &old)<0) perror ("tcsetattr ~ICANON"); printf("\r\n"); return 0; }
données Gris mlx(IR) mlx(internal) 20 21.8 21.65 21.8 24.76 24.42 18.5 21.2 19.72 25.6 28.4 26.9 29.2 31.30 31 11 9.6 9.6 amb_temp_f = ((amb_temp_f_ar[0]+amb_temp_f_ar[1]+amb_temp_f_ar[2])/3)-1.6; //1.6 correctif : moyenne sans MIN et MAX obj_temp_f = ((obj_temp_f_ar[0]+obj_temp_f_ar[1]+obj_temp_f_ar[2])/3)-2.5; //2.5 correctif : moyenne sans MIN et MAX