If you want values between x.0 and x.5 use this little improvement.
This reads 5 values. Every 100ms one, and after average them you get some nice 
temperature value each 500ms.

But its just an idea to improve the output ;)

n8 everybody

///////////////////////////////////////////////////////
        while(1)
        {
                temp05 = 0;
                
                for(i=0; i<5; i++)
                {
                        if ((rtc=ioctl(fd_i2c,_IO( ETRAXI2C_IOCTYPE, I2C_READ), 
&i2c_d))!=EI2CNOERRORS)  
                        {
                                close(fd_i2c);
                                printf( "Error %d on line %d\n",rtc,__LINE__);
                                return ( -1 );   
                        }
                        temp05 += (float)((i2c_d.rbuf[0]<<8 | i2c_d.rbuf[1]) >> 
7);
                        usleep(100000);
                }
                printf("Temperature: %3.1f°C\n", temp05/10);
        }
///////////////////////////////////////////////////////

Reply via email to