Hello,
I2C onnection works on:
UNO with UNO
Leonardo with Leonardo
But UNO with Leonardo did not work.
Please help me understand why it does not work, and what need to do.
Thanks
Hello,
I2C onnection works on:
UNO with UNO
Leonardo with Leonardo
But UNO with Leonardo did not work.
Please help me understand why it does not work, and what need to do.
Thanks
edit -> copy for forum
in the IDE and next paste it here in a reply.1.
UNO is Slave / Leonardo is Master
2.
Anything else not connected to Arduino.
The target is: Leonardo sending a Value -> UNO receiving a value and turning on Arduino led.
Master (Leonardo)
#include<Wire.h>
int LED = 13;
int x = 0;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
Wire.begin();
}
void loop() {
Serial.println(x);
digitalWrite(LED, HIGH);
delay(500);
x = 3;
Wire.beginTransmission(9);
Wire.write(x);
Wire.endTransmission();
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
}
Slave (UNO)
#include<Wire.h>
int LED = 13;
int x = 0;
void setup() {
Serial.begin(9600);
pinMode (LED, OUTPUT);
Wire.begin(9);
Wire.onReceive(receiveEvent);
}
void loop() {
Serial.println(x);
if (x == 3) {
Serial.print("Hello - 1\n");
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(5000);
}
if (x == 0) {
Serial.print("Hello - 2\n");
digitalWrite(LED, HIGH);
delay(400);
}
}
void receiveEvent(int bytes) {
x = Wire.read();
}
Resolved, was a bad connection
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.