Description

onRequest() registers a callback function to be called when a controller device requests data from a peripheral device.

This function is part of the Wire library. See the Wire main page for more information.

Syntax

Wire.onRequest(handler)

Parameters

  • handler: the callback function to be called when data is requested. It should have the following signature:
    • Parameters: none.
    • Return: void (nothing).

Returns

Nothing.

Example Code

void setup() {
  Wire.begin(0x08);             // Join I2C bus as peripheral with address 0x08
  Wire.onRequest(requestEvent); // Register callback function
}

void requestEvent() {
  Wire.write("Hello");  // Send data to controller
}