Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Arduino serial data transfer issue

tapu

Full Member level 4
Joined
Sep 15, 2014
Messages
232
Helped
1
Reputation
2
Reaction score
1
Trophy points
18
Location
india
Activity points
1,749
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);
}
 

barry

Advanced Member level 5
Joined
Mar 31, 2005
Messages
4,985
Helped
1,090
Reputation
2,190
Reaction score
1,074
Trophy points
1,393
Location
California, USA
Activity points
27,283
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.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
18,715
Helped
4,174
Reputation
8,350
Reaction score
4,109
Trophy points
113
Activity points
123,131
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
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top