[SoftSerial] [SOLVED] Strange char when receiving ASCII

Hoi friends,

when i receive a plain ASCII Character like the A then i got always µA

I using the demo code:

  }
  delay(2000);
  Serial.println("5 s Input Chance !");
  delay(2000);
  lcd.setCursor(0,2);
  lcd.print(" 5 Sek. Inputchance ");

  // make a string for assembling the data to log:
  String dataString = "";
  // Read device output if available.  
  while(softSerial.available()) { // While there is more to be read, keep reading.
    command += (char)softSerial.read();
    command += (char)Serial.read();
  }       
  //       // Read user input if available. This bit is for debugging, if you write anything into the Arduino Serial Monitor 
  //       if (Serial.available()){          //  and press Return it will be sent over the Bluetooth link.
  //         softSerial.write(Serial.read());  // send whatever was written over the bluetooth link 
  //    }            

  if (command == "OK"){
    Serial.println("Read OK");
  }

  if(command == ("A")){  
    softSerial.println("Panel1");  // sending  'screen1' will cause BTInterface to show screen1
    Serial.println("btinterface Rodger");
    delay(1000); // wait a second to give it a chance to get all the characters.
    softSerial.println("screen1title Trixi"); // will cause BTInterface to alter the title of screen1 
  }
  if(command == "a"){         
    softSerial.println("pong"); 
    Serial.println("pong"); 
  }


  if(command != ""){              // so if there is something in the string 'command' If command doesn't equal "" (if its not empty!) then print it to the
    Serial.println(command);  // Arduino's Serial Monitor and what's in 'command' is what has been received over the Bluetooth link.
  }                 

  delay(5000); 
  command = "";

So, when i send A the terminal window shows µA, when i send RUN it shows µRµUµN

Has anyone an idea what is wrong ?

Has anyone an idea what is wrong ?

Yes. You haven't said anything about what is sending data to the SoftwareSerial pins. I'm pretty sure that it isn't a mySerial connected to the pins. Why doesn't the name of the instance reflect what is actually attached?

Hoi PaulS,

no icon here for that what i want to express ]:D Pasted a wrong code in the code window - nothing more to say :zipper_mouth_face: about :cold_sweat:

Just modified the code-entry 8)

  while(softSerial.available()) { // While there is more to be read, keep reading.
    command += (char)softSerial.read();
    command += (char)Serial.read();
  }

You make sure that softSerial has something available, read it, concatenate it to command and then read Serial without checking if anything is available and concatenate it to command. Is that what you meant to do ?

Yes, all what comes in should be output'ted (Keyboard, Serial, LCD, WhatEver...)

The mu symbol is ascii 230
ETB is 23 (end of transmission block)
0 is null

Just a guess but it’s probably

UKHeliBob get it right. you check for softSerial.available(), so softSerial.read() will always return a valid number, but you don't check for Serial.avaiable(), to Serial.read() can return -1 if no char is available... and that is your garbage!

kiss

Didn't make that clear enough i think (english is not my native language)

The trasmission works, but only the "µ" or "y" sign is the problem. This will be send before EVERY sign, so when i write test it appears as i.e. ytyeysyt on the receiver side

The trasmission works, but only the "µ" or "y" sign is the problem.

The y with the double dots is what you see when you print a -a as an ASCII character. And, a -1 is what you get when you read from the serial port when nothing is available, as you appear to be doing.

And what can i do to suppress this awesome y - send it not as a ASCII char ?

And what can i do to suppress this awesome y - send it not as a ASCII char ?

Don't read from the serial port if there is nothing to read.

Why are you combining the data from the hardware serial port and the software serial port into one String instance? Most people like to keep them straight.

OK, thx for that hint :)

I tried it and here is the (working) result:

  while(softSerial.available()) { // While there is more to be read, keep reading.
    command += (char)softSerial.read();
//    command += (char)Serial.read();
  }       
  while(Serial.available()) { // While there is more to be read, keep reading.
//    command += (char)softSerial.read();
    command += (char)Serial.read();
  }

The reason why i am using both ports the same time is that i want to read from the keyboard AND the other port(s).

Thx a lot guys - your Karma will be brighter from now on :D

The reason why i am using both ports the same time is that i want to read from the keyboard AND the other port(s).

And mix the data together in whatever order it was received? Well, OK, whatever floats your boat.

And mix the data together in whatever order it was received? Well, OK, whatever floats your boat.

my only interest is that it works - so it does, so all is good, so - still in my dry boat :P