Argument of type Void is incompatible

Hi,

I am trying to write a simple i2c reader and when i come to compile the code i get an error " argument of type “void()()" is incompatible with parameter of type "void()(int)”

code is below, the error relates to line Wire.onReceive(read_data);

any help would be greatly appreciated.

#include <Wire.h>
 
// Define Slave I2C Address
#define SLAVE_ADDR 9
 
 
// Variable for received data
int rd;
 
// Variable for blink rate
int br;

void setup() {
 
  
  // Initialize I2C communications as Slave
  Wire.begin(SLAVE_ADDR);

  // Function to run when data received from master
  Wire.onReceive(read_data);
  
  // Setup Serial Monitor 
  Serial.begin(9600);
  Serial.println("I2C Slave Demonstration");
}
 
void loop() {
   delay(50);
  rd = Wire.read();
  Serial.println(rd);
  // Calculate blink value
  br = map(rd, 1, 255, 10, 100); 
}

void read_data() {
  // read one character from the I2C
  rd = Wire.read();
  // Print value of incoming data
  Serial.println(rd);
    
}

Your read_data function requires an int parameter for how many bytes to receive:

void read_data(int howMany)

This is necessary even if you don’t need the howMany parameter.

Thanks @rickkas7 i come from the Arduino world where you seem to get away with things like this!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.