The I2C bus works with packages of data. It is used to get a number of bytes from a sensor. It is not meant to be communication bus between Arduino boards.
If you want to send text, then you have to determine how to send that. For example:
Always send 20 bytes, and fill everything with spaces.
Or send a variable number of bytes, you have to determine if you want to send the zero-terminator at the end or not.
Please do not use the .readString() with the I2C bus. It has a timeout and is not meant for a interrupt routine.
Okay. So, that's easy to do with two Unos, but for the easiest case, you can't be using the Serial Monitor as well so it complicates matters if you're not competent in "Arduino" yet. Since you took the moniker "thecoder251", I will presume you know how to code in some environment or another.
You need to code one Uno to simply send something when you, for example, click a button, or just send something periodically. What you don't want is it yammering uselessly. Set it to send sequential "Test1", "Test2" for example, one every second.
Then in the second Uno, use software serial to receive that message and display it on Serial Monitor.
Tips
don't use anything higher than 9600 baud, software serial is limited.
Wire UNO1 TX to Uno 2, pin 2, RX to pin 3, and connect their grounds.
and then set up Software Serial to receive on 2 and send on 3.
That should work. If not, post both codes here and we can move ahead.
I saw post 7. The processor on that board doesn't really have the guts for multiprocessing. So anything that you do, will be a hack. It can be a good hack, but it will still be a hack. Honestly, if I absolutely had to do it, I would use SPI with some handshaking lines.
Why do you need two processors? The last time I built anything with two, was several years ago. Since then, I have never seen any application that I could not do with one good processor.
Answer - awkwardly. The main reason is the asymmetry of a master-slave system. The I2C was not designed for open ended payloads. It was designed for a smart master device accessing simple register sets on very simple slave devices.
Since you draw my attention, you have not yet said at all, what your actual problem is. Don't you think it would be a good idea? You only referenced someones project. No word about whether you tried it or what you did...
If you wrote the code you posted, we still have no idea what it does, whether it works or not, if not, what the exact problem is...
Procedures: 1. Build the circuit as per Fig-1. 2. Upload the following sketches in Master UNO and Slave UNO/NANO Master Sketch:
#include<Wire.h>
char myMsg[10]= {0};
void setup()
{
Serial.begin(9600);
Wire.begin();
//------------------------
Wire.beginTransmission(0x13); //roll calling for the Slave
byte busStatus = Wire.endTransmission();
if (busStatus != 0x00)
{
Serial.println("I2C Bus communication problem...!");
while (1); //wait for ever
}
Serial.println("Slave found!");
}
void loop()
{
byte n = Serial.available();
if (n != 0)
{
byte m = Serial.readBytesUntil('\n', myMsg, sizeof myMsg);
myMsg[m] = '\0'; //insert Null character
Serial.println(myMsg); //debugging point
//----------------------------
Wire.beginTransmission(0x13); //Slave address is queued
Wire.write(myMsg, sizeof myMsg);
Wire.endTransmission(); //all queued data bytes are sent on ACK
}
}
Slave Sketch:
Create the sketch and upload into Slave UNO/NANO.
3. Open Serial Monitor (SM) of Slave. 4. Open Serial Monitor of Master. 5. Check that the following message has appeared on SM of Maser.
Slave found!
6. Select Newline option for the Line ending box of SM of Master. 7. Type Forum in the InputBox of SM of Master and then click on the Send button. 8. Check that Forum has appeared on Serial Monitor of Slave.
@thecoder251 In case you ask yourself what kind forum this is, perhaps I can explain.
The I2C bus can be used to transfer text between Arduino boards, but there are many things that can go wrong. So our first thought is: Don't do it.
We tell you that with kindness and being helpful. After all, we love that you are using Arduino and we want you to stay happy with Arduino.
If you still want to use the I2C bus, then we would like to know why. Because we have not even mentioned the 10 or 20 serious problems that you might run into. If you tell about your project, then maybe we can show ways to use only one Arduino board.
Without knowing the reason for using the I2C bus between Arduino boards, there might be a XY Problem: https://xyproblem.info/
For me, I want you to specify in what way you want to transfer the characters of the text as I mentioned in post #3.