Run slave from master arduino


I have a master-slave communication between two Arduino Mega boards (through i2C). The master sends a command to the slave in order to perform a given tasks. The system works when I open the Serial Monitor window from both Arduino boards. I mean, I open two Arduino IDE instances with their respective COM acquiring the data from USB cables. However, if I unplug the slave from the PC, while the master still is connected to the PC, the system does not work. The code in the slave includes an initialization of variables before the void setup() - with function configurations and void loop() - running the board-.

If I move the variable initialization inside the void setup(), I get errors because the variables inside the void loop() are not declared. How can I run the system if the slave is not connected directly to the PC?

My goal is to acquire all data just plugging the master to the pc uniquely (keeping the i2C communication with the slave).

If you need additional information, I can add it.


Are the I2C pull up resistors on the slave ? First try with some stronger (say 3.3 k) pull up resistors on the master to see if it can then survive the disconnection of the slave.
If that does not help, consider posting all your code here.

Have you provided the same supply to both of your Arduino boards ? Their Ground must be common.

Moreover check out the code, may be you have added the serial restriction in setup.