0

I'm trying to control my domotic house by smartphone, the smartphone sends 3-4 byte to Raspberry via Internet(Wi-Fi) and Raspberry send all those bytes to the corresponding Arduino throught I2C bus(I've got two Arduinos). When I send the commands to Raspberry it shows "Failed to write to the i2c bus" Anyone can help me please?

  int i2csend(msg_t *pmsg)
  {
    int fd;
    /* Open I2C device */
    if ((fd = open(device, O_RDWR)) < 0) error ("Can't open I2C device");
    if (ioctl(fd, I2C_SLAVE, arduino_addr) < 0) error ("Can't talk to slave");
    if (write(fd, (char *)pmsg, n) < n ) printf ("Failed to write to the i2c bus [1]\n");
    else
    {
      read(fd, (char *)pmsg, n);
      printf("Ricevuto il messaggio: %c%c %d %d\n", pmsg->tipo, pmsg->gruppo, pmsg->dato[0], pmsg->dato[1]);
    }
    close(fd);
    return 0;
  }

1 Answers1

0

When I've used I2C on the raspi, I've never used the 'open' function in an if statement (like you have in the i2csend() function). Here's a sample from a (working) project of mine:

//open file for i2c interface
int fh=open("/dev/i2c-1",O_RDWR);
if (ioctl(fh, I2C_SLAVE, UIBC_ADDR) < 0){
    printf("Couldn't establish contact with the UIBC\n");
}
  • Thank you, but I've resolved. I haven't connected rasp and arduino ground toghether. I haven't done it because the first time I've used the usb bus ground and it has worked. This time I've used separated power supply. – Nicola Domenico Rinaldi Jun 11 '16 at 15:56