2 PCF8574_addr_byteout_slug.c
4 Send address and byte to switch lines on 8 line port of i2c bus PCF8574
5 -----------------------------------------------------------------------
7 1) send the i2c address
8 2) send byte to set the 8 port lines on or off
10 usage :- type with spaces but without the < >
11 <PCF8574_addr_byteout_slug> <decimal address> <decimal byte out 0-255>
13 Home Page - http://www.sunspot.co.uk/Projects/SWEEX/slug/i2c/slug_i2c.html
18 #include <sys/ioctl.h>
21 #include <linux/i2c-dev.h>
22 #define I2C_SLAVE0x0703/* Change slave address*/
26 unsigned long address;
29 unsigned char data[1];
30 int main(int argc, char *argv[])
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]);
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]);
43 i2c = open("/dev/i2c-0",O_RDWR); /* open the device dev/i2c-0 */
45 rc=ioctl(i2c,I2C_SLAVE,address); /* set the i2c chip address */
47 write(i2c,data,1) ; /* send the byte */