The I2C bus with its maximum of 128 components

As the Bio-Digester project is coming to an end, the software had to be implemented and tested on our micro controller. Here is a short overview of my encounter with the I2C bus interface.

For those who don’t know what I2C is; it is a configurable address bus which may be linked to one master and up to 128 devices which have a unique address ranging from 0000000 to 1111111. Here is a very nice image which clarifies the I2C bus:



The hardware is fairly straight forward; the I2C bus has two lines SDA and SCL which are the Data and Clock lines used for communication. The master will send a signal with a corresponding address after which the bus will be empty for the slave device to respond with data. It is important to note the two pull-up resistors in the image above as the I2C bus implementation does not have an internal pull-up, thus nothing will function without the two resistors.

Traditional pull-up resistors I have encountered so far were all “flexible” meaning that I could replace the 10k with a 20k or a 50k resistor. Do not make the same mistake for I2C! Since we are dealing with communication signals, it is extremely important that the line is pulled up fast enough for the data bits to be detected properly on the micro controller. Here is a very nice explanation/guide about the effects different resistances can have on the signal as I do not want to go too much into detail about it: I2C Pull-Up Resistors Final Note: The Pull-Ups MUST be at the very end of the bus.

As per my design, we wanted 8 temperature sensors on the bus, so we went ahead and purchased digital sensors for this purpose. The bus itself was implemented on an Ethernet Cable which is shown in the picture below. The sensor modules are connected 3 feet from each other until the final one at 24 feet. A great feature of my design was to use male headers on the modules which allows the user to dynamically select the address of each sensor. As per the datasheet of our device, the address is 1001A0A1A2 where A0, A1 and A2 are set by a high or low voltage applied to the pin of the sensor. With my design one can pick up any of the modules and give it a different address if desired.

The software implementation for the I2C bus is a whole different game. There aren’t that many libraries and/or sample code available on-line since its application is not extremely common for hobbyists. However, one great library and resource was found here: I2C Library. As I tweaked the library to work with our sensors we had encountered multiple challenges such as low pull-ups, poor signal strengths and loss of bits. After about six hours behind the screen I was able to retrieve the temperature from our sensors and to display it on the LCD Screen.

A lot of testing still needs to be done before the bus is fully functional and is able to recover from all crashes and errors, but I just wanted to share a great milestone in our project. Here is a final picture of some temperature readings from our system: