Serial Library requiring a lot of memory?

I have been using avr-size.exe to track my memory foot print for my project to ensure I am within the save limits depending on what chip I am on. I started adding the Serial communication functions today and noticed a spike in SRAM usage by 680bytes by just initializing Serial.

With Serial.being(9600) in the setup loop:
text data bss dec
30538 1652 1001 33191

Without Serial.being(9600) in the setup loop:
text data bss dec
27998 1636 321 29955

I tested this with several baud rates and it stays at 680 bytes. And btw I am using an Arduino Mega 2560 R2 if it matters.

Does anyone know if 680 byte consumption is normal? Is there another library alternative that has less overhead requirement (have another project where I need Serial communication but I cannot spare 680 bytes of RAM)?

FYI I did this test without ANY serial commands being used other than Serial.begin.

Well if it's compiling for a mega board then it defines serial send and rec software buffers (in SRAM) for all four possible hardware serial ports even if you aren't using them. Others have complained of this behaviour but don't know if more intelligent method is forthcoming.

Lefty

A good chunk of that is the Tx and Rx buffers for the serial data.

If you need more SRAM, consider the '1284P - 16 Kbyte of SRAM, twice what the '2560 has. Dual serial ports, 32 IO lines.
I have a nice Duemilanove style board for the 366/644/1284 series of chips.

http://www.crossroadsfencing.com/BobuinoRev17/
Can use onboard FTDI module, mikroe483 from mouser.com, or offboard with FTDI Cable, FTDI Basic, or similar CP2102 module.

A good chunk of that is the Tx and Rx buffers for the serial data.

If you need more SRAM, consider the '1284P - 16 Kbyte of SRAM, twice what the '2560 has. Dual serial ports, 32 IO lines.
I have a nice Duemilanove style board for the 366/644/1284 series of chips.

Cross Roads Electronics
Can use onboard FTDI module, mikroe483 from mouser.com, or offboard with FTDI Cable, FTDI Basic, or similar CP2102 module.

Bob, I've finally gotten around to populating the 1284 Duemilanove board you sold me. Still waiting on the 1284p chip but it's checking out with a 644P chip I had on hand. I really think if you or someone offered this in a completed assembled package with a included CP2102 cable that it could be a good seller.

Have you had any problems yet with the software mods needed for the IDE? Any libraries not work? I've only run blink and a few other simple sketches just to verify basic operation so far.

Only question I have is the intended purpose of the 6 pin header in the corner of the board. Not real clear to me from the schematic what pins it actually breaks out? So far I didn't put header pins on it.

Lefty

I have not seen any problems with 1.0. I tend not to use many libraries - Serial, SPI, I2C, VirtualWire are about it. Anything else, I read the datasheet and write my own stuff.

Maybe I'll look into 1284 kits after tax season. I can't take that on right now. Got fencing club taxes, personal taxes, college financial aid forms, and a 56 seven-segment display project to finish first.
Just delivered another 10 Mega screwshields, those are pretty popular. Board & 4 connector types, easy to package up, no ESD concerns.

CrossRoads:
I have not seen any problems with 1.0. I tend not to use many libraries - Serial, SPI, I2C, VirtualWire are about it. Anything else, I read the datasheet and write my own stuff.

Maybe I'll look into 1284 kits after tax season. I can't take that on right now. Got fencing club taxes, personal taxes, college financial aid forms, and a 56 seven-segment display project to finish first.
Just delivered another 10 Mega screwshields, those are pretty popular. Board & 4 connector types, easy to package up, no ESD concerns.

And about my last question?

Only question I have is the intended purpose of the 6 pin header in the corner of the board. Not real clear to me from the schematic what pins it actually breaks out? So far I didn't put header pins on it.

Sorry, missed that one - it's to select whether A4/D18 & A5/D19 show up on the Analog header pins, or whether SDA/SCL show up there.
I would put male pins there with two 2-pin jumpers like these to select.
http://www.dipmicro.com/store/JUMPER2

Finally got the schematic on the website too.

Sorry, missed that one - it's to select whether A4/D18 & A5/D19 show up on the Analog header pins, or whether SDA/SCL show up there.
I would put male pins there with two 2-pin jumpers like these to select.
2-Pin 0.1” Jumper Closed Top Gold Plated - dipmicro electronics

Ah, got it, I'll have to add that.

Thanks;

Lefty

retrolefty:
Well if it's compiling for a mega board then it defines serial send and rec software buffers (in SRAM) for all four possible hardware serial ports even if you aren't using them. Others have complained of this behaviour but don't know if more intelligent method is forthcoming.

Lefty

Thanks for the info, I will need to do a test on my Uno board which only has 1 serial port.

CrossRoads:
A good chunk of that is the Tx and Rx buffers for the serial data.

If you need more SRAM, consider the '1284P - 16 Kbyte of SRAM, twice what the '2560 has. Dual serial ports, 32 IO lines.
I have a nice Duemilanove style board for the 366/644/1284 series of chips.

Cross Roads Electronics
Can use onboard FTDI module, mikroe483 from mouser.com, or offboard with FTDI Cable, FTDI Basic, or similar CP2102 module.

My main project is actually using one of these chips (love em! the extra ram is awesome) but my issue was that I need to communicated to individual devices over longer range than I2C will allow without a booster chip and my cheapest solution that I could find was the ATTiny45-20PU chip (NeWark sells these at 62 cent a piece if you buy 25 or more at a time) and I was worried about the memory foot print. I guess I will just order one and run software serial on it (or attempt to run it... 250 bytes of memory) and see where I stand. All the ATTinyies will have to do is read things like sensor values and transmit them to the main board which if I can get software serial to work on it would be perfect solution for the project.

Does the ATtiny45 need to receive data or just send?

Just needs to send. Basically all I need it to do is identify itself with a byte value, then sent it's sensor info

Is it possible for multiple ATtiny45s to transmit simultaneously on the same wire?

Good point... on second thought I guess the best option would be for it to be called on by the main board, then send its data, then stop transmitting until called upon again. Anyone know the distance limitation of an Arduino RX TX signal? This project is for an home automation system I am working on. If the distance RX TX can travel is not sufficient I will need to start looking into forwarding hubs (which should be simple enough by using yet again another ATTiny45 as in: receive signal, forward signal to other ATTiny's within range, read received return signal, forward return signal to main board).

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). Currently they allocate 64 byte buffers on Tx and Rx, which comes to 640 bytes (4 hardware UART and the USB connection as well gets allocated a serial port and pulls in more resources from the USB libraries). If you still need all of these you have no choice really but to leave them all on, and reduce buffer size, but be aware that if you do this you need to check the serial ports regularly to make sure there isn't any data to read.

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

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.

retrolefty:

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.

tobyb121:
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.