This is an issue i have been fighting with for a while. I am having it with both my UNO boards.
I am currently in the process of building a packet system that will allow for easy communication between arduino and a java program on my computer. Everything is going fine except for the fact that after sending exactly 12 127 byte arrays communication just stops. The size of the arrays does affect how many get though.
Of course i have done extensive debugging and completely ruled out the java side as the cause. This can be easily reproduced with just a few lines of code and the serial monitor. Here is a simple sketch that will reproduce the issue.
void setup() {
Serial.begin(115200);
}
void loop() {
byte *data = new byte[127];
for (int i = 0; i < 126; i+=2) {
data[i] = 43;
data[i + 1] = 35;
}
data[125] = 33;
data[126] = 10;
Serial.write(data, 127);
delay(1000);
}
You dont actually need to set any data in the array thats just to make the output readable.
That code results in the following serial output.
+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+!
+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+!
+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+!
+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+!
+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+!
+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+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++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#+#
As you can see with that code it sends 13 byte arrays just fine but number 14 is corrupted and after that the console does not receive any more data. Restarting ether the board or the serial monitor resets the connection and it runs again with the exact same output except for the last line which seems to be random.
It should be noted this only seems to happen when sending a byte array via Serial.write As far as i can tell all other serial communication works fine but i have not done a lot of testing with the other write/print functions because they are no good to me.
I am running windows 10 with Arduino IDE 1.8.1
These are the bourds i have tested with:
Im curious if anyone else has this same issue. And ofcourse i would like to know i anyone has any idea how to fix this issue.
Edit: after more testing it seems the program is actually freezing on the Serial.write call. I tried blinking an led every time the program loops (Turn on before writing then off 100ms after writing) When it reaches the last write the led turns on byt never turns off indicating that the program is freezing on the serial.write call.
Edit2: i just figured it out... The issue is i am so used to java that i completely forgot that garbage collection is not a thing here... So i am running out of memory.