4

I'm running a program on a ATtiny85 and running into problems because of a lack of available RAM. When I ran avr-nm on my ELF file I found that SoftwareSerial was taking up a lot of RAM even though I'm just using it to set the data transfer rate with mySerial.begin(9600); and nowhere else.

So I'm wondering if there is another way of doing this without using so much memory:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0,1);

mySerial.begin(9600);

2 Answers 2

6

Simplest thing would probably be to edit your copy of SoftwareSerial.h and replace #define _SS_MAX_RX_BUFF 64 on line 42 by something smaller. If your loop() runs fast enough (no delays, no blocking code) you could probably get away with buffering only a very few bytes.

Or you could rewrite the library so that, instead of buffering the incoming bytes, it handles them to you for processing. See for example this receive-only UART code based on the USI port for an illustration of the approach.

2
  • Where would I go to edit my SoftwareSerial.h? Also my program is working with a camera and I am using delays to send a clock impulse does that mean that lowering the buffer rate would not work for me? Jun 14, 2016 at 20:12
  • 2
    @AngelLockhart: It's probably somewhere like $ARDUINO_HOME/hardware/arduino/avr/libraries/SoftwareSerial/src/SoftwareSerial.h, where $ARDUINO_HOME is you Arduino installation directory. You can use the search facilities of your OS. If your clock pulses are very short (a few microseconds or so), the delays may be OK. Otherwise you should learn to control timings without delay(). Jun 14, 2016 at 20:21
-1

My ESP8266 was randomly crashing any time I used SoftwareSerial from framework-arduinoespressif8266 or https://github.com/plerup/espsoftwareserial, due to too low memory.

https://github.com/CrazyRobMiles/Esp8266EdgeSoftwareSerial fixed this problem. I still receive data from the sensor via SoftwareSerial, and there is 4000 bytes more RAM compared to the alternative implementations.

4
  • how should it help with the problem in the question?
    – Juraj
    Mar 25, 2022 at 6:30
  • @Juraj Well, the arduino SoftwareSerial.h somehow requires more 4000 bytes of RAM to transfer a buffer of 64 bytes (why???). The linked library can be used as a direct replacement for SoftwareSerial, and has a much smaller footprint. I now realize the code is called Esp8266EdgeSoftwareSerial, and might not run on other architectures. Is that your implied question? Mar 25, 2022 at 7:07
  • I doubt that the standard SoftwareSerial has a 4000 byte RAM overhead, this must be something else. Anyway, the OP uses an ATtiny85, so answers for Esp8266 don't help. Mar 25, 2022 at 7:13
  • @thebusybee: Okay, I'll delete my answer. SoftwareSerial.h seems to have a huge overhead for the projects I work on. If I include it and use it, without changing any other parameter, ESP.getMaxFreeBlockSize() and ESP.getFreeHeap() both take a huge hit. I'll keep on investigating, and file a bug report (I'm not the only one complaining about memory use). For what it's worth, OP's question still need a proper answer : the accepted one leads to 404 and tells OP to rewrite the lib. :-/ Mar 25, 2022 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.