简体   繁体   中英

Raspberry Pi Arduino I2C communication

I am trying to connect a Raspberry Pi 3 with Windows 10 IoT Core to an Arduino Uno R3 via I2C in order to send some data from the Pi to the Arduino. Either the Arduino I2cDevice in C# is evaluated to null, or it isn't but when I send data the Arduino doesn't receive anything.

My Arduino code

void receiveEvent(int howMany) {
  while (1 < Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
  }
  int x = Wire.read();
  Serial.println(x);
}

My Raspberry Pi code

var i2cSettings = new I2cConnectionSettings(0X26);
i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
var devices = await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector());
var arduino = await I2cDevice.FromIdAsync(devices[0].Id, i2cSettings);
arduino.Write(Encoding.ASCII.GetBytes("Hello world"));

Edit: I dont know if it changes anything, but I also have a touchscreen connected to the Raspberry Pi.

I'm not sure whether or not this is also the same which I experienced in the past. Due to the different Voltage between Arduino 5V version and Raspberry Pi, you need to use level shifter in the middle of the connection.

https://core-electronics.com.au/tutorials/how-to-use-logic-level-shifters-converters.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM