We're no longer updating This wiki!!

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
en:xu3_weather_board [2015/04/30 14:38]
john1117
en:xu3_weather_board [2015/07/26 12:16]
charles.park
Line 1: Line 1:
 +====== Using the temperature & humidity sensor with H/W I2C ======
  
 +We tested to read si702x sensor with H/W I2C.
 +
 +{{http://​dn.odroid.com/​wiki_image/​xu3_si702x_2.jpg}}
 +
 +{{http://​dn.odroid.com/​wiki_image/​pinmap.png}}
 +
 +Open /​etc/​modprobe.d/​blacklist.conf file and add drivername using following syntax:
 +  blacklist ioboard_bh1780
 +  blacklist ioboard_bmp180
 +  blacklist ioboard_keyled
 +
 +Reboot
 +  sudo reboot
 +
 +Compile & Run
 +  gcc -o ex_si702x ex_si702x.c
 +
 +<​code>​
 +odroid@odroid:​~$ sudo ./ex_si702x
 +Temperature : 28.64 °C
 +Humidity : 43.62 %
 +</​code>​
 +
 +<file c ex_si702x.c>​
 +#include <​stdio.h> ​                                                             ​
 +#include <​fcntl.h> ​                                                             ​
 +#include <​linux/​i2c-dev.h> ​                                                     ​
 +                                                                                ​
 +#define CMD_MEASURE_TEMPERATURE_HOLD ​   0XE3                                    ​
 +#define CMD_MEASURE_HUMIDITY_HOLD ​      ​0xE5 ​                                   ​
 +#define SI702X_ADDRESS ​                 0x40                                    ​
 +                                                                                ​
 +int main(void) ​                                                                 ​
 +{                                                                               
 +        unsigned char rbuf[2]; ​                                                 ​
 +        unsigned char wbuf[1]; ​                                                 ​
 +        double temperature = 0;                                                 
 +        double humidity = 0;                                                    ​
 +        int status = 0;                                                         
 +                                 
 +        // Net name I2C_1 Physical address : 0x12C70000
 +        int fd = open("/​dev/​i2c-3",​ O_RDWR); ​                                   ​
 +        if (fd < 0) {                                                           
 +                printf("​ERROR:​ open failed\n"​); ​                                
 +                return -1;                                                      ​
 +        }                                                                       
 +                                                                                ​
 +        status = ioctl(fd, I2C_SLAVE, SI702X_ADDRESS); ​                         ​
 +        if (status < 0) {                                                       
 +                printf("​ERROR:​ ioctl error\n"​); ​                                
 +                close(fd); ​                                                     ​
 +                return -1;                                                      ​
 +        }                                                                       
 +                                                                                ​
 +        wbuf[0] = CMD_MEASURE_TEMPERATURE_HOLD; ​                                
 +        write(fd, wbuf, 1);                                                     
 +        if (read(fd, rbuf, 2) != 2)                                             
 +                printf("​Failed to read from the i2c bus.\n"​); ​                  
 +                                                                                ​
 +        temperature = rbuf[1] | rbuf[0] << 8;                                   
 +        printf("​Temperature : %.2lf *C\n", (temperature*175.72/​65536) - 46.85) ;
 +                                                                                ​
 +        wbuf[0] = CMD_MEASURE_HUMIDITY_HOLD; ​                                   ​
 +        write(fd, wbuf, 1);                                                     
 +        if (read(fd, rbuf, 2) != 2)                                             
 +                printf("​Failed to read from the i2c bus.\n"​); ​                  
 +                                                                                ​
 +        humidity = rbuf[1] | rbuf[0] << 8;                                      ​
 +        printf("​Humidity : %.2lf %%\n", (humidity*125.0/​65536) - 6);            ​
 +                                                                                ​
 +        close(fd); ​                                                             ​
 +}
 +</​file>​
en/xu3_weather_board.txt · Last modified: 2017/01/06 15:05 by john1117
CC Attribution-Share Alike 3.0 Unported
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0