Go Down

Topic: serial stop char array size (Read 827 times) previous topic - next topic

joeblogs

Hi
does any one know why the following example causes the serial monitor to not print anything at all
Code: [Select]

struct fred { const char id[3]; const char msg[64]; };     <-------- 64

struct fred x[2]
{
{ { "12" }, {"test message 1"} } ,
{ { "21" }, {"test message 2"} }
};


void PrintString(const char *str) {
const char *p = str;

while (*p) {

Serial.print(*p);
p++;
}
Serial.println();
}

void setup()
{
Serial.begin(115200);

PrintString(x[1].id);
PrintString(x[1].msg);
}



yet if i change 64 in the first line of code to 33 or less it works fine.

BulldogLowell

this works fine...
Code: [Select]

struct fred {
   char id[3];
   char msg[64];
};

fred x[2]
{
  { {"12"} , {"test message 1"}},
  { {"21"} , {"test message 2"}} 
};


void setup()
{
  Serial.begin(9600);
  Serial.println(x[1].msg);
}

void loop()
{

}


where are you in your overall memory usage?

PaulMurrayCbr

Add a
Code: [Select]

while(!Serial) /* do nothing */ ;


after the Serial.begin to make sure that serial is ready to be printed to. Yeah - it shouldn't make any difference. But it might.

http://paulmurraycbr.github.io/ArduinoTheOOWay.html

AWOL

#3
May 24, 2017, 01:24 pm Last Edit: May 24, 2017, 01:25 pm by AWOL
Code: [Select]
void PrintString(const char *str) {any good reason for this particular long-winded bit of wheel-reinvention?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Whandall

After making your example compile (adding loop, commenting the strange arrow,
it behaves as expected, it does not fail as claimed (on a Nano).

Code: [Select]

struct fred { const char id[3]; const char msg[64]; };     //<-------- 64

struct fred x[2]
{
  { { "12" }, {"test message 1"} } ,
  { { "21" }, {"test message 2"} } 
};   


void PrintString(const char *str) {
  const char *p = str;
 
  while (*p) {
   
    Serial.print(*p);
    p++;
  }
  Serial.println();
}

void setup()
{
  Serial.begin(250000);
 
  PrintString(x[1].id);
  PrintString(x[1].msg);
}
void loop() {}
Code: [Select]
21
test message 2


Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

joeblogs

bulldog, doesnt work on mine (due), still limited to 33 not 64, baud rate up to 250000 still no difference

Paul, your right it has no effect

AWOL, trying to narrow down a problem ive been having, thought it might be a String class issue so trying to rule it out

Program size: 26,916 bytes (used 5% of a 524,288 byte maximum)

I think its a memory problem of some kind but dont know where to start

joeblogs

#6
May 24, 2017, 01:38 pm Last Edit: May 24, 2017, 01:44 pm by joeblogs
//<-------- 64, was typed into the browser


just tried it standalone in the arduino ide and it does work fine, must be a problem in another source file causing it

cheers for the replies

AWOL

Whatsoever the numbers 33 and 64 signify in this discussion?

(It took us until reply #5 to find out this was posted in the wrong section?)
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up