【发布时间】:2016-06-07 20:38:35
【问题描述】:
我正在尝试通过智能手机控制我的家庭住宅,智能手机通过 Internet(Wi-Fi)向 Raspberry 发送 3-4 个字节,而 Raspberry 通过 I2C 总线将所有这些字节发送到相应的 Arduino(我有两个阿杜诺斯)。 当我向 Raspberry 发送命令时,它显示“无法写入 i2c 总线” 谁能帮帮我?
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;
}
【问题讨论】:
标签: sockets raspbian raspberry-pi2 i2c