ask AT command in serial port error

hello, i have connected Sony T230 to arduino

the code is below

#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9); // RX, TX pins
 
void setup() {
 Serial.begin(9600);
mySerial.begin(9600); // Open serial connection at baud rate of 9600
 }
 
void loop(){
 if (mySerial.available())
 Serial.write(mySerial.read());
  if (Serial.available())
 mySerial.println(Serial.read());
  }

and then i open serial monitor and type “AT” on keyboard and respon ERROR

but if i open hyperterminal and conncet to COM Arduino, it respon OK

send sms, and calling work fine in hyperterminal but don’t work in serial monitor arduino

any have idea?

The serial monitor has options to append newline and carriage return characters to each input line you enter - if you select the ‘no line ending’ option it should behave similarly to hyperterminal.

Also note that mySerial.println(Serial.read()); is going to append a newline after each character - I suspect that’s not what you want.

I was able to get it to work doing this:

void loop(){
  while (mySerial.available()) Serial.write(mySerial.read());
  while (Serial.available()) mySerial.write(Serial.read());
  delay(1000);
}

Just make sure you have the proper baud settings, and like Peter said, adjust the NL & CR parameters in the monitor. I had to set it to append NL and CR.

EDIT: The delay was in there for testing. Not sure it is necessary.

i have adjust both NL & CR and it's WORK

thank you very much

What is NL and CR parameters, and how do you set them to the right value? Also which baud rate did you use?

Thanks