简体   繁体   English

Raspberry Pi Arduino I2C通讯

[英]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. 我正在尝试通过I2C将具有Windows 10 IoT核心的Raspberry Pi 3连接到Arduino Uno R3,以便从Pi发送一些数据到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. C#中的Arduino I2cDevice被评估为null,或者不是,但是当我发送数据时,Arduino没有收到任何东西。

My Arduino code 我的Arduino代码

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 我的Raspberry Pi代码

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. 编辑:我不知道它是否会改变任何东西,但我也有一个触摸屏连接到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. 由于Arduino 5V版本和Raspberry Pi之间的电压不同,因此您需要在连接中间使用电平转换器。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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