Looking for i2c example in C

Does torizon have an i2c Lib. Like it does with GPIO. Just looking for an example in C/C++ using the i2c in torizon.

Greetings @jeffbelz,

We don’t provide our own libraries for generic peripheral use. The GPIO lib you’re talking about is just a generic library not specific to Torizon. For C++ the generic i2c library is i2c-dev though you can use anything you’d like in the end.

Searching online here’s generic example of working with i2c devices in Linux: https://www.kernel.org/doc/Documentation/i2c/dev-interface

This should generally apply to Torizon as well. The only thing specific to Torizon is making sure you properly give your container user-space access to the i2c devices you need, as shown here: How to use I2C on Torizon | Toradex Developer Center

Best Regards,

Most I2C devices are handled by kernel drivers. The device tree or platform data binds the I2C bus to such drivers. From userspace one accesses them then through the relevant subsystem rather than having to do low-level I2C access. E.g. for an RTC one would use /dev/rtcX or even a userspace program like hwclock.

If you wich to access I2C device directly you can use functions defined at i2c.h .
You can use an I2C tools source code as an example.

Documentation for Linux I2C subsystem - I2C/SMBus Subsystem — The Linux Kernel documentation

Thanks! I figured it was long these lines.

Glad we were able to help clarify this for you.