trying to read serial output of device - get garbage withing the data

Hello ,
I have connected my arduino to a serial device
the connection are OK.
whe nI start the device I get the data - but when the data is "waiting" I get a square abd then the data continue
what is this ?how do I ignore this ?
Thanks ,

Press <delete> key within 2 seconds to enter setup����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������.�����������������������������������������������������������������������������������������������������������������.�����������������������������������������������������������������



loading kernel from nand...���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ��������������������������O���������������������������K������������

this is the code (this is jsut the start of the code - I jsut want to see i can read it right )

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8);
char full [600];
void setup()
{
  Serial.begin(2400);
  mySerial.begin(2400);
  Serial.println("Starting.....");
  for (int i = 0; i < 10; i++)
  {
    Serial.println("**");
    delay (100);
  }
  Serial.println( "Done!");
}



void loop()
{
  if (mySerial.available())
  {
    for (int num = 0; num < 599; num++)
    {
      full[num] = mySerial.read();
      if (full[num] == '\r')
      {
        Serial.println ("");
      }
     // Serial.print(num);
     // Serial.print("    ");
      Serial.print(full[num]);
    }//end of reading
  }

}//end of loop

The code you have posted did not produce the output you have shown.

What produced the output with the garbage characters?

If you want a simple reliable way for an Arduino to receive data have a look at Serial Input Basics

...R

I think you may have the wrong com port selected.

  if (mySerial.available())
  {
    for (int num = 0; num < 599; num++)
    {
      full[num] = mySerial.read();

So, if one character is available, you read 599? The read function will return -1 if there aren't any characters available. That's what you're printing. You could just do this:

  if (mySerial.available())
    Serial.print( mySerial.read() );

Cheers,
/dev

O.K
now it's working
I get jsut what I need

now I know that after 324 chars I can send the device a command (he has finish upload - I have counted it)
I have try this :

void loop()
{
  if (mySerial.available())
  {
   Serial.write(mySerial.read());
   total++;
  }
if (total >=324) //startup has finish
{
  mySerial.write("admin");
}
}//end of loop

but it doesn't work - now I get garbage after I enter the word "admin"

I will explain what I want to do
to be able to connect to the serial device using RS232-TTL and send him a simple command
to do that I need to enter the device user\pass after he hve finish uploading
I have serach here and didn't find something like I want to do

Thanks ,

I think I have found a solution ,
I don't need to read the answer - jsut send to the device
so I ignore the reading
and it's working

but it will be nice if i will be able to read the answer and do with it something

Thanks ,

Like Robin2 said, Serial Input Basics is a good place to start. You should write your code to watch for "answer", then start saving/parsing chars until the "end" of the answer, whatever that is. Depending on what you saved or parsed, you can print another command.

BTW, you should be using print, not write:

    Serial.print( F("admin") ); // use the F macro around that double-quoted admin

The write method is only for writing one character, like this:

    Serial.write( 'c' );

Cheers,
/dev

I understand what you are saying ,
but how can I "save" the output? I don't allways know how long the answer is going to be...so how can I save it if I don't know long it is ? to create a string of 100 and wait until I get EOL "/r" or something like this?

I will change the "write" to "print(F)" - but what is the different?

also I can see in the device itself what I'm sending to it - so it's good for what I need to do right now.

Thanks,

david1234:
but how can I "save" the output? I don't allways know how long the answer is going to be.

What is the maximum length that it could be? If that is (say) 200 bytes just set aside storage for that and allow the Serial Input Basics code to save the data there. When it detects the end marker it will set the variable newData to true so that you know a message has been received.

If the maximum length is too long to store in a char array then a different approach will be needed.

...R