Running low on variable space, PROGMEM doesn't help [SOLVED]

Somehow using a PROGMEM array takes up 10 bytes MORE space. I'm working on a serial command interface for my uno, here's the full code:

Actually, no. The whole thing (327 lines) is too big to post. The full sketch and schematic can be found here:

CLICK ME!

As you can see, I tried using PROGMEM, but, as I said earlier, that takes up 10 bytes more SRAM.

Serial.println("Unknown command. Type \'/\' for a list of commands");

Keep these strings in progmem. Use the F() macro.

.

AWOL: Serial.println("Unknown command. Type \'/\' for a list of commands");

Keep these strings in progmem. Use the F() macro.

I can't get it to save me any SRAM. Sometimes it even does this:

sketch_nov26b.ino:142:28: note: in expansion of macro 'F'
Error compiling.

That was a helpful error message. Maybe the "142:28" refers to line 142, character 28?

OK, good luck

bbrk24: .I can't get it to save me any SRAM. Sometimes it even does this:

sketch_nov26b.ino:142:28: note: in expansion of macro 'F'
Error compiling.

That was a helpful error message. Maybe the "142:28" refers to line 142, character 28?

Posting the code that actually caused the error along with the error message might give us a chance.

Yes, the 142:28 means just that.

Use the Reply button. At the bottom of the text entry field, there is a link, Additional Options (yeah, yeah, I know; it's a shitty rendition of a link; not my idea, and the idiot that came up with it insists its perfect). Use that to post your code HERE!

Delta_G: Posting the code that actually caused the error along with the error message might give us a chance.

Yes, the 142:28 means just that.

Line 142 read:

           Serial.println(F(listOfLongStrings[0]));

Apparently you can't put arrays inside of an F().

I know a bit of Javascript, and while sometimes that's helpful, there are some differences. Sometimes, I'll get a C++ error. Sometimes I can get help from someone I know who knows C (like with #include instead of import), but not always. That's when I come here. Click here for the INO!

Why do you have so many variables defined as static longs? Each one of those takes up 4 bytes of SRAM. Also, that String array isn't doing you any good - quit using the String class, and use a char array.

All that said - I am not even sure what it is that this code is meant for, or what it does exactly; I have a feeling that whatever it is doing, it likely could be greatly simplified in order to use less SRAM. I don't have any objective reasons for feeling this way - it's just a gut reaction to looking at the code, and having been a software developer for 25 years...

What is it you are trying to accomplish here?

F is only for constant strings. Things in quotes in print statements.

Like this sort of thing.

Serial.println(F("This is a constant string going into progmem"));

You can't put your array element into progmem because it is variable. It might change. Your code can't change things in progmem.

I just put F() macros everywhere they were needed, and compiled the code for the 168 processor, with only 1024 RAM, without getting a low memory warning.

Just 621 bytes of RAM used. I could probably save some more.

cr0sh: Why do you have so many variables defined as static longs? Each one of those takes up 4 bytes of SRAM. Also, that String array isn't doing you any good - quit using the String class, and use a char array.

All that said - I am not even sure what it is that this code is meant for, or what it does exactly; I have a feeling that whatever it is doing, it likely could be greatly simplified in order to use less SRAM. I don't have any objective reasons for feeling this way - it's just a gut reaction to looking at the code, and having been a software developer for 25 years...

What is it you are trying to accomplish here?

I'm counting how many times each command is used. What if someone doesn't reset for a while and uses a command more than a couple hundred times? A static unsigned int would overflow.

As for why I'm writing this, I want a command-based interface (like minecraft commands).

AWOL: I just put F() macros everywhere they were needed, and compiled the code for the 168 processor, with only 1024 RAM, without getting a low memory warning.

Just 621 bytes of RAM used. I could probably save some more.

Could you give me a download link? Thanks in advance. All of you, your help is greatly appreciated.

Also, please people, slow down. I can only post once every 10 minutes.

bbrk24: I'm counting how many times each command is used. What if someone doesn't reset for a while and uses a command more than a couple hundred times? A static unsigned int would overflow.

unsigned int gives you 65535 as a max count. WAY more than a couple of hundred.

Delta_G: unsigned int gives you 65535 as a max count. WAY more than a couple of hundred.

Oh. Arduino Uno is an 8-bit machine, I thought the maximum for an unsigned int was only 255. 65535 would be a 16-bit number. EDIT: replacing all the long variables with unsigned int variables compiles at 1531 bytes, but someone said he got it down to less than 700. EDIT 2: I updated the .ino at this site. EDIT 3: What I was thinking of was a byte variable type.

bbrk24:
Oh. Arduino Uno is an 8-bit machine, I thought the maximum for an unsigned int was only 255. 65535 would be a 16-bit number.

Perhaps a little reading on variable types in the Arduino environment is in order then.

https://www.arduino.cc/en/Reference/VariableDeclaration

A list of available types is towards the bottom.

but someone said he got it down to less than 700.

Yes, I did that by making sure most of the constant string prints used the F() macro. I didn't even touch the variables - I assumed you had good reason for having them the size they were.

EDIT 2: I updated the .ino at this site.

Distinct lack of F() macros.

I’ll call this problem solved. I got it down to less than 1200 bytes.
EDIT:

AWOL:
You can get it to half that.

I added some more F() macros and some more commands too, compiling at 681 bytes (33%) of dynamic memory and 9,756 bytes (30%) of program storage space.

You can get it to half that.