Hi
does any one know why the following example causes the serial monitor to not print anything at all
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.
this works fine...
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?
Add a
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.
system
4
void PrintString(const char *str) {
any good reason for this particular long-winded bit of wheel-reinvention?
After making your example compile (adding loop, commenting the strange arrow,
it behaves as expected, it does not fail as claimed (on a Nano).
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() {}
21
test message 2
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
//<-------- 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
system
8
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?)