Arduino - Wire Library
Arduino - Wire Library
C(/)
C/EN/SOFTWARE) CLOUD(//CREATE.ARDUINO.CC) DOCUMENTATION COMMUNITY BLOG(//BL
Wire Library
This library allows you to communicate with I2C / TWI devices. On
the Arduino boards with the R3 layout (1.0 pinout), the SDA (data Functions
line) and SCL (clock line) are on the pin headers close to the AREF pin.
The Arduino Due has two I2C / TWI interfaces SDA1 and SCL1 are near - begin (//www.arduino.cc/en/Reference/WireBegin)()
to the AREF pin and the additional one is on pins 20 and 21.
- requestFrom
As a reference the table below shows where TWI pins are located on
various Arduino boards. (//www.arduino.cc/en/Reference/WireRequestFrom)()
Board I2C / TWI pins - beginTransmission
Uno, Ethernet A4 (SDA), A5 (SCL) (//www.arduino.cc/en/Reference/WireBeginTransmission)
Mega2560 20 (SDA), 21 (SCL)
()
Leonardo 2 (SDA), 3 (SCL)
Due 20 (SDA), 21 (SCL), SDA1, SCL1 - endTransmission
(//www.arduino.cc/en/Reference/WireEndTransmission)
As of Arduino 1.0, the library inherits from the Stream functions,
()
making it consistent with other read/write libraries. Because of this,
send() and receive() have been replaced with read() and write(). - write (//www.arduino.cc/en/Reference/WireWrite)()
- available (//www.arduino.cc/en/Reference/WireAvailable)
Note ()
There are both 7- and 8-bit versions of I2C addresses. 7 bits identify - read (//www.arduino.cc/en/Reference/WireRead)()
the device, and the eighth bit determines if it's being written to or
read from. The Wire library uses 7 bit addresses throughout. If you - SetClock (//www.arduino.cc/en/Reference/WireSetClock)
have a datasheet or sample code that uses 8 bit address, you'll want ()
to drop the low bit (i.e. shift the value one bit to the right), yielding
an address between 0 and 127. However the addresses from 0 to 7 - onReceive
are not used because are reserved so the first address that can be (//www.arduino.cc/en/Reference/WireOnReceive)()
used is 8. Please note that a pull-up resistor is needed when
- onRequest
connecting SDA/SCL pins. Please refer to the examples for more
informations. MEGA 2560 board has pull-up resistors on pins 20 - 21 (//www.arduino.cc/en/Reference/WireOnRequest)()
onboard.
Examples
- Digital Potentiometer (/en/Tutorial/DigitalPotentiometer):
Control an Analog Devices AD5171 Digital Potentiometer.
- Master Reader/Slave Writer (/en/Tutorial/MasterReader):
Program two Arduino boards to communicate with one another
in a Master Reader/Slave Sender configuration via the I2C. Help(https://support.arduino.cc)
- Master Writer/Slave receiver
PROFESSIONAL EDUCATION STORE (//STORE.ARDUINO.CC) Search on Arduino.cc
(/en/Tutorial/MasterWriter):Program
(//WW W.ARDUINO.CC/PRO) (//WWWtwo
. A RArduino
D U I N O . boards
C C / E D Uto
)
communicate with one another in a Master Writer/Slave
A R D U I NReceiver
O . C(/)
C/EN / S O F T W A R Evia
configuration ) the I2C.
CLOUD(//CREATE.ARDUINO.CC) DOCUMENTATION COMMUNITY BLOG(//BL
See also
- Master Writer (http://arduino.cc/en/Tutorial/MasterWriter)
- Master Reader (http://arduino.cc/en/Tutorial/MasterReader)
- SFR Ranger Reader
(http://arduino.cc/en/Tutorial/SFRRangerReader)
- Digital Potentiometer
(http://arduino.cc/en/Tutorial/DigitalPotentiometer)
The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License
(http://creativecommons.org/licenses/by-sa/3.0/). Code samples in the reference are released into the public domain.
Help(https://support.arduino.cc)
PROFESSIONAL EDUCATION STORE (//STORE.ARDUINO.CC) Search on Arduino.cc
(//WWW.ARDUINO.CC/PRO) (//WWW.ARDUINO.CC/EDU)
Back to top
A R D U I N O . C(/)
C/EN/SOFTWARE) CLOUD(//CREATE.ARDUINO.CC) DOCUMENTATION COMMUNITY BLOG(//BL
Enter
Contact Us (//www.arduino.cc/en/contact-us) your email to sign up SUBSCRIBE
Help(https://support.arduino.cc)