Placing strings in flash
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.
is in the begining of the sketch.
Would like to save the ramspace
@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?
The string in the gateway becomes unreadable.
@kk02067 unreadable in what way? You're not giving us much to go on here
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.