Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino serial data transfer issue

Status
Not open for further replies.

tapu

Full Member level 4
Joined
Sep 15, 2014
Messages
234
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
india
Activity points
3,041
Dear All,
I want to send bytes from 0 to 99 from one arduino uno to another arduino nano serially.But when i send 1 then receiver shows 49 on serial monitor,when i send 2 then they shows 50 on reciever .how to manage the code for successfull transmition & reception.i have given both code below.please reply
Code:
//Transmitter code
int senddata = 3;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.print((int)senddata);
delay(1000);
}
Code:
//Reciever code
int incomingByte=0;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
if (Serial.available())
   incomingByte=Serial.read();
   Serial.print(incomingByte);
   delay(1000);
}
 

How are you encoding your data? ASCII? Straight binary?

Get an oscilloscope and look at the output data and compare that to the data in the received data. Verify that your baud rates match.
 

Hi,

"1" is a character ASCII coded, it has the decimal value of 49, this is the same as a hex value of 0x31 or a binary value of 0b00110001.
All is a byte containing 8 bits.

The problem is that you send a ASCII coded character but your terminal represents it at decimal value.

No you have to devide whether you want to send your values
* as plain (uncoded) byte with range of 0...255, or (then set your terminal to show decimal values)
* as ASCII string, (with 1 byte for values 0...9 and as 2 byte string for values 10..99, one decimal is one character), then set your terminal to show ASCII characters.
You may also transmit always 2 bytes either "00" to "09" or " 0" to " 9"

Klaus
--- Updated ---

And please read Arduino documentation of "Serial.print" command.
Mind the "human readable ASCII" statement.

Klaus
 

    tapu

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top