Ich versuche, ein einfaches Projekt mit I2C-Schnittstelle zu erstellen. Dafür habe ich eine Skizze in Arduino erstellen, die immer einzelne Byte sendet:Raspberry Pi: Problem bei der Kommunikation über I2C
#include <Wire.h>
void setup() {
Wire.begin(8);
Wire.onRequest(requestEvent);
}
void loop() {
delay(100);
}
void requestEvent() {
Wire.write(0x11);
}
Auf Raspberry Pi gibt es ein Python-Skript:
#!/usr/bin/env python3
import smbus
import time
bus = smbus.SMBus(1)
while True:
try:
data = bus.read_byte_data(0x8, 0)
print(data)
except Exception as e:
print(e)
time.sleep(1)
Und hier ist seine Ausgabe:
17
17
17
17
17
17
17
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
17
17
17
17
17
[Errno 5] Input/output error
[Errno 5] Input/output error
17
17
Was ich versuche herauszufinden, warum I2C zu einigen zufälligen Zeitpunkten Fehler zurückgibt, anstatt Daten zurückzugeben? Keine Hardware-Änderungen, nichts anderes läuft auf RPi, buchstäblich ändert sich nichts, aber I2C hört auf zu arbeiten.
Irgendwelche Ideen?
I2C hat normalerweise einen einzigen Master und die adressierten Geräte sind Slaves - normalerweise ist das, was Sie programmieren, der Master. Die Slaves senden niemals, bis der Master ihnen einen Befehl gesendet hat, bei dem der Master eine Antwort erwartet. Wenn der Arduino sendet, muss der Pi als Slave arbeiten, nicht sicher, dass das der Standard ist. – barny