6.3. Setting up I²C control

This section explains how to connect a microcontroller to the Jrk G2’s I²C interface so that you can send commands to control the Jrk G2. The Jrk G2 library for Arduino makes it particularly easy to control the Jrk from an Arduino or Arduino-compatible board such as an A-Star 32U4.

About the I²C interface

The SCL and SDA/AN pins of the Jrk provide its I²C interface. The pins are open drain outputs, meaning that they only drive low and they never drive high. Each pin has a 220 Ω series resistor protecting it from short circuits. By default, each pin is pulled up to 5 V by the Jrk’s microcontroller with a pull-up resistor that is typically around 40 kΩ. When the Jrk is reading the SCL or SDA pin as an input, any value over 2.1 V will be considered to be high.

Devices on the I²C bus have two roles: a master that initiates communication, and a slave that responds to requests from a master. The Jrk acts as the slave. The Jrk uses a feature of I²C called clock stretching, meaning that it holds the SCL line low to delay I²C communication while it is busy processing data from the master.

Connecting an I²C device to one Jrk

If you have not done so already, you should follow the instructions in Section 4.3 to configure and test your motor, and follow the instructions in the appropriate part of Section 5 to set up your desired feedback method. You should leave your Jrk’s input mode set to its default value of “Serial / I²C / USB” and leave the “Device number” set to its default value of 11. The “Device number” specifies the 7-bit address for the Jrk to use on the I²C bus.

Next, connect your device’s SCL pin to the Jrk’s SCL pin, and connect your device’s SDA pin to the Jrk’s SDA pin. You should also connect your device’s GND (ground) pin to one of the Jrk’s GND pins. These connections, and some other optional connections, are shown in the diagram below:

Connecting a 5V microcontroller or other I²C device to the I²C interface of the Jrk G2. Dashed connections are optional.

Because the Jrk considers an input value of 2.1 V on SCL or SDA to be high, you can connect those pins directly to 3.3 V microcontrollers without needing a level shifter. If your microcontroller’s I²C interface is not 5V tolerant, it will usually still have a diode going from each I/O pin to its logic supply. These diodes clamp the voltage on the pins, preventing the Jrk’s pull-up resistors from pulling the pins too high. If you want to be extra safe and not rely on the clamping diodes, you can disable the Jrk’s pull-up resistors by going to the “Advanced” tab and checking “Disable I²C pull-ups”.

Depending on your setup, you might need to add pull-up resistors to the SCL and SDA lines of your I²C bus to ensure that the signals rise fast enough. The Jrk’s pull-up resistors are enabled by default, and many I²C master devices will have pull-ups too, but that might not be enough, especially if you want to use speeds faster than 100 kHz or have long wires. The I²C-bus specification and user manual (1MB pdf) has some information about picking pull-up resistors in the “Pull-up resistor sizing” section, and trying a value around 10 kΩ is generally a good starting point.

If you are using an Arduino or Arduino-compatible board, you should now try running the I2CSetTarget example that comes with the Jrk G2 Arduino library. If you are using a different kind of microcontroller board, you will need to find or write code to control the Jrk on your platform. If you are writing your own code, we recommend that you first learn how to use the I²C interface of your platform, and then use the I2CSetTarget example and the source code of the Jrk G2 library as a reference. You should also refer to the sections in this guide about the Jrk’s commands (Section 11) and I²C protocol (Section 13).

If your connections and code are OK, you should now see your motor moving back and forth. If the motor is not moving, you should check all of your connections and solder joints. You should check the “Status” tab of the Jrk Control Center to see if any errors are being reported. You can also try slowing down your I²C clock speed to something very slow like 1 kHz or 10 kHz. If slowing down the clock works, then the problem might be due to not having strong enough pull-up resistors on the SDA and SCL lines.

Optional connections

The Jrk’s 5V (out) pin provides access to the output of the Jrk’s 5V regulator, which also powers the Jrk’s microcontroller and the red and yellow LEDs. You can use the Jrk’s regulator to power your microcontroller or another device if the device does not draw too much current (see Section 7.8).

The VM pin provides access to the Jrk’s power supply after the reverse-voltage protection circuit, and this pin can be used to provide reverse-voltage-protected power to other components in the system if the Jrk supply voltage is within the operating range of those components. Note: this pin should not be used to supply more than 500 mA; higher-current connections should be made directly to the power supply. Unlike the 5V (out) pin described above, this is not a regulated, logic-level output.

The ERR pin of the Jrk is normally pulled low, but drives high to indicate when an error (other than the “Awaiting command” error bit) is stopping the motor. You can connect this line to an input on your microcontroller (assuming it is 5V tolerant) to quickly tell whether the Jrk is experiencing an error or not. Alternatively, you can query the Jrk’s serial interface to see if an error is happening, and which specific errors are happening. For more information about the ERR pin, see Section 7.7.

The RST pin of the Jrk is connected directly to the reset pin of the Jrk’s microcontroller and also has a 10 kΩ resistor pulling it up to 5 V. You can drive this pin low to perform a hard reset of the Jrk’s microcontroller and immediately turn off the motor, but this should generally not be necessary for typical applications. You should wait at least 10 ms after a reset before sending commands to the Jrk.

Controlling multiple Jrks with I²C

I²C is designed so that you can control multiple slave devices on a single bus. Before attempting to do this, however, we recommend that you first get your system working with just one Jrk as described above.

Next, make sure that the I²C master device and the Jrks all share a common ground, for example by connecting a GND pin from the I²C master device to a GND pin on each of the Jrks. Make sure that the SCL pins of all devices are connected and that the SDA pins of all devices are connected.

You should use the Jrk G2 Configuration Utility to configure each Jrk to have a different “Device number”, which specifies the 7-bit I²C address to use. Then you should change your code to use those addresses. If you are using our Jrk G2 Arduino library, you can declare one object for each Jrk by writing code like this at the top of your sketch, which uses addresses 11 and 12:

JrkG2I2C jrk1(11);
JrkG2I2C jrk2(12);

The following diagram shows the standard I²C connections described above along with optional connections of the ERR and RST pins:

Wiring diagram for controlling multiple Jrk G2 modules from a single I²C source, such as a microcontroller.

The ERR pins can all be safely connected together. In such a configuration, the line will be high if one or more Jrks has an error; otherwise, it will be low.

More information about the I²C interface

This user’s guide has more information about the Jrk’s commands (Section 11) and I²C protocol (Section 13).

Related Products

Jrk G2 18v19 USB Motor Controller with Feedback
Jrk G2 24v13 USB Motor Controller with Feedback
Jrk G2 18v27 USB Motor Controller with Feedback
Jrk G2 24v21 USB Motor Controller with Feedback
Jrk G2 21v3 USB Motor Controller with Feedback
Jrk G2 21v3 USB Motor Controller with Feedback (Connectors Soldered)
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors