"I2C" (Device Connection Protocol)
There are two classes of devices that are compatible with I2C, master devices and slave devices. Master devices facilitate all communication on the bus, but slave devices are not allowed to communicate on the bus unless explicitly permitted by the master. The Wolfram Language implementation of I2C designates the device that is running the Wolfram Language as the master on the I2C bus.
The system may need to be set up prior to using the I2C kernel; see "I2C Setup" for more information.
Note: On Raspbian versions lower than Jessie, to access GPIO you must be logged in as root or be running the Wolfram Language as root. All higher versions do not need root access.
Device Discovery

- I2C devices are discovered automatically. Use FindDevices to list the devices currently on the I2C bus.
Opening the Device

- Valid I2C slave addresses are integers from 8 to 119. 10-bit addresses are not supported. Consult the manufacturer's documentation on the device for a particular device's address.
- On the Raspberry Pi, the only valid bus is 0.
DeviceOpen["I2C",addr]
opens a connection to the I2C device with a slave address addr.
DeviceOpen["I2C",{addr,bus}]
opens a connection to the I2C device with a slave address addr on the specified bus.
Reading Data

- The I2C slave device may need to be configured independently of the Wolfram Language before communication occurs.
- Note that some I2C slave devices may respond differently to read operations requesting a different number of bytes. Consult the manufacturer's documentation on the device for more information.
DeviceRead[dev]
reads a single byte from the device on the I2C bus.
DeviceRead[dev,n]
reads n bytes from the device on the I2C bus.
Writing Data

- data must be a list of integers between 0 and 255 or a single Integer between 0 and 255.
- The I2C slave device may need to be configured independently of the Wolfram Language before communication occurs.
DeviceWrite[dev,data]
writes data to the device.
Closing and Releasing Resources

DeviceClose[dev]
closes the connection to the I2C bus and frees the bus for other programs to use.
Examples
Basic Examples (1)Summary of the most common use cases
In[1]:=1

✖
https://wolfram.com/xid/0czh05bgbfoq6rt4yr5-n3j8u
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0czh05bgbfoq6rt4yr5
Out[2]=2

In[3]:=3

✖
https://wolfram.com/xid/0czh05bgbfoq6rt4yr5
Out[3]=3

Write a sequence of bytes to the device:
In[4]:=4

✖
https://wolfram.com/xid/0czh05bgbfoq6rt4yr5
Out[4]=4

Read a single byte from the device:
In[5]:=5

✖
https://wolfram.com/xid/0czh05bgbfoq6rt4yr5
Out[5]=5

Read a sequence of 10 bytes from the device:
In[6]:=6

✖
https://wolfram.com/xid/0czh05bgbfoq6rt4yr5
Out[6]=6
