Wire Library

Implements I2C on Z-Uno pins 9–16. Default is 9 for SCL and 10 for SDA. Other pin range can be selected using ZUNO_REMAP_SPINS() This library allows you to communicate with I2C devices.
  • begin()
  • requestFrom()
  • beginTransmission()
  • endTransmission()
  • write()
  • available()
  • read()
  • enableTS()
Z-Uno boards have the following I2C interfaces:
  • Wire(Wire0) — i2c on SCL(9) and SDA(10) pins (default)
  • Wire1 — i2c on SCL1(23) and SDA1(25) pins
You begin()
Pinout
Compatibility pin table
Z-Uno pin number Wire0 SCL Wire0 SDA Wire1 SCL Wire1 SDA
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Z-Uno can only be I2C master. Default pins can be changed during I2C initialization, but they should be in fast mode pin range: Note, by default Wire uses 32 bytes size received buffer. It it not enough for your task please bind custom buffer by means of begin() method. Until this moment Wire is able to operate in master mode only. Slave mode is in development. Note, any Wire object uses one DMA channel for data receiving. It occupies channel from begin() call. User can release channel and other occupied resources using end() method. Also, another one channel is engaged for the time of data transmission. All Wire objects have the following methods supported:
  • available()
  • begin()
  • beginTransmission()
  • end()
  • endTransmission()
  • read()
  • requestFrom()
  • setClock()
  • setWireTimeout()
  • transfer()
  • write()

#define SCL_PIN 11
#define SDA_PIN 12

I2CDriver alternative_I2C(SCL_PIN, SDA_PIN); 

void setup() {
    // …
    Wire.bindDriver(&alternative_I2C); // This instructs to use other pins than default
    // …
}
		
#include "Wire.h"

void setup() {
	Wire.begin(0, 1, 2);	// join i2c bus 
							// 0 - is a default master address, 
	                    	// We use alternate SCL pin = 1, SDA pin =2
	Serial.begin(115200);	// start serial for debug output
}

void loop() {
	Wire.requestFrom(8, 6);     // request 6 bytes from slave device #8

	while (Wire.available()) {  // slave may send less than requested
		char c = Wire.read();   // receive a byte as character
		Serial.print(c);        // print the character
	}
	delay(500);
}