Arduino Mega, increase SERIAL_RX_BUFFER_SIZE in HardwareSerial.h - no effect

Dear Forum Members,

I've used an Arduino Mega as a serial datalogger and it has been working well. My serial message to be received is longer than the default 64 bytes, so I increased the buffer size to 256 (SERIAL_RX_BUFFER_SIZE in HardwareSerial.h 64 -> 256) with success following these instructions in:

However today I fixed a bug on the sketch, uploaded the new version and the received message was truncated back to 64 bytes. When I opened the Arduino IDE to do the fix I ran suggested updates to boards and libraries. I cannot remember anymore which updates these were and don't know how to check. I assumed that some of these updates had overwritten the HardwareSerial.h and my changes but no, they were still there.

I check from the sketch code the value of the SERIAL_RX_BUFFER_SIZE and it gives me 64 instead of 256 I've inserted to HardwareSerial.h. Changing SERIAL_RX_BUFFER_SIZE to any value in HardwareSerial.h has no effect.

After extensive poking and Googling I'm still clueless how to debug. Please advise.

EDIT: My OS is macOS Sierra 10.12.5 and IDE version 1.8.2

  • K

The Arduino IDE includes the latest Arduino AVR Boards hardware package (which contains the core library and hardware definitions used by the Arduino Mega board) at the time of the release. This is located at {Arduino IDE installation folder}/hardware/arduino/avr.

When you update to a new version of Arduino AVR Boards the hardware package is installed to a different location and the outdated version included with the Arduino IDE is no longer used. The new location is /Users/(username)/Library/Arduino15/packages/Arduino/avr.

Thanks for your reply.

The only instance of HardwareSerial.h seems to be in:


grep -lr 'SERIAL_RX_BUFFER' *

Does not seem to yield hits on files outside that directory and the only place where the value of that constant is being set in that header file.

  • K

I believe the Arduino15 folder is hidden. You can get to it by clicking the link in the Arduino IDE after File > Preferences > More preferences can be edited directly in the file.

The trick I like to use for determining if the file I'm editing is actually the one used by the compiler is to temporarily add the line:


somewhere in the file, then do a compilation. That will very quickly answer that question :) .

This worked! I was compiling from this hidden directory all the time. Many, many thanks!

  • K