Hello every one ! welcome back ! It’s nice to show you my new tutorial after long time .Today we will learn how to connect multiple I2C device (typically for demo temperature sensor ) to the Arduino Uno .I recommend download datasheet of that I2C device you are going to interface with Arduino before jump into coding.
I2C communication Protocal
I²C (also referred as IIC or TWI ) pronounced as I square C is widely used communication protocal . If we wish to use multiple device with serially communicating device then I2C is the best way to communication between a microcprocessor and multiple device like motors , LCD , LED , EEPROM , etc . In this method we can control ( communicate ) up to 128 device which is almost impossible with conventional USART method . I2C bus consists of two lines called Serial Data Line (SDA) and Serial Clock Line (SCL) ,Communication between devices is master and slave based. Master generates clock signal, initiates and terminates data transfer. In many case microcontroller is master and it generate clock and address for multiple slave devices . From electrical point of view I2C devices use open drain (open collector) pins. In order to operate correctly SDA and SCL lines require pull up resistors. Typically 4.7kΩ resistors are used as shown in figure below .And The devices that we are using TWI must support TWI protocal .
The complete tutorial about I2C or TWI protocal can be found in this section . The short description of this project is below the code .
The code is very simple to understand . Here are some conceptual points used in the code
- First we included wire.h library for I2C transmission
- Also included LCD library and defined LCD used pin using LiquidCrystal lcd(12, 13, 8, 9, 10, 11); function
- After that we defined address for both I2C temperature device
- Enable I2C devices using wire.begin function with their respective address using data sheet of DS1261
- now get the data from temperature sensor write and request function
- And those data are displayed on Lquid Crystal Display also displayed on Serial communication window of arduino compiler
- That’s all
The complete project file with simulation , and code can be download from this link download complete project file .
Please share this project if this helped you !