In this demo, I connected two Arduino UNO boards to communicate over I2C Bus.
To demonstrate the working of I2C in Arduino, let us build a small circuit. If you are using any other board then the following table will be useful to you as it describes the I2C pins on all the popular Arduino boards.ĪTmega328P Microcontroller used in Arduino UNO and Nano supports I2C Data Transfer speeds up to 400 kHz. In R3 of original Arduino UNO, there are two more pins near Digital IO Pin 13 (near the USB socket), dedicated to SDA and SCL. The A4 pin acts as SDA while the A5 pin acts as SCL. If you take a look at the pinout of Arduino UNO from the tutorial “ ARDUINO UNO PINOUT”, Analog Input pins A4 and A5 have an alternative function of I2C. I2C in ArduinoĪrduino supports I2C Communication. For more information on that, visit “ Basics of I2C Communication”. I made an extensive tutorial on basics of I 2C Communication. Using this address, master selects a particular slave for data transmission (send or receive) and the selected slave responds according to request. Each slave device connected to the I2C bus has a unique 7-bit address. I2C network supports multiple masters and multiple slaves (but we usually see single master and multiple slaves). The clock signal is also supplied by the master. Bus Masters are responsible for sending and receiving data to and from the slave devices. There are two types of devices that connect to the I2C Bus: Master and Slave.
Wire h library drivers#
Data is transmitted through the SDA line while the SCL line is used to synchronize the devices with the clock signal.īoth these bus lines are open-drain drivers and hence you have to use pull-up resistors to keep them HIGH.
Wire h library serial#
The I2C Bus consists of two wires called the Serial Data (SDA) and the Serial Clock (SCL). This may not seem much but it is sufficient for interfacing sensors, memories and displays at small distances. Using I2C, you can transmit data at rates 100 kbit/s (clock 100 kHz – Standard Mode), 400 kbit/s (clock 400 kHz – Fast Mode), 1 Mbit/s (clock 1 MHz – Fast Mode Plus) and 3.4 Mbit/s (clock 3.4 MHz – High Speed Mode). Hence, it is sometimes also known as TWI (Two Wire Interface).
This then sets a flag so the main loop starts when there is new data.I2C or I 2C is short for Inter-Integrated Circuit, a synchronous serial communication protocol developed by Phillips for communication between a fast Microcontroller and relatively slow peripherals (like Memory or Sensors) using just two wires. When the second atmega receives the data it causes an interrupt via Wire.onReceive(event). So the first atmega sends all the data via i2c to the second atmega 250 times per second. To have it run smooth, the motor controller (ESC) gets updated 250 times per second (250Hz). I've programmed it so that the first atmega receives al the data from sensors and the radio transmitter and then calculates the values for the motors, LEDs and servos. So i'm building my own quadcopter at this moment and I have designed a flight controller board for it using two atmega328p's.