I2C library on C# for Raspberry Pi. About connecting Arduino and Raspberry Pi read this blog posts: hardware part and software part.
The library provides basic read/write functionality with I2C-devices for Mono v. 2.10.x. It uses device files exposed by the I2C kernel drivers in Arch Linux.
Update your system to get I2C kernel drivers. For Arch Linux:
$ pacman -Syu
Load I2C kernel module. You can do
$ modprobe i2c-dev
Or if you want to load the module automatically on boot add i2c-dev
to /etc/modules/
. If you're on Arch Linux create file /etc/modules-load.d/i2c.conf
and add i2c-dev
to the file.
make
from Lib/LibNativeI2C/src
.libnativei2c.so
to /usr/lib/
or to the same folder where RPi.I2C.Net.dll
is located.I2CBus
instance with I2CBus.Open()
. The function accepts path to an I2C device file, which is "/dev/i2c-0"
for RPi rev.1 and "/dev/i2c-1"
for RPi rev.2 by default.I2CBus.WriteBytes()
or I2CBus.ReadBytes()
.using (var bus = RPi.I2C.Net.I2CBus.Open("/dev/i2c-1"))
{
bus.WriteByte(42, 77);
}
The performance testing was done using:
Sending 3-byte packets to Arduino. Results: 1428 transactions per second (4284 Bytes/s)
Reading 3-byte packets from Arduino. Results: 1660 transactions per second (4980 Bytes/s)
Sending 3-byte packet to Arduino and reading back the respose 3-byte packet. Results: 830 transactions per second (4980 Bytes/s total)
The project uses MIT license: do whatever you want wherever you want it.