Pages: [1]   Go Down
Author Topic: Sending large values from Arduino to computer  (Read 322 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 403
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How can I send large values < 32000 to a computer over serial?
is there any scripts to do this?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Many, this is discussed every two weeks or so on the forum

you split up the value in separate bytes and send these one by one. You recombine them on the other side.

Another option is to make a character array of it and send it over as text and reassemble the text on the other side and convert to integer again.

TO make it reliable you need start and stop characters/bytes to recognize the beginning of a variable.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A good reader to start - http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=11425&page=1 -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Sr. Member
****
Karma: 0
Posts: 403
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

could I send a number as a string? as in do a serial write with each digit so if the number was 10123 it would do code equivalent to this
serial.write(1);
serial.write(0);
serial.write(1);
serial.write(2);
serial.write(3);
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11179
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you can, but you don't need to format it yourself. Serial.print() will format a wide range of argument types into an ascii representation. If you use an ascii format, you'll need to define a scheme for detecting the boundaries between values and (if you have messages consisting of multiple values) between messages. For example you could use commas to separate values within a message, and a newline to separate messages. Or use any other scheme you like.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

could I send a number as a string? as in do a serial write with each digit so if the number was 10123 it would do code equivalent to this
serial.write(1);
serial.write(0);
serial.write(1);
serial.write(2);
serial.write(3);

That isn't a string. And in any case, how does the receiving end know whether you are sending 1, 10, 101, 1012, or 10123? You need some sort of terminator.
Logged

Pages: [1]   Go Up
Jump to: