Skip to main content
Skip table of contents

I2C Sensor Examples

The following examples outline how I2C communication can be achieved in Lua scripts.

The below examples utilize the I2C library with the functions built in to the firmware. More detail (at the ModBus register level) can be seen under the I2C Utilities, where the library is exposed as a Lua object with functions. A list of these functions with descriptions can be found here.

The T7 supports Inter-Integrated Circuit (I²C or I2C) communication as the master only. I²C is a synchronous serial protocol typically used to communicate with chips that support I2C as slave devices. More information on I2C can be found here (Wikipedia).

It is recommended to use the EIO or CIO lines for I2C communication on the T7 rather than the FIO lines. For more information on using the T7 with I2C devices, see the T7 Datasheet.

Many sensors can be on the same I2C bus, with very minimal circuitry for each additional I2C device. A total of 7 I2C devices are shown connected to the T7 below, and can all successfully connect and communicate with the T7.

These Lua scripts use the USER_RAM registers to pass data from the Lua script to any other program accessing the T-Series device. LabVIEW, C#, Python, or any other supported languages can access the T-Series device and read from or write to these registers. LJLogM, a LabJack application can be used for easy logging of data from the various sensors.

Subsections

I2C FAQ/Common Questions

Q: Why are no I2C ACK bits being received?

  • Double check to make sure pull-up resistors are installed.  A general rule for selecting the correct size pull-up resistors is to start with 4.7kΩ and adjust down to 1kΩ as necessary.  If necessary, an oscilloscope should be used to ensure proper digital signals are present on the SDA and SCL lines.

  • Double check to make sure the correct I/O lines are being used.  It is preferred to do I2C communication on EIO/CIO/MIO lines instead of the FIO lines due to the larger series resistance (ESD protection) implemented on the FIO lines.

  • Use an oscilloscope to verify the SDA and SCL lines are square waves and not weird arch signals (see "I2C_SPEED_THROTTLE" or use EIO/CIO/MIO lines).

  • Use a logic analyzer (some oscilloscopes have this functionality) to verify the correct slave address is being used.  See this EEVblog post on budget-friendly options.  It is common to not take into account 7-bit vs 8-bit slave addresses or properly understand how LabJack handles the defined slave address and the read/write bits defined by the I2C protocol to perform read and write requests.

  • Make sure your sensor is being properly powered.  The VS lines of LJ devices are ~5V and the I/O lines are 3.3V.  Sometimes this is a problem.  Consider buying a LJTick-LVDigitalIO or powering the sensor with an I/O line or DAC channel.

Q: I've tried everything, still no I2C Ack Bits...

  • Try slowing down the I2C bus using the "I2C_SPEED_THROTTLE" register/option.   Reasons:

  • Not all I2C sensors can communicate at the full speed of the LabJack.  Check the I2C sensor datasheet.  

  • The digital signals could be getting corrupted due to the series resistors of the I/O lines on the LabJack.

  • Consider finding a way to verify that your sensor is still functioning correctly using an Arduino and that it isn't broken.

  • Try to establish communications with an LJTick-DAC to ensure the DIO are operating properly and that you are configuring I2C properly.

Q: Why is my device not being found by the I2C.search function?

  • See information on I2C ACK bits above.

Q: What are I2C Read and Write functions or procedures?

Q: Why am I getting a I2C_BUS_BUSY (LJM Error code 2720) error?

  • See information on I2C ACK Bits above. Try different pull-up resistor sizes.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.