Missing lines when prining strings received trough I2C

Hello,

I'm not a real expert so I hope someone can help me.

I have two Arduino Nanos. One Master, One Slave.

The master send every 10 seconds 20 strings of 28 bytes. There is a delay between sending the strings of 5 ms.
The slave receives the 20 strings and based on the first character in the string it places the strings in separate, unique variables.

After receiving the strings I print the strings on the serial monitor. This works fine if I use: Serial.println(StringA+StringB);
The serial monitor prints the 10 rows nicely.

However, if I first create a simple calculation like StringTotal=StringA+StringB. And then print Serial.println(StringTotal); The serial monitor starts skipping lines.

Can anyone help me on this topic?

Firmware_V07_B01_08_Slave.ino (3.91 KB)

Can anyone help me on this topic?

Yes, don't use the String class on an AVR Arduino. They have very limited memory and the String class fragments that memory too fast. Once you are on that limit the rest of the code execution is unpredictable.

  String I2CStr;

Pylon; Thanks for your reply. I'm not an expert can you advise me how to change this?

Use only c strings (character arrays) where you have exact control over memory usage.

BTW, I2C is not suited well for transmitting strings, although it works.

All variables used in interrupt context (the onReceive handler is called in interrupt context) and normal code must be declared volatile otherwise the compiler might optimize parts away.

Please, post your NANO-Master codes using code tags (</>).