writeI2C()

[Inter Integrated Circuit]
bool writeI2C(unsigned char data);

Description

Write an unsigned char to the I2C buffer

Parameters

data: character to be written to the follower chip.

Returns

A boolean value that indicates that the buffer is full.

Example Code

The code initializes the I2C communication with the SDA pin connected to pin 4, and the SCL pin connected to pin 5.

Then begins an I2C transmission to the follower chip with the address 0x20.

Write value 42 to the buffer.

Ends the I2C transmission, sends the data to the follower chip, and sends a stop condition on the I2C bus.

void setup() {
    beginI2C(4, 5);  // initializes the I2C communication with the SDA pin connected to pin 4, the SCL pin connected to pin 5
}

void loop() {
    beginI2CTransmission(0x20);  // begins an I2C transmission to the follower chip with the address 0x20
    writeI2C(42);                   // sends the value 42 to the follower chip
    endI2CTransmission(true);       // ends the I2C transmission
}
c bool writeI2C(const char* data); ### Description Write a string to the I2C buffer
### Parameters data: the pointer to the string to be written to the follower chip.
### Returns A boolean value that indicates that the buffer is full.
### Example Code The code initializes the I2C communication with the SDA pin connected to pin 4, and the SCL pin connected to pin 5.
Then begins an I2C transmission to the follower chip with the address 0x20.
Write the string “x is” to the buffer.
Ends the I2C transmission, sends the data to the follower chip, and sends a stop condition on the I2C bus.
```c void setup() { beginI2C(4, 5); // initializes the I2C communication with the SDA pin connected to pin 4, the SCL pin connected to pin 5 }
void loop() { beginI2CTransmission(0x20); // begins an I2C transmission to the follower chip with the address 0x20 writeI2C(“x is”); // sends the string “x is” to the follower chip endI2CTransmission(true); // ends the I2C transmission } ```
bool writeI2C(const int* data, int length);

Description

Write an array of integers to the I2C buffer

Parameters

data: the pointer to the first element in the array of integers to be written to the follower chip. length: the number of elements in the array.

Returns

A boolean value that indicates that the buffer is full.

Example Code

The code initializes the I2C communication with the SDA pin connected to pin 4, and the SCL pin connected to pin 5.

Then begins an I2C transmission to the follower chip with the address 0x20.

Write the array of integers {1, 2, 3, 4, 5} to the buffer.

Ends the I2C transmission, sends the data to the follower chip, and sends a stop condition on the I2C bus.

static const int data[] = {1, 2, 3, 4, 5};

void setup() {
    beginI2C(4, 5);  // initializes the I2C communication with the SDA pin connected to pin 4, the SCL pin connected to pin 5
}

void loop() {
    beginI2CTransmission(0x20);  // begins an I2C transmission to the follower chip with the address 0x20
    writeI2C(data, 5);             // sends the array of integers {1, 2, 3, 4, 5} to the follower chip
    endI2CTransmission(true);       // ends the I2C transmission
}

Notes and Warnings

  • The writeI2C() function data types accepted are unsigned char, const char*, and const int* (together with the lenght parameter).