Go Down

Topic: Sending large values from Arduino to computer (Read 405 times) previous topic - next topic

arduinoPi

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

robtillaart

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.
Rob Tillaart

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

robtillaart

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

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

arduinoPi

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);

PeterH

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.
I only provide help via the forum - please do not contact me for private consultancy.

Nick Gammon


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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up