Notes on using the Robotics Connection I2C line following sensor with Arduino based boards

After many of wasted hours of trying to get the I2C line following sensor from Robotics Connection working with an Arduino based controller board I was finally able to get it to communicate and since there was no other information out there on this issue I decided to write this post.

To start off the I2C master sends and 8 bit word onto the I2C bus consisting of a 7-bit address and a 1-bit read or write command for a total 8-bit word looking like <7-bit address><R/W bit> with the R/W bit being the LSB. The 7-bit address is set by the device it’s self either in it’s firmware or through switches (In some cases like the I2C line following sensor this can be change through I2C). The read or write bit lets the device that you want to communicate with know if you want to receive data from it or write data to it. This bit is set to 0 if the master wants to receive data or to 1 if it wants to send data. When a device on the I2C bus that has this address detects a packet with it’s address it will read the last bit of the word and either wait to receive more data or start sending out data at the proper time.

The problem I had with the I2C line following sensor was that Robotics Connection lists the default address of the sensor in there documentation as 0x50. What they do not mention is that this is the full 8-bit word that you must send to receive data not the 7-bit address of the device. So the actual 7-bit default address of the sensor is 0x28 (which is 0x50 shifted 1-bit to the right). This might not be an issue on other boards where you must specify the full 8-bit word when sending over I2C but in the Arduino language the Wire.requestFrom command adds the final R/W bit for you. So when i was attempting to communicate on the address 0x50 the the wire library was adding the extra bit resulting in the word being 0xA0 while when using the proper address of 0x28 results in the word being 0x50. So in the end, when using the I2C line following sensor from Robotics Connection with an Arduino based board any values in their documentation must be shifted to the right one place for it to work.

Sample Code

Share

5 thoughts on “Notes on using the Robotics Connection I2C line following sensor with Arduino based boards

    • On some of the Arduino boards the serial tx & rx pins are used to program the microcontroller, I have found that most of the time you must disconnect anything connected to the tx & rx pins in order to program it. Additionally make sure you are using the correct pins for sda & scl (analog pins 4 & 5 on the duemilanove).

  1. I want to thank you for the blog. I have some additional problems that I was hoping that you could help me with.

    I hookup the linefollowing sensor just as you said and it works fabulously. However I would like to put it into analog mode. I contacted the distributor and he sent me a link the a website with some documentation.

    http://shop.gadgetsngizmosetc.com/Line-following-Sensor-Line-Sensor.htm

    So I think there is some type of problem with the send sequence and was wondering if you could help me. I would be rather greatful.

    Thank you
    Casey

Leave a Reply

Your email address will not be published. Required fields are marked *