ads1115 analog-to-digital 4-channel added
[i2c-telemetry.git] / pcf8574_1.c
1 /*
2 PCF8574_addr_byteout_slug.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_slug> <decimal address> <decimal byte out 0-255>
12
13 Home Page - http://www.sunspot.co.uk/Projects/SWEEX/slug/i2c/slug_i2c.html
14
15 */
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <sys/ioctl.h>
19 #include <fcntl.h>
20 #include <unistd.h>
21 #include <linux/i2c-dev.h>
22 #define I2C_SLAVE0x0703/* Change slave address*/
23
24 int i2c;
25 char filename[20];
26 unsigned long address;
27
28 int rc;
29 unsigned char data[1];
30 int main(int argc, char *argv[]) 
31 {
32 if (argc != 3) { /* error if we are not getting just 2 inputs after the program name */
33 fprintf(stderr, "usage: %s <address> <databyte>\n",argv[0]);
34 exit(1);
35 }
36
37 /* address is the first number after the program name */
38 address = atoi(argv[1]);
39 /* the byte to send out to the PC8574 is the second number
40 place it into the first element of the buf array */
41 data[0] = atoi(argv[2]);
42
43 i2c = open("/dev/i2c-0",O_RDWR); /* open the device dev/i2c-0 */
44
45 rc=ioctl(i2c,I2C_SLAVE,address); /* set the i2c chip address */
46
47 write(i2c,data,1) ; /* send the byte */
48
49 i2c = close(i2c);
50 return(0);
51 }
52