Go Down

Topic: Serial Library requiring a lot of memory? (Read 1 time) previous topic - next topic

retrolefty

Quote
and the USB connection as well gets allocated a serial port and pulls in more resources from the USB libraries).


On a mega board? I could see USB stuff possibly required for a Leonardo type board but why would a bog standard Uno or Mega board require anything to do with USB in a sketch compilation?

Lefty

Coding Badly

Quote
This project is for an home automation system I am working on.


In that case, you should be considering RS-422, RS-485, Ethernet, CANBUS, LINBUS, etcetera instead of TTL-serial.

tobyb121


Quote
and the USB connection as well gets allocated a serial port and pulls in more resources from the USB libraries).


On a mega board? I could see USB stuff possibly required for a Leonardo type board but why would a bog standard Uno or Mega board require anything to do with USB in a sketch compilation?

Lefty


Yes sorry, my mistake, there's only 512 bytes allocated to buffers, still it makes up the majority of the RAM that is allocated by the serial library.

Nick Gammon


If you want, you can edit HardwareSerial.cpp and HardwareSerial.h and either change the buffer size (very easy), or turn off some of the serial ports (a bit harder but still relatively easy).


Quite right. Those calculations show where the memory is going. You can just "comment out" the declarations for Serial1, Serial2, Serial3 to save the memory their buffers use.

It's a pity the Serial library doesn't do a "new" to allocate the memory (eg. in Serial.begin) but that's life.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up