Initial fork + minor fixes for BMP085 (mBar output) + shell scripts for ADS1115 and...
[i2c-telemetry.git] / pcf8574_3.c
1 /*
2     PCF8574_addr_byteout.c
3     ----------------------
4     Send address and byte to switch lines on 8 line port of i2c bus PCF8574
5     -----------------------------------------------------------------------
6
7       1) send the i2c address
8       2) send byte to set the 8 port lines on or off
9
10   usage :-  type with spaces but without the < >
11 <PCF8574_addr_byteout.c>  <address as decimal> <byte out value as decimal 0-255>
12
13 */
14
15 #include <stdio.h>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <sys/ioctl.h>
19 #include <linux/i2c.h>
20
21   int i2c;
22   int buf[1];
23   int address;
24
25 int main(int argc, char** argv)
26 {
27  if (argc != 3)   /* error if we are not getting just 2 inputs after the program name */
28  {
29   printf("Error. usage: %s i2c_chip_address byte_to_send_out\n", argv[0]);           
30  }
31
32 /* address is the first number after the program name */
33         address = atoi(argv[1]);
34
35 /* the byte to send out to the PC8574 is the second number */
36
37 /* place it into the first element of the buf array */
38         buf[0] = atoi(argv[2]);
39
40   i2c = open("/dev/i2c/0",O_RDWR); /* open the device on i2c-bus number 0*/
41
42   ioctl(i2c,I2C_SLAVE, address); /* set the i2c chip address */
43
44   write(i2c,buf,1); /* send the byte */
45
46   i2c = close(i2c);
47
48 }
49