3.4. Setting I²C addresses with a Raspberry Pi

Each device on an I²C bus should have a unique address so that you can communicate with the device without interfering with other devices on the bus. By default, the Motoron uses I²C address 16, so if you have connected two or more Motorons to your bus, or you have another device that uses address 16, you will need to change the I²C addresses of one or more Motorons.

Warning: If you have devices on your I²C bus that are not Motorons, the procedure below could cause undesired behavior when it sends commands to them that are intended for the Motorons.

The recommended procedure for setting the I²C address of one or more Motorons that are connected to the I²C bus of your Raspberry Pi is:

  1. Ensure that the JMP1 pin on each Motoron is not connected to anything.
  2. Download the Motoron Motor Controller Python library for Raspberry Pi, and install its dependencies, as described in the “Getting started” section of its README file.
  3. In a Terminal, use cd to navigate into the directory holding the library and its examples.
  4. Run ./set_i2c_addresses_example.py. This utility will print some information and then prompt you for a command.
  5. Perform a scan of the I²C bus by typing “s” followed by “Enter”. You should get output that looks like this:
    Scanning for I2C devices…
    Found device at address 0
    Found device at address 16
    The scan detects that a device on the bus is responding to address 16 because that is the Motoron’s default address. It also detects a device on address 0 because that is the I²C general call address and all Motorons respond to it by default, in addition to the normal address. We will use address 0 to send commands in later steps, so if the scan does not detect any devices on address 0, those steps will probably fail.
  6. Connect the JMP1 pin of one Motoron to GND. If you have not soldered headers to the JMP1 pin and its adjacent GND pin, you can connect those two pins together using a wire, test clip, or with a shorting block attached to a 1×2 male header. Connecting JMP1 to GND is how we select which Motoron’s address will be changed in the next step. Only one Motoron at a time should have its JMP1 pin connected to GND.
  7. Set the address of the selected Motoron by typing “a”, followed by the address (in decimal), and then “Enter”. We recommend picking an address between 8 and 119 that is not in use by any other devices on your bus (numbers outside that range could work too, but they are reserved for other uses by the I²C specification). For example, type “a17” to set the address of the Motoron to 17. Alternatively, you can just send “a” by itself in order to have the program automatically pick an address for you, starting at 17 and skipping addresses that are already in use on the bus.

    This sends a “Write EEPROM” command to all of the Motorons using address 0, but the command will only have an effect on the one Motoron whose JMP1 line is low. That Motoron will record the address in its non-volatile EEPROM memory, but will not start using it yet.
  8. Disconnect the JMP1 pin from GND.
  9. Repeat the last three steps for every Motoron whose address you wish to change.
  10. Type “r” to make the new addresses take effect. This sends a “Reset” command to all of the Motorons using address 0. Alternatively, you can power cycle the system or use the RST pin to reset the Motorons.
  11. Perform another scan of the I²C bus by typing “s”. Check that a device is now found on each of the addresses that you assigned.

Related Products

Motoron M3S256 Triple Motor Controller Shield for Arduino (Connectors Soldered)
Motoron M3S256 Triple Motor Controller Shield Kit for Arduino
Motoron M3S256 Triple Motor Controller Shield for Arduino (No Connectors)
Motoron M3H256 Triple Motor Controller for Raspberry Pi (Connectors Soldered)
Motoron M3H256 Triple Motor Controller Kit for Raspberry Pi
Motoron M3H256 Triple Motor Controller for Raspberry Pi (No Connectors or Standoffs)
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors