Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python I2C总线Raspi主设备Arduino巨型从设备上的远程I/O错误_Python_Loops_Error Handling_Raspberry Pi3_I2c - Fatal编程技术网

Python I2C总线Raspi主设备Arduino巨型从设备上的远程I/O错误

Python I2C总线Raspi主设备Arduino巨型从设备上的远程I/O错误,python,loops,error-handling,raspberry-pi3,i2c,Python,Loops,Error Handling,Raspberry Pi3,I2c,我已将我的raspi(主)与Arduino Mega(从)连接,并希望持续将模拟读数从模拟引脚A0-A3传输到raspi。程序运行了一段时间,崩溃使我: [Errno 121]远程I/O错误 我怀疑有两个问题:1)while循环=>较长的睡眠时间导致较长的运行时间,直到程序崩溃2)我在某处读到wire库在执行onRequest之前执行onReceive命令 这是我的Arduino和raspi代码: Arduino巨型代码 #包括 int SLAVE_ADDRESS = 0x08; int ana

我已将我的raspi(主)与Arduino Mega(从)连接,并希望持续将模拟读数从模拟引脚A0-A3传输到raspi。程序运行了一段时间,崩溃使我: [Errno 121]远程I/O错误

我怀疑有两个问题:1)while循环=>较长的睡眠时间导致较长的运行时间,直到程序崩溃2)我在某处读到wire库在执行onRequest之前执行onReceive命令

这是我的Arduino和raspi代码:

Arduino巨型代码 #包括

int SLAVE_ADDRESS = 0x08;
int analogPin1 = A0;
int analogPin2 = A1;
int analogPin3 = A2;
int analogPin4 = A3;


void setup(){
Wire.begin(SLAVE_ADDRESS);
Wire.onRequest(sendAnalogReading);
}

void loop(){
}

void sendAnalogReading(){

uint16_t reading1 = analogRead(analogPin1);
uint16_t reading2 = analogRead(analogPin2);
uint16_t reading3 = analogRead(analogPin3);
uint16_t reading4 = analogRead(analogPin4);


Wire.write((char *) &reading1, 2);
Wire.write((char *) &reading2, 2);
Wire.write((char *) &reading3, 2);
Wire.write((char *) &reading4, 2);

}
这是我的Raspi上的脚本: 导入smbus 导入时间

bus = smbus.SMBus(1)

SLAVE_ADDRESS = 0x08

def requestreading():
block = bus.read_i2c_block_data((SLAVE_ADDRESS), 0, 8)

print(block)


while True:
#var = input("Press any key for reading: ")
requestreading()
    time.sleep(0.1)
可以连续运行,但我觉得实际运行时间取决于两个因素,直到崩溃。while循环中.sleep()的时间长度,以及测量值是否发生很大变化