initial serial monitor test . puzzled by response

Following Simon Monk book "Programming Arduino", p. 39 . Here is my code

void setup()
{
Serial.begin(9600);
Serial.println(1234);
}

void loop()
{
}

and the output to monitor is shown in the file. The monitor reports the most significant digit, then the number itself

When using the next program in his book with the following code

// sketch 03-04
void setup()
{
Serial.begin(9600);
int a = 2;
int b = 39;
int c = a + b;
Serial.println(c);
}
void loop()
{}

The serial monitor reports that seen in the second file. Again first we print the most significant digit, then the number.

I don't understand why.

Thanks,

Don

2014-05-12_1330.png

2014-05-12_1337.png

Instead of printing anonymous data, try:

  Serial.print("Value = ");
  Serial.println(1234);

What do you see in the Serial Monitor application, then?

Nothing in the code looks like it would explain what you are seeing. What OS?

The monitor reports the most significant digit, then the number itself

Not here it doesn't

Works fine on the Due, IDE 1.56 r2.
Perhaps your IDE could use an update?

My IDE is 1.05, OS in Mac 10.9.2. Will look into updating IDE.

IDE 1.05 seems up to date.

When using code

void setup()
{
  Serial.begin(9600);
  Serial.print("Value =  ");
  Serial.println(1234);
}

void loop()
{
}

The results in Serial Monitor are shown below. It immediately prints V the after a moment Value

2014-05-12_1428.png

Could this be a workaround?

void setup()
{
  Serial.begin(9600);
  Serial.print("");
  Serial.print("Value =  ");
  Serial.println(1234);
}

void loop()
{
}

...or a small delay after Serial.begin(9600) or test with another baudrate.

They're at 1.05 r2. The last revision for 1.56 r2 was "JSSC: Fixed NPE when RXCHAR event with no bytes (José Pereda)" Not sure if something similar was done in 1.05 r2 or even if this was the issue ... but there is a newer revision available.

I just re-downloaded ver. 1.05 and the behavior is unchanged. The code

void setup()
{
  Serial.begin(9600);
  Serial.println(3234);
}

void loop()
{}

Still produce output 33234 in the serial monitor. Immediately you get 3 followed later by 3234.

Similarly the sketch

// sketch 03-04
void setup()
{
  Serial.begin(9600);
  int a = 2;
  int b = 49;
  int c = a + b;
  Serial.println(c); 
}
void loop()
{}

results in 551 in the serial monitor, the 5 appearing immediately followed shortly by 51

It works perfectly on my Uno with Arduino 1.05 on Ubuntu.

...R

I understand it works for everybody else. Here is some further tests by adding lines

void setup()
{
  Serial.begin(9600);
  Serial.println(1234);
  Serial.println(5678);
  Serial.println("hello world");
  
}
void loop()
{}

Gives the first Serial output.

If I change the code to print a blank line so that it looks like

void setup()
{
  Serial.begin(9600);
  Serial.println();
  Serial.println(1234);
  Serial.println(5678);
  Serial.println("hello world");
  
}
void loop()
{}

then I get the next result. It's a workaround, but it should not be necessary. Why is my iMac (10.9.2) doing this?

2014-05-13_1155.png

2014-05-13_1159.png

Other possibilities ... Arduino clone, faulty Arduino, faulty serial pins, wrong type of USB serial adapter (type or level mismatch - ttl/rs232/3.3V/5V), faulty USB cable, USB cable too long, using USB Hub without adapter connected, incorrect serial settings in OS, etc.

dlloyd:
Other possibilities ... Arduino clone, faulty Arduino, faulty serial pins, wrong type of USB serial adapter (type or level mismatch - ttl/rs232/3.3V/5V), faulty USB cable, USB cable too long, using USB Hub without adapter connected, incorrect serial settings in OS, etc.

It's not a clone. Using one from the Sparkfun kit. Tried both serial settings with identical results. Don't know how to attack the other issues you mention. Cable works fine if I include a Serial.println(); in code. Also blinking diode sketch works fine. May go out to see if I can get another Uno at Radio Shack.

Any other suggestions?

Don

I would try another USB cable if you have one.
Also try lowering or turning off the serial port buffer settings in your OS.
EDIT: Check the board setting in Arduino.

Sorry, but I don't have that extra cable. Also don't know how accomplish your second request on an iMac.

Check that the Tools ---> board ---> "your board" is set to the one Sparkfun recommends.

It is set to Uno. I was using a powered usb hub to power the uno. Have just added a 9v battery for power, but results are the same. Also connected directly to usb connector on iMac with unchanged results. Always get an extra character unless I insert that print blank line statement.

Does the problem still happen if you use a terminal emulator on the Mac instead of the Serial monitor in the IDE ?