Serial-Monitor - softwareserial...

Hello

Is the serialmonitor able to read from softwareserials? i just had a sketch where this didnt work. does it not work in general?

Thanks
Jkb

Perhaps the question you should be asking yourself is "How is the software serial connected to the serial monitor?", and take the argument from that starting point.

The way I see it:
actually the serialmonitor is connected via usb to the arduino. so it only can use serial and not serial1, 2 or 3 (ArduinoMEGA).
would you say that is right?

but if that is true, why should someone print out lines which are definately for the user at a softwareserial?

/**
 * Copyright (c) 2009 Andrew Rapp. All rights reserved.
 *
 * This file is part of XBee-Arduino.
 *
 * XBee-Arduino is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * XBee-Arduino is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with XBee-Arduino.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <XBee.h>
#include <SoftwareSerial.h>

/*
This example is for Series 1 (10C8 or later firmware) or Series 2 XBee radios
 Sends a few AT command queries to the radio and checks the status response for success
 
 This example uses the SoftSerial library to view the XBee communication.  I am using a 
 Modern Device USB BUB board (http://moderndevice.com/connect) and viewing the output
 with the Arduino Serial Monitor.
 */

// Define SoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX = 8;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 9;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
SoftwareSerial nss(ssRX, ssTX);

XBee xbee = XBee();

// serial high
uint8_t shCmd[] = {
  'S','H'};
// serial low
uint8_t slCmd[] = {
  'S','L'};
// association status
uint8_t assocCmd[] = {
  'A','I'};

AtCommandRequest atRequest = AtCommandRequest(shCmd);

AtCommandResponse atResponse = AtCommandResponse();

void setup() { 
  xbee.begin(Serial);
  // start soft serial
  nss.begin(9600);

  // Startup delay to wait for XBee radio to initialize.
  // you may need to increase this value if you are not getting a response
  delay(5000);
}

void loop() {

  // get SH
  sendAtCommand();

  // set command to SL
  atRequest.setCommand(slCmd);  
  sendAtCommand();

  // set command to AI
  atRequest.setCommand(assocCmd);  
  sendAtCommand();

  // we're done.  Hit the Arduino reset button to start the sketch over
  while (1) {
  };
}

void sendAtCommand() {
  nss.println("Sending command to the XBee");
  //Serial.println("Sending command to the XBee");

  // send the command
  xbee.send(atRequest);

  // wait up to 5 seconds for the status response
  if (xbee.readPacket(5000)) {
    // got a response!

    // should be an AT command response
    if (xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE) {
      xbee.getResponse().getAtCommandResponse(atResponse);

      if (atResponse.isOk()) {
        nss.print("Command [");
        nss.print(atResponse.getCommand()[0]);
        nss.print(atResponse.getCommand()[1]);
        nss.println("] was successful!");

        if (atResponse.getValueLength() > 0) {
          nss.print("Command value length is ");
          nss.println(atResponse.getValueLength(), DEC);


          nss.print("Command value: ");


          for (int i = 0; i < atResponse.getValueLength(); i++) {
            nss.print(atResponse.getValue()[i], HEX);
            nss.print(" ");
          }

          nss.println("");
        }
      } 
      else {
        nss.print("Command return error code: ");
        nss.println(atResponse.getStatus(), HEX);
      }
    } 
    else {
      nss.print("Expected AT response but got ");
      nss.print(xbee.getResponse().getApiId(), HEX);
    }   
  } 
  else {
    // at command failed
    if (xbee.getResponse().isError()) {
      nss.print("Error reading packet.  Error code: ");  
      nss.println(xbee.getResponse().getErrorCode());
    } 
    else {
      nss.print("No response from radio");    
    }
  }
}

why should someone print out lines which are definately for the user at a softwareserial?

Again, ask yourself the question "What is the software serial connected to?"

well, they are at first digital pins i declared as software serials. and they are directly connected to my arduino microcontroller.
so, that would mean it cant be read elsewhere...!?
...but this doesnt make sense to me if i look at the sketch I sendt... :~

these pins write data on intern memory of the µController, right? So isn't it possible that they are recognized as serial message and then send to the usb, then serial monitor? you are starting to confuse me

// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX = 8;
// Connect Arduino pin 9 to RX of usb-serial device

If they're connected to a USB-serial device, then the other end of that USB-serial device can be opened as a COM port on the PC.

If they're connected to a USB-serial device, then the other end of that USB-serial device can be opened as a COM port on the PC.

OFC, true. BUT since i dont use that serial device, I cannot read such messages...
...OK, i just answered it myself, I think. The code is meant to be for users who have that serial to USb device pluged on the softwareserial. they can listen via putty or something else to that connection...

You can use a serial connection to talk to other things than your computer. A common use case would be to talk to eg a gps. I also use a software serial to receive data from a remotely located arduino through a long telephone cable. The data is then routed on to a computer through the hardware serial (Serial) -> usb interface, where it is logged.