小编d s*_*d s的帖子

尝试通过 I2C 从 Arduino 获取数据时,出现 IOError:[Errno 121] python(树莓派)上的 smbus 远程 I/O 错误

我遇到了问题,在启动通过 I2C 从 Arduino 请求数据的脚本时,pyhton 有时会在我的 raspberry pi 3 上抛出这个 IOError 。

电气连接是完美的,所以这不是问题。此外,我在使用 i2cget -y 1 0x04 时也没有收到任何错误

有时只有 python 脚本很糟糕,我不知道为什么。

这是我的 Arduino 代码:

我注册了一个 onReceive 和一个 onRequestEvent。onReceive 回调将定义应该发送回树莓派的数据类型。onRequest 回调执行响应。

    #include <CommonFunction.h>
#include <Wire.h>

#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 = …
Run Code Online (Sandbox Code Playgroud)

python arduino i2c raspberry-pi smbus

10
推荐指数
1
解决办法
5万
查看次数

标签 统计

arduino ×1

i2c ×1

python ×1

raspberry-pi ×1

smbus ×1