Emulating the serial monitor sending with Arduino code

I want to emulate sending ASCII text in the serial monitor window with Arduino code but I am having troubles doing so.

In the serial monitor, I can send "SI" and receive "test data".

I try to replicate this with Arduino but using the Serial.println("SI") and my receiving command is from the Serial Input Basic but I receive nothing back.

Is there something I am missing or doing wrong?

Thanks for helping!

Is there something I am missing

Code. You are missing code. At least your post is.

Right, here it is. Actually, this iteration of the code ends up just reading what I sent, which isn't helpful.

//#include <SoftwareSerial.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{

//Setting up the serial port to receive information
//Serial.begin(9600, SERIAL_8N1); 
Serial.begin(9600);

// initialize the LCD
lcd.begin();
lcd.clear();

delay(500);
lcd.println("Test");
delay(500);
}

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void loop()
{

Serial.println("SI");

recvWithEndMarker();

if (newData == true) {
lcd.println(receivedChars);
newData = false;
}

delay(500);

lcd.clear();
}


void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;

while (Serial.available() > 0 && newData == false) {
rc = Serial.read();

if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}

This website will help: www.xyproblem.info

Also, try reading the guidelines on posting code in this forum. Without code tags, the forum software eats some of your code and turns it into smileys.

Have you considered software serial to simulate? If you use a Mega, you can use one of the other ports instead of software serial.

Hook the tx of the extra serial to the rx of hardware serial (I think it's pin 0, not sure).

By the way, serial.print sends to the serial monitor and that is it. Serial monitor is a terminal that you can use to send and receive data, it is not intelligent in the sense that it echoes something.

Actually, this iteration of the code ends up just reading what I sent, which isn't helpful.

What did you expect it to do?

If you want to compare the data you read to "SI", and send "test data" if there is a match, you need to write code to do that.

MorganS - Thanks. I fixed the code.

sterretje - I did consider it but say it as unnecessary as I don't need to use my serial port for anything else. Right, but if the Arduino is hooked up directly to an RS-232 cable and I tell it to Serial.print, it should send the data through the cable, right?

PaulS - I expect it to send "SI" to the device, the device responds with a readout, and the Arduino displays that readout on an LCD. I don't understand why the Arduino would pick up its own outbound communication.

PaulS - I expect it to send "SI" to the device

What is "it" that you expect to send "SI"? To what device?

You appear to be trying to use Serial to talk to the PC (for debugging) and to this mysterious device. Hate to be the bearer of bad news, but that is not going to work.

No, I am not trying to do that. I am attempting to use the Arduino to send/receive from a scale. My computer has nothing to do with this other than to troubleshoot concerns. The ultimate use will not have my computer involved.