solved: how to use strings instead of const char?

Hi, in my program a GSM module is controlled by an Arduino Mega sending AT-commands to the GSM module.

Example to list all SMS stored on the GSM module: The command string to do so is: AT+CMGL="ALL",1 This command shall be sent as a string via a serial interface with a function _cell.print(). The code is here:

_cell.print("AT+CMGL=\"ALL\",1\r");
      gsm.WhileSimpleRead();

The function gsm.WhileSimpleRead() receives the answer from the GSM module and displays it.

This works ok, but now I wanted to save dynamic RAM and replaced the constant string by a string stored in flash memory (the F macro cannot be used here, because _cell.print() cannot handle the macro):

...
const char cmgl_cmd[] PROGMEM  = {"AT+CMGL=\"ALL\",1\r"};

_cell.print(cmgl_cmd);
gsm.WhileSimpleRead();

This does not work, but why?

If the ‘F’ macro doesn’t work with ‘cell.print’ that means the ‘print’ method doesn’t have an overload that works with type ‘_FlashStringHelper *’. So, it doesn’t sound like there’s a method that will directly pull a string from PROGMEM and use it. You can check the library’s source code to be sure. If it doesn’t, then you’ll need to transfer the string you want from PROGMEM to a RAM buffer yourself. Then call ‘_cell.print’ as usual.

thanks, I'll do so

If the .print() method can't accept the F() macro, it is unlikely it will work with any string in FLASH. You will have to have a buffer in RAM and copy each message before you use it. Make sure that the buffer is larger than any of your messages. You will need to use a function for copy from FLASH/PROGMEM to RAM. I think the function strncpy_P(buffer, PROGMEM_message, sizeof buffer); will do the trick. Then print 'buffer'.