By now you should be thinking “how do we differentiate each device on the bus?”… Each device has a unique address. We can write data to a device, or read data from a device. In our Arduino situation, the board is the master and the devices on the I2C bus are the slaves. This distance can be extended with the use of a special IC, which we will examine during the next I2C chapter.Įach device can be connected to the bus in any order, and devices can be masters or slaves. The maximum length of an I2C bus is around one metre, and is a function of the capacitance of the bus. Sometimes you may see in a particular device’s data sheet the use of different value pull-up resistors – for example 4.7k ohm. Like anything, some testing on a breadboard or prototype circuit will determine their necessity. However if you are running a string of devices, use two 10 kilo ohm resistors.
If you are only using one I2C device, the pull-up resistors are (normally) not required, as the ATmega328 microcontroller in our Arduino has them built-in. If you have another type of board, check your data sheet or try the Arduino team’s hardware website.Īnd finally, if you are using a bare DIP ATmega328-PU microcontroller, you will use pins 27 for SDA and 28 for SCL. The bus wiring is simple: If you are using an Arduino Mega, SDA is pin 20 and SCL is 21, so note that shields with I2C need to be specifically for the Mega. Those of you with an Arduino Uno or 100% compatible board, you will be using pins A4 for SDA (data) and A5 for SCL (clock): There are many applications, such a real-time clocks, digital potentiometers, temperature sensors, digital compasses, memory chips, FM radio circuits, I/O expanders, LCD controllers, amplifiers, and so on.Īnd you can have more than one on the bus at any time, in fact the maximum number of I2C devices used at any one time is 112.įrom a hardware perspective, the wiring is very easy. And our Arduino boards can control them all. Here is a nice introductory video from NXP:Īs there are literally thousands of components that use the I2C interface. This reduced the number of wires to two (SDA – data, and SCL – clock). In the late 1970s, Philips’ semiconductor division (now NXP) saw the need for simplifying and standardising the data lines that travel between various integrated circuits in their products. I2C is an acronym for “Inter-Integrated Circuit”. Furthermore it would be in your interest to have an understanding of the binary, binary-coded decimal and hexadecimal number systems. In this article we will learn the necessary theory, and then apply it by controlling a variety of devices. The I2C bus can be a complex interface to master, so we will do my best to simplify it for you. In this first of several tutorials we are going to investigate the I2C data bus, and how we can control devices using it with our Arduino systems.