How do I see sensor's response through Serial Monitor 'mySerial'?

Hello,

I have a gas sensor (Sprint IR sensor) that measures the CO2 concentration in the atmosphere. I am using Arduino 101 as my MCU. As of now I am able to see the sensor's measurement, which is outputted onto the serial monitor. However, I believe the readings have been inaccurate lately; the sensor's manual states that I can review or even adjust the digital filter setting. According to the manual, the command to let the sensor return its current digital filter setting is "a\r\n" (\r\n stands for carriage return and line feed, respectively). My question is, where can I see the sensor's response, provided that my sensor is categorized in 'mySerial' instead of 'Serial'? Refer to the code below:

#include<SoftwareSerial.h>

SoftwareSerial mySerial(5,6); // TX, RX pins for serial communication
String val = ""; //holds the string of the value
double co2 = 0; //holds the actual value

double multiplier = 10; //each range of sensor has a different value.
  //up to 65% = 10
uint8_t buffer[25];
uint8_t ind = 0;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //Start Serial connection with host
  Serial.println("SprintIR Sample");
  mySerial.begin(9600); //start serial connection with Sensor
}
void loop() {

    while(buffer[ind-1] != 0x0A) //while buffer is not new line
    {
      if(mySerial.available()> 0)
      {
      buffer[ind] = mySerial.read();
      ind++;
      }
    }
  report(); //once we get the '0x0A' we will report what is in the buffer
}

void report()
{
  //cycle through the buffer and send out each byte including the final linefeed

  /*
   * each packet in the stream looks like "Z 00400 z 00360"
   * 'Z' lets us know it's a co2 reading. the first number is the filtered value
   * and the number after the 'z' is the raw value.
   * we are really only interested in the filtered value
   */

   for(int i=0; i < ind+1; i++)
   {
    if(buffer[i]=='z') //once we hit the 'z' we can stop
      break;

    if((buffer[i] != 0x5A)&&(buffer[i] != 0x20)) //ignore 'Z' and white space
    {
      val += buffer[i]-48; //because we break at 'z' the only bytes getting added are the numbers
                          //we subtract 48 to get to the actual numerical value
                          //example the character '9' has an ASCII value of 57. [57-48 = 9]
    }
   }

   co2 = (multiplier * val.toInt()); //now we multiply the value by a factor specific to the sensor.

   Serial.print("Co2 = ");
   Serial.print(co2);
   Serial.println(" ppm");
   ind=0; //reset the buffer index to overwrite the previous packet
   val = ""; //reset the value string

}

As you can see, the sensor is reading and parsing the buffer string from 'mySerial'. On my serial monitor, I'm only seeing the 'Serial.print' statements only.
Back to my question..how do I see the sensor's response when I give the command mySerial.println('a'); ?

You have to add something like this to the loop() to transfer the command string from the serial console to the device om mySerial:

if (Serial.available() > 0) {
   mySerial.write(Serial.read());
}

The carriage return and line feed are delivered automatically when the appropriate setting is chosen in the serial console.

6v6gt:
You have to add something like this to the loop() to transfer the command string from the serial console to the device om mySerial:

if (Serial.available() > 0) {

mySerial.write(Serial.read());
}




The carriage return and line feed are delivered automatically when the appropriate setting is chosen in the serial console.

Or, you could have the Arduino send the command directly.

mySerial.println("a");

and then read any response EXACTLY the same way you read from the sensor now.

Of course, you clearly don't have a mySerial connected to the Arduino, so mySerial is a dumb name. But that's a different issue.