"I2C" (Device Connection Protocol)
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.