Closed LoungeFlyZ closed 3 years ago
Good question, this looks weird. The serial1 should not influence the usb serial (Serial
). Does this also happens multiple times?
Yes it happens every time. Comment out that line it works. Uncomment, it stops working.
But here is the strange thing. The Serial.println is printing an empty string with a \n
. That is why I get the blank line. If I print the new_str length I get 0
.
It's like using Serial1 breaks String after Serial.println(str);
Can you try with normal string instead of the character array? I guess there is some weird c memory management stuff going on. I am not into that right now, doing a lot of other stuff recently. You may better ask in the arduino irc or the forum for help. I am not sure if this is related to this library. If you find the issue, please let me know.
ok will do. The reason for the char array is that is what I get from reading Serial1. I was working on a simple bridge but needed to concat strings from serial1 until I got a full message. I wanted to send
Closing this issue. @NicoHood it was a memory issue. During String concat (called when + was used) it was trying to realloc and failing because the __malloc_margin is set to 128 and this didn't leave enough room.
Short answer is not to use String.
Test work around is to use extern size_t __malloc_margin; __malloc_margin = 32;
and it all starts to work.
Thanks to timemage on IRC for hunting and tracking this down.
Thanks for the feedback! I remember those guys, they are awesome! Helped me a lot too!
Timemage remembered you too!
I'm struggling to understand what might be happening when loading what looks like a relatively simple sketch on my megas 16u2.
The code:
This results in:
However, if I comment out
Serial1.begin(9600);
from the setup, then I get the expected output.I was attempting to build a simple bridge that receives messages from the i/o MCU and use your keyboard library to do things. However I struck a problem with dealing with strings as shown above.
I am hoping you might have some pointers given your experience with 16u2. I am hoping its not something totally stupid that I've done :)