hardware and wiring:
I am using a Mega 2560 (chinese) as master and a RF-Nano (chinese) as slave. I already checked that SCL and the SDA in the Nano are positioned as usual on the pin A5 and A4, while I am not sure which of the Mega pin should I use; those on 20 and 21 to which SCL and SDA seem to be assigned, or the pins directly named SCL and SDA? From what I read online it seems to be irrelevant and they give me the same result (which is notting) anyway.
The Mega, which is alimented by USB which allow serial communication with the computer, power the nano and the wiring is the following:
mega - nano
SDA - A4
SCL - A5
GND - GND
V3.3 - 3V3
forgive me for not uploading an image but is is very short and simple, there is no resistors or anything. if needed soon I will upload an image but in this moment I have to run.
I have copied this code from Arduino website, without applying any change
insert code here
Master:
// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop() {
Wire.requestFrom(8, 6); // request 6 bytes from slave device #8
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}
Slave:
// Wire Slave Sender
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Sends data as an I2C/TWI slave device
// Refer to the "Wire Master Reader" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
When I check the serial communication with the computer for debugging, nothign appears.
I would expect the to receive “hello “ written repeatedly, as the master is calling the slave char, to print it, but the sheet is completely blanc.
Would you help me to find out which is the problem? Thanks!
