습도 온도 센서 SHT3x sample code
본 글은 linux에서 i2c dev를 사용한 습도 온도 센서 SHT3x의 예제 코드를 싣고 있다. SHT3x의 자료는 아래 링크에서 찾아볼 수 있다. https://www.sensirion.com/kr/environmental-sensors/humidity-sensors/digital-humidity-sensors-for-various-applications/ 본들의 예제 코드는 single shot mode에서 온도 습도 데이터를 읽어오며, single shot mode에서의 커맨드와 온도 습도 변환 공식은 아래와 같이 datasheet를 참조 했다. [소스 코드] #include <pthread.h> #include <stdint.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <getopt.h> #include <fcntl.h> #include <string.h> #include <sys/types.h> #include <linux/i2c-dev.h> #include <linux/i2c.h> int open_dev(char *name, int address) { int fd = open(name,O_RDWR); if(fd <= 0) { perror("i2c open "); return 0; } if (ioctl(fd, I2C_SLAVE, address)<0) { perror("i2c set address "); close(fd); return 0; ...