user26868: I'm writing the character 1 from a node.js XBee using the code sp.write("1"); to my Arduino's XBee. Then on my Arduino's XBee I read it like this (inside a loop):
  if (XBee.available()) {
    do {
      r = XBee.read(); 
      Serial.print(r);
    } 
    while (r != -1);

And the input char r shows up as 1� instead of just 1. Why is this and how can I remove the added invalid character from the char? Also is this char now 2 chars, how does this work? Thanks.
EDIT:
Arduino code:
#include <SoftwareSerial.h>

// Global variables
int AnalogPin = A2; // has much less jumpy readings than A0 (maybe A0 slightly damage from overuse)
int ledPin = 13;
SoftwareSerial XBee(2,3); // RX, TX

// Setup
void setup() {
  Serial.begin(9600);
  pinMode(AnalogPin, INPUT);
  XBee.begin(9600);
  for (int i=0; i<100; i++) 
    Serial.print("\n"); 
  // Random ID
  Serial.println("Listening...");
}

// MAIN LOOP
void loop() {
  char r;
  // Allow data reception while waiting for handshake confirmation
  while (1) { 
      if (XBee.available()) {
        do {
          r = XBee.read(); 
          Serial.println(r);
        } 
        while (r != -1); 
      }
      delay(500);
        if (r == 'Q') {
          Serial.println(r);
          Serial.println();
          Serial.println("Turning LED OFF.");
          digitalWrite(ledPin, LOW);
          Serial.println();
          exit(1);
        }
       else if (r == '1') {
          Serial.println(r);
          Serial.println();
          Serial.println("Turning LED on.");
          digitalWrite(ledPin, HIGH);
          Serial.println();
        }     
  }
} // end main loop

Node code:
var SerialPort = require('serialport');
var express = require('express');
app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var ON_DEATH = require('death');

    /* ------------- Connecting to Serial Port ---------------- */
    var portName = '/dev/cu.usbserial-AD01SSII',
    portConfig = {
        baudRate: 9600,
    };

    var sp;
    sp = new SerialPort(portName, portConfig);
    sp.on("open", function (err) {

        console.log("Sending LED on signal.");
        console.log("Ctrl+C: quit and send LED off signal.");
        sp.write('1');

        // Cleanup when termination signals are sent to process
        ON_DEATH(function(signal, err) {
            var death_msg = 'Q';
            sp.write(death_msg);
            sp.close();   
            console.log("\n\nSending reset signal to nodes.\n\n")
            process.exit();
        })
*/
  }); // end open

All I'm really trying to do here is turn an LED on and off when I start or end the node program. Maybe I'm just too exhausted to think straight. 

user10794:  do {
      r = XBee.read(); 
      Serial.print(r);
    } 
    while (r != -1);

Think about it. Since you tested for XBee.available() you will have at least one iteration of this loop. And then you do a second read, and print it, before finding that the second character is -1.
You need to re-order your loop, or your tests. The second character will be what -1 looks like on your monitor.

A better loop would be:
  while (XBee.available()) {
      r = XBee.read(); 
      Serial.println(r);
  }

This is the standard way of looping and reading. You won't get -1 from the read here, because if something is available, you will get that something.

26868: <p>I'm writing the character <code>1</code> from a node.js XBee using the code <code>sp.write("1");</code> to my Arduino's XBee. Then on my Arduino's XBee I read it like this (inside a loop):</p>

<pre><code>  if (XBee.available()) {
    do {
      r = XBee.read(); 
      Serial.print(r);
    } 
    while (r != -1);
</code></pre>

<p>And the input char <code>r</code> shows up as <code>1�</code> instead of just <code>1</code>. Why is this and how can I remove the added invalid character from the char? Also is this char now 2 chars, how does this work? Thanks.</p>

<p>EDIT:</p>

<p>Arduino code:</p>

<pre><code>#include &lt;SoftwareSerial.h&gt;

// Global variables
int AnalogPin = A2; // has much less jumpy readings than A0 (maybe A0 slightly damage from overuse)
int ledPin = 13;
SoftwareSerial XBee(2,3); // RX, TX

// Setup
void setup() {
  Serial.begin(9600);
  pinMode(AnalogPin, INPUT);
  XBee.begin(9600);
  for (int i=0; i&lt;100; i++) 
    Serial.print("\n"); 
  // Random ID
  Serial.println("Listening...");
}

// MAIN LOOP
void loop() {
  char r;
  // Allow data reception while waiting for handshake confirmation
  while (1) { 
      if (XBee.available()) {
        do {
          r = XBee.read(); 
          Serial.println(r);
        } 
        while (r != -1); 
      }
      delay(500);
        if (r == 'Q') {
          Serial.println(r);
          Serial.println();
          Serial.println("Turning LED OFF.");
          digitalWrite(ledPin, LOW);
          Serial.println();
          exit(1);
        }
       else if (r == '1') {
          Serial.println(r);
          Serial.println();
          Serial.println("Turning LED on.");
          digitalWrite(ledPin, HIGH);
          Serial.println();
        }     
  }
} // end main loop
</code></pre>

<p>Node code:</p>

<pre><code>var SerialPort = require('serialport');
var express = require('express');
app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var ON_DEATH = require('death');

    /* ------------- Connecting to Serial Port ---------------- */
    var portName = '/dev/cu.usbserial-AD01SSII',
    portConfig = {
        baudRate: 9600,
    };

    var sp;
    sp = new SerialPort(portName, portConfig);
    sp.on("open", function (err) {

        console.log("Sending LED on signal.");
        console.log("Ctrl+C: quit and send LED off signal.");
        sp.write('1');

        // Cleanup when termination signals are sent to process
        ON_DEATH(function(signal, err) {
            var death_msg = 'Q';
            sp.write(death_msg);
            sp.close();   
            console.log("\n\nSending reset signal to nodes.\n\n")
            process.exit();
        })
*/
  }); // end open
</code></pre>

<p>All I'm really trying to do here is turn an LED on and off when I start or end the node program. Maybe I'm just too exhausted to think straight. </p>
 10794: <pre class="lang-c++ prettyprint-override"><code> do {
      r = XBee.read(); 
      Serial.print(r);
    } 
    while (r != -1);
</code></pre>

<p>Think about it. Since you tested for <code>XBee.available()</code> you will have at least one iteration of this loop. And then you do a <em>second</em> read, <strong>and</strong> print it, before finding that the second character is -1.</p>

<p>You need to re-order your loop, or your tests. The second character will be what -1 looks like on your monitor.</p>

<hr>

<p>A better loop would be:</p>

<pre class="lang-c++ prettyprint-override"><code>  while (XBee.available()) {
      r = XBee.read(); 
      Serial.println(r);
  }
</code></pre>

<p>This is the standard way of looping and reading. You won't get -1 from the read here, because if something is available, you will get that something.</p>
