I2C via Greybus
The following has been tested on BeaglePlay (host) and BeagleConnect Freedom (node).
To ensure that we are interacting with the Greybus I2C device, run the following command. Reading from or writing to arbitrary I2C devices can sometimes have unintended consequences.
ls -la /sys/bus/i2c/devices/* | grep greybus
lrwxrwxrwx 1 root root 0 Oct 18 18:32 \
/sys/bus/i2c/devices/i2c-6 -> ../../../devices/platform/bus@f0000/2860000.serial/2860000.serial:0/2860000.serial:0.0/serial0/serial0-0/greybus1/1-3/1-3.3/1-3.3.4/gbphy6/i2c-6
In this example, values are read from several sensors on the
beagleconnect_freedom.
First, read the ID registers (I2C register address 0x7e) of the opt3001
sensor (I2C bus address 0x44), as shown below:
i2cget -y 6 0x44 0x7e w
0x4954
Next, read the ID registers (I2C register address 0xfc) of the hdc2080
sensor (I2C bus address 0x41):
i2cget -y 6 0x41 0xfc w
0x5449
Finally, probe the Linux kernel driver for the opt3001 sensor and use the
Linux IIO subsystem to read ambient light values.
echo opt3001 0x44 | sudo tee /sys/bus/i2c/devices/i2c-6/new_device
cd /sys/bus/iio/devices/iio:device0
cat in_illuminance_input
3.33000
What is particularly interesting about this example is that the local Linux driver is used to interact with a remote I2C PHY. In other words, the microcontroller does not require a dedicated driver for the sensor, and the driver code can be maintained entirely within the Linux kernel.