Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
5951901447 | 1 week ago |
@ -0,0 +1,21 @@
|
|||||||
|
#include <unistd.h> //i2c
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <linux/i2c-dev.h>
|
||||||
|
#include <i2c/smbus.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "htu21d.h"
|
||||||
|
|
||||||
|
// Reset function
|
||||||
|
int i2cReset(int fd){
|
||||||
|
if(ioctl(fd, I2C_SLAVE, ADDR)<0){
|
||||||
|
perror("Failed to open the I2C bus; reset\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
i2c_smbus_write_byte(fd, RESET);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// temperature
|
||||||
|
|
||||||
|
// humidity
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "htu21d.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
int fd;
|
||||||
|
char path[20];
|
||||||
|
snprintf(path, sizeof(path), "/dev/i2c-%d", 1); // 1 is the number of I2C bus
|
||||||
|
fd = open(path, O_RDWR);
|
||||||
|
if(fd<0){
|
||||||
|
perror("Unable to access I2C bus path\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
i2cReset(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue