user6394: I've got this quite basic code running on an Arduino Mega 2560, and the output is looking like I have the serial settings wrong, though I can't work out what to change.
void setup()  
{
  Serial.begin(9600);
  Serial.println("test123");
}

void loop()
{
  Serial.println("test" + millis());
}

The output looks like this:
ð¦·Z©÷
×ï¾üÿ7ß^|ïüûÿVÏuØëo~ìÿÓûzëýÿ{ßþ©×xñ×¤¿ïßûÏûýoÏ¿îãõI
õfwi÷`p¬½Ïª»QáÀª»¦·ð¦·Z©÷
test123
D



4ñjü¯÷~µÞMz¹Ý~¼
Ûþ}iû}ÒÖ­¦Ç¿÷ÿÂï½Õ¾;îö

I'm using the inbuilt "Serial Monitor" in the Arduino suite with settings 9600 baud and no line endings.
I see that the first println in setup() is sending the data as expected but all other comms are coming through as nonsense.
Any suggestions of what to do?

user89: Just as a minor addition to Peter's excellent answer and comments on concatenation and implicit typecasting with String objects:  
Alternatives to construct the message (as a char[]) to be send might be: 

use sprintf()


char buffer[80];  // for the complete output
char value[4];    // for millis(), which returns an unsigned long

sprintf(buffer, "I'm running for %u ms now", millis());
Serial.println(buffer);       

Note that sprintf() uses quite some memory!

build the message 'manually':


 char buffer[80] = "I'm running for "; 

 itoa(millis(), value, 10);  
 strcat(buffer, value);
 strcat(buffer, " ms");
 Serial.println(buffer);


user42: This is unfortunately not valid in C++:
"test" + millis()

Rather than concatenating two strings, it's actually doing pointer arithmetic. It's taking the memory address where "test" is stored, and offsetting by the value retrieved from millis(). The result is a totally arbitrary memory location which gets treated like a string.
Generally speaking, it's arguably best to avoid string concatenation on Arduino anyway unless absolutely necessary. The reason is that it can use more memory than you might expect.
A simpler approach would simply be to do the serial output as a sequence of individual operations, e.g.:
Serial.print( "test" );
Serial.println( millis() );

Note the difference between print() and println(). The first one doesn't add a line break at the end, but the second one does.

6394: <p>I've got this quite basic code running on an Arduino Mega 2560, and the output is looking like I have the serial settings wrong, though I can't work out what to change.</p>

<pre><code>void setup()  
{
  Serial.begin(9600);
  Serial.println("test123");
}

void loop()
{
  Serial.println("test" + millis());
}
</code></pre>

<p>The output looks like this:</p>

<pre><code>ð¦·Z©÷
×ï¾üÿ7ß^|ïüûÿVÏuØëo~ìÿÓûzëýÿ{ßþ©×xñ×¤¿ïßûÏûýoÏ¿îãõI
õfwi÷`p¬½Ïª»QáÀª»¦·ð¦·Z©÷
test123
D



4ñjü¯÷~µÞMz¹Ý~¼
Ûþ}iû}ÒÖ­¦Ç¿÷ÿÂï½Õ¾;îö
</code></pre>

<p>I'm using the inbuilt "Serial Monitor" in the Arduino suite with settings 9600 baud and no line endings.</p>

<p>I see that the first println in <code>setup()</code> is sending the data as expected but all other comms are coming through as nonsense.</p>

<p>Any suggestions of what to do?</p>
 89: <p>Just as a minor addition to Peter's excellent answer and comments on concatenation and implicit typecasting with <code>String</code> objects:  </p>

<p>Alternatives to construct the message (as a <code>char[]</code>) to be send might be: </p>

<ol>
<li>use <code>sprintf()</code></li>
</ol>

<p></p>

<pre><code>char buffer[80];  // for the complete output
char value[4];    // for millis(), which returns an unsigned long

sprintf(buffer, "I'm running for %u ms now", millis());
Serial.println(buffer);       
</code></pre>

<p><em>Note that <code>sprintf()</code> uses quite some memory!</em></p>

<ol start="2">
<li>build the message 'manually':</li>
</ol>

<p></p>

<pre><code> char buffer[80] = "I'm running for "; 

 itoa(millis(), value, 10);  
 strcat(buffer, value);
 strcat(buffer, " ms");
 Serial.println(buffer);
</code></pre>
 42: <p>This is unfortunately not valid in C++:</p>

<pre><code>"test" + millis()
</code></pre>

<p>Rather than concatenating two strings, it's actually doing pointer arithmetic. It's taking the memory address where <code>"test"</code> is stored, and offsetting by the value retrieved from <code>millis()</code>. The result is a totally arbitrary memory location which gets treated like a string.</p>

<p>Generally speaking, it's arguably best to avoid string concatenation on Arduino anyway unless absolutely necessary. The reason is that it can use more memory than you might expect.</p>

<p>A simpler approach would simply be to do the serial output as a sequence of individual operations, e.g.:</p>

<pre><code>Serial.print( "test" );
Serial.println( millis() );
</code></pre>

<p>Note the difference between <code>print()</code> and <code>println()</code>. The first one doesn't add a line break at the end, but the second one does.</p>
