Connecting Arduino with multiple I2C devices

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
How many devices can you connect to the I2C bus? Connecting a single sensor to an Arduino is easy enough. Usually you can find a tutorial online showing you how to plug everything up, you download some library containing the code, and you get your sensor to work within a few minutes. But using several devices at the same time it's much more complicated. And i'm not even talking about the challenge of programming all of them into the same code. The problem lies on the hardware. Depending on the number of devices on your I2C bus you may get to a point, where you no longer that meaningful data from the sensors. Now just to be clear, here I'm assuming that every device is built on its own Breakout Board. So with that in mind, how many Breakout Boards can actually connect to the I2C Bus? But if you're new to Arduino and still not sure what I'm talking about, here are some basic information on the I2C Bus. If you're connecting a digital sensor using the pins A4 and A5 of your Arduino Uno, then you're using the I2C Bus. In this scenario the Arduino is the Master and the sensor is the Slave. You need only two wires to run the communication. One of them is a Serial Data Line. And the other one is the Serial Clock Line. Now this is important. We need to see how the I2C Bus looks like inside the device. So let's keep it simple. Really simple. Now let's pretend these are the pins of your device. You have your Power Supply, the Serial Data Line, the Serial Clock Line, and the Ground. Inside the device the Data and and the Clock Lines are each connected to the Ground through a switch. This switch can either be "open" or "closed". If this device is working as a Master, then the other one is the Slave. But from a hardware perspective, they look pretty much the same. Outside the device you need to connect resistors between the Power Supply and both the Data Line and the Clock Line. These are the Pull-up Resistors. But you can only have one Resistor for each bus line. Not one for the Master and another for the Slave. It doesn't matter if you have one Slave for a hundred. You only need one Resistor for the Data Line and one Resistor for the Clock Line. Ok, so let's see how the Serial Clock Line works. The Data Line works the same way, but let's focus on one of them only. Suppose your device works with 5 Volts. If the switch is open, then all the blue region has a 5 Volt potential. The signal on the Clock Line is now "Logic High". Also as a consequence, there is no current flowing through the Resistor or the device. If you close the switch then the 0 Volt potential from the Ground will now be on this green region. The signal on the Clock Line is now "Logic Low". Because of the potential difference across the Resistor, a current will flow through the device. Ok, so by opening and closing the switch you get a digital signal on the Clock Line. Now let's take a look at a real signal, measured from the Clock Line with a single device on the I2C Bus. As you can see, the signal at "Logic Low" is a bit higher than 0 Volts, and the signal at "Logic High" is a bit lower than 5 Volts. Also the signal take some time to transition from zero Volts to 5 Volts. That's how a good signal on the I2C Bus looks like. And if you have too many devices on the I2C Bus? Like 11 devices? Ok, so the signal doesn't look that bad right? At "Logic Low" the signal is much higher than before, but at "Logic High" the signals still just a bit lower than 5 Volts. And it takes now much less time to transition from 0 Volts to 5 Volts. Overall the signal looks very similar to an ideal digital signal. Especially compared to the signal with a single device. So that's a good signal, right? No! And the single reason is the higher voltage at "Logic Low". To understand how that's a problem, let's go back to our diagram. Our diagram shows the Clock Line and the Ground connected through a switch. But there are no mechanical switches in the device. Instead we use a transistor operating as a switch, so that by turning the transistor ON and OFF we can change the voltage on the Clock Line. When the transistor is OFF, the resistance between the Clock Line and the Ground is very high, so the transistor acts like an open switch. The voltage on the Clock Line is almost 5 Volts, so the signal is at "Logic High". Also there's practically no current flowing through the device. Now when the transistor is ON, the resistance drops considerably, but it's not zero. A current is now flowing through the device, and the voltage drop across the transistor corresponds to the voltage on the Clock Line. This voltage drop is almost zero, so that the signal at the Clock Line is at "Logic Low". If you have a smaller Pull-up Resistor you allow a larger current to flow through the device. That leads to a higher voltage drop across the transistor and to a higher voltage on the Clock Line. But this voltage should not exceed 0.4 Volts. Because it corresponds to the maximum current load of 3 mA that a transistor can handle. These values are specified by the I2C Bus User Manual. So the minimum value of the Pull-up Resistor is given by the worst case situation, when the voltage at the Clock Line is at 0.4 Volts and the maximum current of 3 mA is flowing through the Resistor. For a Power Supply of 5 Volts this gives a minimal Resistor of 1.53 kilo ohms, and for a Power Supply of 3.3 Volts, this gives a Resistor value of 970 ohms. Ok, so a Low-Level Voltage higher than 0.4 Volts indicates that the current on the transistor is larger than the maximum load of 3 mA. Now it doesn't mean that by forcing the Low-Level voltage beyond 0.4 Volts that your device with self-destruct or something. but it does mean that you're operating the device outside its specifications and communication on the I2C Bus can become unstable. Ok, so back to the question: How many breakout boards can you connect to the I2C Bus? Well, it depends on the breakout boards you have. Breakout boards are so easy to use because they already contain Pull-up Resistors. Most breakout boards seem to have Resistors ranging from 2.2 kilo ohms to 10 kilo ohms. Now when you connect multiple breakout boards together, you're effectively connecting those Resistors in parallel to each other, so in the best-case scenario with 10 boards, each with 10k Resistors, you get an effective resistance of 1k, which would be fine for 3.3 Volt devices. In case you don't know which Resistors are built on your board you just need to unplug your Power Supply, take a multimeter and measure the resistance between the bus line and Power Supply. This should give the total resistance on your I2C Bus. I hope you enjoyed this tutorial, if you have any questions please leave them in the comments below, and see you next time!
Info
Channel: BlueDot
Views: 190,641
Rating: undefined out of 5
Keywords: Arduino, I2C Bus, Pull-up Resistor, Sensor, Connection, Devices, I2C, I2C Protocol, Arduino Uno, I²C, I²C Bus, Communication, Multiple devices, serial data line, data line, SDA, serial clock line, clock line, SCL, tutorial, Hardware, Software, Introduction, Basics, How-to, I2C Devices, Applications, circuit interconnections, I2C communication, slave devices, master device, master, slave
Id: RPHP4fAisz8
Channel Id: undefined
Length: 6min 22sec (382 seconds)
Published: Wed Oct 19 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.