Serial port String buffer truncated to ~115 characters on first upload

Customer:

I have a program that reads from the serial port and stores approximately 150 characters into a String. However, it only stores about 115 characters. After re-uploading the same program, it stores all 150 characters and works as expected, but I’m not sure how long it will last. Is this a memory issue?

Original message (Croatian)

izvinjavam se na smetnji, imam jedno pitanje.

Radi se o jednom programu koji cita serijski port i sprema u jedan String oko 150 znakova. I događa mi se to da mi spremi samo cca 115 znakova. Nakon ponovnog uploada istog programa meni sprema svih 150 znakova i onda radi kako treba no ne znam koliko dugo :slight_smile: Da li je to stvar do memorije?

Originally submitted via Facebook on 25 October 2016. Migrated to the forum for community visibility.

Customer:

The serial port reads 150 characters every time, so that part is working correctly.

Original message (Croatian)

Serijski port cita svaki put 150 znakova, tako da je to s njime uredu.

Soldered Support:

How are you certain the serial port is reading 150 characters if you cannot successfully store them in a String? Are you printing them directly without storing them in a String?

If so, this is likely a RAM issue. Here is a good tutorial with tips on how to save RAM: Optimizing SRAM | Memories of an Arduino | Adafruit Learning System

Please share your code in the next message so we can help better.

Original message (Croatian)

kako ste sigurno da serijski port čita 150 znakova, ako ih ne možete uspješno spremiti u String? Direktno ih ispisujete bez spremanja u String?
Ako da, vjerojatno je do RAM-a. Ovo je dobar tutorijal sa savjetima kako uštediti na RAMu: Optimizing SRAM | Memories of an Arduino | Adafruit Learning System
Pošaljite kod u sljedećoj poruci kako bismo mogli bolje pomoći.

Customer:

Yes, I’m printing character by character directly to the serial port.

Original message (Croatian)

Tako je, direktno znak po znak ispisujem na SP

Soldered Support:

That’s it then—it’s a memory issue. The 256 byte serial buffer was being reserved in RAM and you didn’t have enough space left for local variables.

Original message (Croatian)

to je to onda, memorija. 256 se inače rezerviralo u RAMu kao serial buffer i niste imali dovoljno mjesta za lokalne varijable.