I2C + Arduino

From ESE205 Wiki
Revision as of 21:38, 13 December 2016 by Djsullivan (talk | contribs)
Jump to navigation Jump to search
I2cA.png

The (Wire library) allows communication between the Arduino and other I2C compatible devices, for example another Arduino. To connect an I2C device, you must connect data(SDA) and clock(SCL) pins together, on the Uno these are pins A4 and A5. Also, both devices must share the same ground. Below is an example of a master reading from a slave. On the left is the code for the master, leaving out the argument on Wire.begin() initializes the device as a master. The requestFrom method takes the inputs of a slave address and how many bytes to take from that slave, then proceeds to send a signal to the slave asking for this information. On the slave side, initialize Wire.begin(address) with the address of that slave. Something to note: if the slave is an Arduino you may set the address for example 8 is used here, however other I2C devices may have a fixed address. The MPU6050 IMU has a fixed address of 0x68, so make sure any I2C devices planned to be used have different addresses.

Master.png
Slave.png