Placing strings in flash



  • Hi.

    This line in a sketch:

    sendSketchInfo("Nod 200 - Altan", "V1.3");
    
    

    places the string both in flash and in ram. And when doing this:

    sendSketchInfo(PSTR("Nod 200 - Altan"), "V1.3");
    

    Places the string only in flash but it don't seem to work.

    the line:

    #include <avr/pgmspace.h>
    

    is in the begining of the sketch.

    Would like to save the ramspace

    Any ideas?


  • Mod

    @kk02067 why do you get the impression that it doesn't work?

    Does the code not compile? If so, are there any error messages?

    Does the compile, but execution fails? If so, how does it fail?



  • @mfalkvidd
    The string in the gateway becomes unreadable.


  • Mod

    @kk02067 unreadable in what way? You're not giving us much to go on here 🙂


  • Hero Member

    @kk02067 said:

    PSTR

    You cannot just replace any "string" in a sketch with a PSTR macro. As these strings are stored in a 'different' memory space (due to the AVR Harvard architecture) you also need other methods to handle these strings. As far as I know these are not implemented in MySensors.

    A few ways to save RAM space:

    • (simple) if you are using the same text at multiple places. Store the text once in a char array and point to and combine the unique parts
    • (more complex) handle the copy from the ROM to RAM space yourself in a separate routine with a pgm_read_byte(str) function. Just search one of the arduino forums.


  • @AWI thanks for clarifying. I will read up on the subject. Strings i C is not my favourite subject.


Log in to reply
 

Suggested Topics

51
Online

11.4k
Users

11.1k
Topics

112.7k
Posts