Serial Rx buffer size increase redux

Need to increase the Nano serial receive buffer size to 128 bytes. Originally running IDE 1.6.7 Upgraded to 1.8.11

This question is specific to the process to increase buffer size which has appeared on the web two or three times in the last four years.

Modified Rx buffer size in Arduino/hardware/arduino/avr/cores/arduino/HardwareSerial.h and
USBAPI.h from 64 for 2048 RAM to 128.

Also modified Arduino/hardware/arduino/avr/libraries/SoftwareSerial/src/SoftwareSerial.h

SS_MAX_RX_BUFF 64 to SS_MAX_RX_BUFF 128

Proceeded in two ways: First to modify the original entries, second to create a second core named arduino_128 to hold the modified values, then edited the board file to add another version of nano, nano128 with the appropriate core build reference.

Neither method changes the buffer from 64 bytes. The second method did not result in a new board under Tools, boards.

I'm not interested in possible sketch code workarounds. Is it possible to change the Rx buffer size and if so how.

Thanks for your time.

Don't touch USBAPI.h, it is only used for USB serial. If you do not have a version of the official avr boards package installed, the file in the location you specified is the one to change.

If you do have a version of official arduino avr board package installed, however, the version of HardwareSerial that you need to modify is buried in the Arduino15/packages/arduino/hardware/avr/(version of installed board package)/core folder - the Arduino15 folder itself is located in C:/Users/AppData/Local on windows, note that AppData is hidden.

Note that it's generally not recommended to modify things under Arduino15, but I mean, that is how to achieve what you are asking.

Why does it hide stuff installed in such a weird hard to find place? because modern operating systems restrict writing to locations that could effect multiple users - such as program files - so while there is a copy of the avr core there, which gets used if you haven't installed anything via board manager, board manager couldn't write there - it would need administrator privs. Operating systems have recommended locations for applications to write data they use to, and that's where arduino puts it's Arduino15 folder (microsoft expects that users would never manually edit anything there, hence hidden folder). The situation is essentially similar on other mac and linux as well.

ITStechpro:
I'm not interested in possible sketch code workarounds. Is it possible to change the Rx buffer size and if so how.

If you need a bigger RX buffer, you're doing something wrong in your sketch - what exactly are you trying to do in your project?

I have one application where a bigger buffer was the most practical solution and I created a separate copy of the Arduino IDE with a different name. In that version I increased the buffer size. Now for normal programming I compile with the regular IDE and if I want to create a program with the bigger buffer I use the modified version of the IDE.

I don't remember the fine details but I think I just had to modify one thing in HardwareSerial.h

...R

Thanks to DrAzzy and Robin2 :slight_smile: Found the correct file set in AppData/Local/Arduino15 .....
Works fine now

No further replies needed ... many thanks for the assistance.

Why not use serialEvent() for preprocessing and storing long inputs?

DrDiettrich:
Why not use serialEvent() for preprocessing and storing long inputs?

In my application it was too much trouble to get the program to loop() fast enough.

...R

Then serialEvent() is the right solution, it does not burden nor block loop().

DrDiettrich:
Then serialEvent() is the right solution, it does not burden nor block loop().

It may - loop won't run again until serialEvent is complete.

ITStechpro:
No further replies needed ... many thanks for the assistance.

Are you sure you don't still want help with this?:

ITStechpro:
The second method did not result in a new board under Tools, boards.

It seems like it would be handy to be able to use the IDE to choose between a standard buffer size and an increased buffer size, depending on the application.

DrDiettrich:
Then serialEvent() is the right solution, it does not burden nor block loop().

That's not correct. serialEvent() is just another function that is called by main() after loop() completes. So the frequency at which serialEvent() is called depends on how long loop() takes to complete - just the same as if I put my Serial Input Basics code into loop()

...R

Thanks for the update. I assumed that serialEvent() was called from the receiver interrupt. As is this function is quite useless :frowning:

DrDiettrich:
Thanks for the update. I assumed that serialEvent() was called from the receiver interrupt.

A common misconception, not helped by the name of the function :slight_smile:

...R

As is this function [SerialEvent] is quite useless :frowning:

A common conclusion. :frowning:

westfw:
A common conclusion. :frowning:

Common, but not conclusive.

I've found use of SerialEvent() when designing my Arduino RC airplane library. Because there are several radios and sensors that use serial ports within the library, using SerialEvent() functions help out a ton. It helped make all of the communication logic completely abstracted from the sketch - making the example sketches super clean and easy to read.

Again, it's an edge case, but I wanted to give an example of why SerialEvent() is actually useful to have in you back pocket.

I suspect that it does not make a difference. Using serialEvent or not, in both cases you have to write code to handle the serial communication; and when you write your serial handler with functions, it keeps loop() a lot cleaner :wink: