Go Down

Topic: Serial Communication Issue  (Read 386 times) previous topic - next topic

dipen010

i am using arduino uno for serial communication pass through software serial port, But when i pass simple "A" from the termial i am getting 95 on arduino terminal. When i pass "B" on software serial port i am getting 47 on arduino terminal

All i am doing is Serial.print(mySerial.read());

pert

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's ok to add it as an attachment. Don't put your code in some external file service like dropbox, etc. We shouldn't need to go to an external website just to help you. I do feel it's reasonable to post a link to code hosted on GitHub or similar code hosting sites since that's an platform specifically designed for this sort of thing

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor then you will not  have access to this useful tool. I recommend using the standard Arduino IDE instead.

When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

dipen010

my application is to pass through ASCII String from One Software Serial port of arduino to Actual Serial Port of Arduino,

using Serial.print(mySerial.read()), While i enter "A" i am getting "95" to other side while i send "B" i am getting "47". when i send the combination of character the output is not consistant. but when i send on actual serial port of arduino and print on the same port iam getting the same character.

How it is so ?

Can anyone help me out ? 

Thank You

 

pert

DON'T CROSS POST!!!!!!!!!!!!!!!!!!!!
http://forum.arduino.cc/index.php?topic=550138
I HAVE REPORTED THIS THREAD TO THE MODERATORS

Coding Badly


dipen010

/*
  Software serial multple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

 Not all pins on the Leonardo and Micro support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
 
  // set the data rate for the SoftwareSerial port
 Serial1.begin(9600);

}

void loop()
{ // run over and over

  if (Serial1.available())
    {
      Serial.print(Serial1.read());
    }


if (Serial.available())
{
  Serial1.print(Serial.read());
}
}

sterretje

#6
May 29, 2018, 08:21 am Last Edit: May 29, 2018, 08:22 am by sterretje
Use Serial.write instead of Serial.print.

Serial.print considers the characters to be numbers and hence you see numbers.

I can explain the numbers that you get, I would expect other numbers 65 and 66. Maybe wrong baudrate. As pert indicated, post you full code and explain what is connected to mySerial.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

dipen010

One thermostat is going to connected on software serial port, But for now i am sendind command from my pc termial using serial to usb cable.

I am also expecting 65 and 66 and so on, Believe me i have set baudrate to 9600 wherever needed. there is no mistake in baudrate setting.

My concern is that why i am getting 95 instread of 65.

sterretje

Where do you create an instance of Serial1. You're using an Uno which does not even have a Serial1 and hence your code (reply #5) does not compile.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up