pythonioerror0 121_获取IOError:[Errno 121]尝试通过I2C从Arduin获取数据时,python(raspberry)上的smbus发生远程I/O错误...
我面临的问题是,在启动一个通过I2C从Arduino请求数据的脚本时,Pyton在我的raspberry Pi3上抛出了这个IOError电气连接是完美的,所以这不是问题所在。此外,在使用i2cget-y10x04时,我也没有收到任何错误只有python脚本有时很糟糕,我不知道为什么。在这是我的Arduino代码:注册并接收请求。onReceive回调将定义应该将什么类型的数据发送回raspber
我面临的问题是,在启动一个通过I2C从Arduino请求数据的脚本时,Pyton在我的raspberry Pi3上抛出了这个IOError
电气连接是完美的,所以这不是问题所在。
此外,在使用i2cget-y10x04时,我也没有收到任何错误
只有python脚本有时很糟糕,我不知道为什么。在
这是我的Arduino代码:
注册并接收请求。
onReceive回调将定义应该将什么类型的数据发送回raspberry。
onRequest回调执行响应。在#include
#include
#define I2C_ADDRESS 0x4
commonFunc GetCountsEverySecond;
int g_iOnRequestActionCode = 0;
unsigned long g_lSecondsSinceStart = 0;
void setup()
{
Wire.begin(I2C_ADDRESS);
Wire.onRequest(sendDataOverI2CGateway);
Wire.onReceive(defineOnRequestAction);
}
void loop()
{
tickSeconds();
}
void tickSeconds()
{
if (GetCountsEverySecond.TimeTriggerAt(1000))
{
g_lSecondsSinceStart++;
}
}
void sendOperationTimeDataOverI2C()
{
unsigned long longInt = g_lSecondsSinceStart;
byte size = sizeof(longInt);
byte arr[size];
for (int i = 0; i < size; i++)
{
int iBitShift = 8 * (size - i - 1);
if (iBitShift >= 8)
arr[i] = ((longInt >> iBitShift) & 0xFF);
else
arr[i] = (longInt & 0xFF);
}
Wire.write(arr, size);
g_bI2CSending = true;
}
void sendDataOverI2CGateway()
{
switch(g_iOnRequestActionCode)
{
case 0:
sendRainDataOverI2C();
break;
case 1: // send firmware version
sendVersionDataOverI2C();
break;
case 2: // send operation time of arduino in seconds from start
sendOperationTimeDataOverI2C();
break;
default: break;
}
}
void defineOnRequestAction(int iBuffer)
{
while (Wire.available())
{
g_iOnRequestActionCode = Wire.read();
}
}
这是我的python代码。
很直截了当,但会引起一些头痛。在
^{pr2}$
在执行python脚本之后,我有时会遇到以下错误:pi@WeatherStation:~/workspace $ sudo python readTimeOperationData.py
Traceback (most recent call last):
File "readTimeOperationData.py", line 5, in
data = bus.read_i2c_block_data(0x04,0x02,4)
IOError: [Errno 121] Remote I/O error
有人能帮我解决这个问题吗?在
为迪特干杯
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐


所有评论(0)