Serial read only reads single characters

oh my god,

I've been working with Arduino and stuff for over 3 years now and have never ever run into this much annoyance. I have everything working on my Mac and all, but apparently stuff is running different on Windows devices? Or I am ready for the looney bin, thats the second option.

Anyway; the issue at hand is; Arduino will only read single individual characters. So for example, I sent the number 121 to the arduino, he reads it as 1 and then a 2 and then a 1. Not as a whole number.

I have the following code;

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
}

void loop() {
  byte incoming;

  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    incoming= Serial.read();
    // set the brightness of the LED:
    Serial.println(incoming, byte);
  }
}

So yeah, this works on mac, doens't work on windows? I am totally clueless as the bloody tutorial differs nothing from my code ?
arduino.cc/en/Tutorial/Dimmer

I've read something about this atoi stuff but I've never ever used that before and it has always worked properly so far.

So where did we go wrong?

Gosh!
I don't know what to say - this has never come up before.

Much.

So what's the problem here? Serial.read always just reads a single character. It's even documented that way. In what way does this create any problems between your Mac and a Windows box?

Korman

@KKZOOI:

    Serial.println(incoming, byte);

Does that compile? Really?

Shouldn't it be

    Serial.println(incoming, BYTE);

Anyhow... I'm not sure what you are asking. What do you expect to happen? What, exactly, happens differently between the Mac and Windows?

Regards,

Dave

Okay

Sorry for the somewhat RAGE post of yesterday.

The issue at hand is the following.

When sending a number (for instance 123) to my Arduino (from the Serial Monitor in the Arduino software (WINDOWS)) my Arduino only registers (using the Serial.read()) a single character (so 123 is read as an individual 1, an individual 2 and an individual 3.

When I do this on my Mac, it just registers 123 as a whole?

Do I have a magic Mac? If not so, is there a quick fix to this problem I am having?

ps. I've read the documentation on Serial.read() many times because of this. I am wondering why there are examples on the site (for instance the Fader) that don't address this issue, but just show that the Serial.read can readout numbers from 0-255 (1 byte)?

Are you sending just a ASCII 123 (Character {) or are you sending ASCII 49 (Character 1), ASCII 50 (Character 2) and ASCII 51 (Character 3)? Or do you send something entirely different? This isn't really clear from your post, but makes a very big difference.

Also, is the code you posted the one you use? What do you use to send the data on your PC or Mac? Is that the same program?

Korman

Below is some test code that takes numbers sent from the serial monitor, captures them into a string, convers the string into a number, and uses the number to control a servo. It may have some parts of interest to you.

// zoomkat 10-27-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// Servo.h default servo position 1500 on startup
// for Arduino IDE 0019 and later

#include <Servo.h>
String readString;
Servo myservo;  // create servo object to control a servo

void setup() {
      Serial.begin(9600);
        myservo.attach(9);
        }

void loop() {

        while (Serial.available()) {
        delay(10);

        char c = Serial.read();  //gets one byte from serial buffer
        readString += c;} //makes the string readString

      if (readString.length() >0) {
      Serial.println(readString);
      int n;
      char carray[6];
      readString.toCharArray(carray, sizeof(carray));
      n = atoi(carray);
      myservo.writeMicroseconds(n);
      //myservo.write(n);
      readString="";
      }
   }