Double characters in array?

I’m stumped as to what is going on here.

I’m not a “seasoned” user of C++, but it hasn’t been hard to adapt, but I am learning new things everyday. I’ve been able to troubleshoot all but this last issue out of this code.

Basically, I am starting the LCD, and Serial, inputting a string (i.e. “ABCD” via the serial monitor. it is writing each byte (unless a carriage return is detected) to the LCD, and placing the character in an array, and on detecting a CR, it writes the array back to the serial monitor. It works just fine except it doubles the character string. If I input ABCD it sends back ABCDABCD. If I put in a single character it sends it back doubled (i.e. input A, sends back AA).

I’m open to any and all constructive criticism here, but I can be considered a “noob” at C++ so don’t get too overly complex, or abstract.

code

//#include <VM_Boards.h>

#include <Arduino.h>
#include <LiquidCrystal.h>

// LiquidCrystal lcd(7,8,9,10,11,12);
LiquidCrystal lcd(43,45,47,49,51,53);
char array[64];
int i = ‘\0’;
byte inByte;
byte mnib;

void setup(){

lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.write(“Begin”); // Just let me know the lcd write is working
Serial.begin(9600);
}

void loop()
{
// when characters arrive over the serial port…
while (Serial.available() >0) {

inByte = Serial.read(); // read serial input
Serial.write(inByte);
if (inByte != 13){ // make sure it’s not CR
lcd.write(inByte);
array = inByte; // put the byte in the array

  • i++; // increment the array pointer*
    _ array = ‘\0’; // terminate the array with a 0_

* }*

* if (inByte == 13) {*
* String str(array); // make the array a string*
* Serial.println(array); // send to the serial monitior the contents of the array *
* inByte = ‘\0’; // if inByte is CR we will endlessly loop*
* i = ‘\0’; // initialize i again*
* }*
* }*
}
code/

Check out your code, do you see it turns into italics at the end. The forum mangles code. There is a way to stop it doing that read the how to use this forum sticky post.

What are you using as a terminal? It looks like that is set to echo.
Try removing that

Serial.write(inByte);

line

Thank you, Mike. Now I really do feel like an idiot. :smiley:
That was certainly it.

So far as posting, I did read the sticky prior to posting. Can you be more specific as to what I have done incorrectly in my post that causes the italics?

This was my first post. After reading some of the posts, both in this and other forums, I was determined not to post in these forums until I developed at least a basic knowledge of C++ (I previously did assembly programming in x86, TI7000, and a few more, as well as some C, but not C++), and some understanding of the processor architecture. I have no desire to waste your time, although it appears I must have. I should have caught that "Serial.write(inByte)" line last night. I put it in there as a debugging statement.

I have no desire to waste your time, although it appears I must have.

No problem. Wood and tree sighting confusion affects us all.

Can you be more specific as to what I have done incorrectly in my post that causes the italics?

Code should be posted between code tags, they are the # icon at the top of the reply box. Without this some things get interpreted by the forum software as smiles, and text formatting commands.