我试图通过智能手机控制我的住宅,智能手机通过互联网(Wi-Fi)发送3-4个字节到树莓,树莓通过I2C总线发送所有这些字节到相应的Arduino (我有两个Arduinos)。当我向树莓发送命令时,它显示“写入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;
}
发布于 2016-06-10 04:06:23
当我在raspi上使用I2C时,我从未在if语句中使用过'open‘函数(就像在i2csend()函数中一样)。下面是我的一个(正在工作的)项目的示例:
//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");
}
https://stackoverflow.com/questions/37688908
复制相似问题