Monday, April 4, 2016

Sensor Communication (I2C)


I wanted to spend a few minutes explaining this for my own sake. I spent an entire frustrating day this weekend trying to get two sensors working simultaneously. In the end I realized I had wired my board incorrectly (hence, 'Check your wiring'), but I did learn some interesting information.

So lets get down to it, disclaimer: the fundamentals of this communication method have very little consequence to an arduino programmer, you could use libraries all day long and cannibalize code until your eyes bleed, but to really understand what you are doing this is important knowledge.

I2C ("I sqaured C) stands for Inter-Integrated Circuit (which means nothing to me). You may have connected pins A4 and A5 on your board to a sensor before, these are the serial pins. If you haven't, don't get confused, we're just getting started! These pins connect to the SDA and SCL wires on your sensor. The connection of these wires allows for communication between the devices.

The SDA line is your data line, this line actually transfers the data in bits/bytes (never can keep them straight). The SCL line is the clock line, which keeps the data organized and decides the speed of the transfer. What makes this type of communication unique is that instead of using different pins for each one of your sensors, each device has its own address, and when the master devices sends the address request down the I2C lines, only the requested device answers. There are two modes for this communications, 7-bit, which can communicate with a little over 120 different addresses, and 10-bit, which is a slightly slower communication, but allows for over 1000 unique addresses.

The are tons of different devices you can connect. The arduino itself is called a master, and you can have more than one master communicating. The sensors (without a processor) are called slaves. You might have heard of this in other computer applications. The slaves can be anything from a thermostat, to a clock, to a gyroscope. I mentioned before that each device has its own address that it responds to. This address is permanently engraved on the device by the manufacturer. For example the TC74 digital serial thermal sensor can be give the address of TC74A0-TC74A7, and if you have two TC74A1's they will interfere with one another. An interesting work around for this would be to power one down while reading the other, but hopefully you'll never have to do that! (as a side note I should mention that the address is in hex, so the addresses will look more like 0x1E)

One of the main benefits of I2C communication is how few pins it requires. You can run tons of sensors with only two serial wires. The fascinating part of this is that each of the devices are connected in parallel, and only the device requested responds to input, all of it happening instantly. Its truly a brilliant form of communication!

Click here for more information!

I hope you enjoyed the read, and remember, check your wiring!

No comments:

Post a Comment