Pages: 1 [2]   Go Down
Author Topic: Moving analog data over serial  (Read 1283 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26338
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void output64 ()
{
  if (valuecmd > 637)
Novel.
Can I recommend you revise your binary arithmetic?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The example I was using is from the web site.

http://arduino.cc/en/Tutorial/ReadASCIIString

Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 627
Posts: 34229
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep looks like crap code in that link.
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1726
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It isn't partuclarly crap. "parseInt()" sits there trying to read in values from the Serial port until it either times out (and returns 0), or another character arrives in and it sits there trying to read the next. That means that it doesn't need for Serial.available() to be any more than 1 when you first call it for it to work.

Granted the implementation could be improved, for example, if you send "12-34" it will detect it as -1234, and if it takes too long for the 2nd, 3rd, and so on characters to arrive after each other it will just give up and return.
Also that example doesn't account for the fact that you should wait until Serial.available()>0 in between each of the calls to parseInt().
« Last Edit: January 07, 2013, 05:24:24 pm by Tom Carpenter » Logged

~Tom~

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Exactly because either you are missunderstanding it or it is wrong.
Serial data takes a long time to arrive, just because one byte has arrived does not mean that all the bytes have arrived. FACT.

LOL, otherwise they wouldn't be allowed to call it serial data as it would be a violation of truth in advertising. Not unlike the fundamental difference between a serial killer and a mass killer, unless you are a victim where the difference is somewhat moot.

Lefty
« Last Edit: January 07, 2013, 08:38:40 pm by retrolefty » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found the binary math problem later. Doesn't help the speed any but did fix the logic.
Logged

Pages: 1 [2]   Go Up
Jump to: