Hello,
I am trying to connect two ESP32 with the I2C bus. The master reads a button and is supposed to send the state of the button to the slave, which will let a LED shine.
Master:
#include <Wire.h>
#define SDA 21
#define SCL 23
int state = 0;
void setup() {
// put your setup code here, to run once:
Wire.begin(SDA,SCL);
}
void loop() {
// put your main code here, to run repeatedly:
state = digitalRead(14);
Wire.beginTransmission(2);
Wire.write(state);
Wire.endTransmission();
}
Slave:
#include <Wire.h>
int state = 0;
void setup() {
// put your setup code here, to run once:
ledcSetup(0, 5000, 8);
ledcAttachPin(19, 0);
Wire.begin(2);
Wire.onReceive(receiveEvent);
}
void receiveEvent(int b){
state = Wire.read();
if(state == LOW){
ledcWrite(0, 255);
}
else{
ledcWrite(0, 0);
}
}
void loop() {
}
I did research and this is my current sketch, the master is compilable, at the slave I get the following error:
sketch\EK512_4.ino.cpp.o:(.literal._Z5setupv+0x10): undefined reference to TwoWire::onReceive(void (*)(int))' sketch\EK512_4.ino.cpp.o: In function setup()':
C:\Users\morit\Desktop\TGM\3\SYT\EK\5.1\EK512_4/EK512_4.ino:25: undefined reference to `TwoWire::onReceive(void (*)(int))'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board ESP32 Dev Module.
Things I dont understand:
Can I just put any (imaginary) Adress in beginTransmission (at master), Wire.begin() (at slave)?
Why do I get this error trying to implement onReceive?
Are the specific diffrences - implementing I2C on a ESP?
What did I miss?
Pictures of circuit (bad):
Thanks for your time.
