Linkbot I2c Port

From LinkbotLabs
Jump to: navigation, search

Intro

This page contains information regarding the Linkbot's I2C interface. The information contained here can be used to design and build your own sensor boards, peripherals, and accessories for a Linkbot. Please be aware that connecting a device incorrectly to a Linkbot's I2C interface can result in permanent damage to the Linkbot. As such, we recommend that you do not attempt to access the I2C interface unless you know what you are doing.

Each Linkbot has an expansion port built into it that looks like a phone jack. In fact, it is the same form factor as a standard RJ14 phone jack, but the pin outs differ from phone line wirings. Note: DO NOT PLUG YOUR LINKBOT INTO A HOUSEHOLD PHONE JACK. It may result in permanent damage to your Linkbot.

Pin Specifications

With the Linkbot sitting flat such that the buttons are facing the ceiling, you will see four leads inside of the phone jack. From left to right, the leads are:

  • GND : This lead connects to the grounding plane on the Linkbot.
  • SDA : This is the I2C Data line.
  • SCL : This is the I2C Clock line.
  • VPP : This line provides 6 volts of "motor level" power. This power line is shared with the Linkbot's motors. Circuits and small motors can be powered using this power source, but we recommend not drawing more than 500mA of current.

Addressing

The Linkbot binds to an I2C address of 0x01 and the on-board accelerometer binds to the address 0x1C . Make sure that your peripherals does not also use either of these addresses.

Python API

The Linkbot Python API provides three functions to communicate with an I2C peripheral.

writeTwi()

The writeTwi() function writes a bytearray onto the TWI bus. The function signature is writeTwi(address, bytearray) Example:

import linkbot
robot = linkbot.Linkbot()
robot.writeTwi(0x03, bytearray([0x02, 0x05, 0x01]))

readTwi()

The readTwi() function can be used to read a number of bytes from a device on the I2C bus. For instance, to read 5 bytes from a device at address 0x0D, you would use the line of code:

data = robot.readTwi(0x0D, 5)

writeReadTwi()

The writeReadTwi() can be used to write bytes onto the I2C bus and then immediately read bytes from the same destination address without releasing the I2C bus. This is a very common paradigm for reading data from I2C peripherals. To write a byte array containing the data 0x1234 to address 0x0D and immediately read 4 bytes from the device at 0x0D, you could do:

data = robot.writeReadTwi(0x0D, bytearray([0x12, 0x34]), 4)

Troubleshooting

We have discovered that different phone lines have different amounts of capacitance per length of line. On certain phone lines, we have discovered that the communications only work if the length of the line is less than six inches. If you experience problems sending and receiving data, we recommend either shortening the line or trying different types of cable.