Hi 2 Yun's are connected by I2C connection (SCL and SDA) 1 master and 1 slave. When I upload the example sketches provided by arduino IDE it works, but If I slightly modify it to display output via Console and rather than serial, then it is not working. Please let me know where am I going wrong ?
Working Code:
[CODE BEGIN] MASTER
// Wire Master WriteR
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop()
{
Wire.beginTransmission(8); // transmit to device #8
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
delay(500);
}
[CODE END]MASTER
[CODE BEGIN] SLAVE
// Wire Slave Receiver
#include <Wire.h>
void setup()
{
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while (1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
[CODE END] SLAVE
DEFECTIVE CODE:
[CODE BEGIN] MASTER[/color]
// Wire Master Writer
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop()
{
Wire.beginTransmission(8); // transmit to device #8
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
delay(500);
}
[CODE END]MASTER
[CODE BEGIN] SLAVE
// Wire Slave Receiver
#include <Wire.h>
#include <Console.h>
void setup()
{
Bridge.begin();
Console.begin();
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
// Serial.begin(9600); // start serial for output
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while (1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Console.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Console.println(x); // print the integer
}
[CODE END] SLAVE
No output is coming in case of Defective Code.
For Working Code, the slave receives nicely the output
1
2
3
4
.
.
.
I want same thing but via wifi, so using Console commands but its not working.
Help appreciated.
Thanks in advance.
Regards,
Swaroop[/code]
