0% found this document useful (0 votes)
170 views

Arduino - Wire Library

Uploaded by

Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views

Arduino - Wire Library

Uploaded by

Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

A R D U I N O .

C(/)
C/EN/SOFTWARE) CLOUD(//CREATE.ARDUINO.CC) DOCUMENTATION COMMUNITY BLOG(//BL

Reference   Language (//www.arduino.cc/en/Reference/HomePage) | Libraries (//www.arduino.cc/en/Reference/Libraries)


| Comparison (//www.arduino.cc/en/Reference/Comparison) | Changes (//www.arduino.cc/en/Reference/Changes)

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.

The Wire library implementation uses a 32 byte buffer, therefore


any communication should be within this limit. Exceeding bytes in
a single transmission will just be dropped.

To use this library


#include <Wire.h>

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

- SFR Ranger Reader (/en/Tutorial/SFRRangerReader): Read an


ultra-sonic range finder interfaced via the I2C.
- Add SerCom (/en/Tutorial/SamdSercom): Adding mores Serial
interfaces to SAMD microcontrollers.

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)

Last revision 2019/12/24 by SM

Reference Home (//www.arduino.cc/en/Reference/HomePage)

Corrections, suggestions, and new documentation should be posted to the Forum


(http://arduino.cc/forum/index.php/board,23.0.html).

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

Trademark NEWSLETTER Help Center FOLLOW US


(//www.arduino.cc/en/Trademark/HomePage) (//support.arduino.cc)

Enter
Contact Us (//www.arduino.cc/en/contact-us) your email to sign up SUBSCRIBE

Distributors (//store.arduino.cc/distributors) (https://www.facebook.com/official.ard


(https://www.instagram.com/ard
(https://twitter.com/arduin
(https://github.com/
(https://www.l
(https://
Careers (//careers.arduino.cc)

Terms Of Service Privacy Policy


© 2021 Arduino (//www.arduino.cc/en/Main/CopyrightNotice)
(//www.arduino.cc/en/Main/TermsOfService) (//www.arduino.cc/en/Main/Priv

Help(https://support.arduino.cc)

You might also like