Pages: 1 [2]   Go Down
Author Topic: Serial communication between arduino uno and arduino SD Logger  (Read 1987 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8621
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Check out itoa()

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Dublin, Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've looked through as much as I can find on itoa(), do you suggest I do something like:

Code:
          hours = mySerial.read();
          minutes = mySerial.read();
          seconds = mySerial.read();
itoa(hours,2,10);
itoa(minutes,2,10);
itoa(seconds,2,10);
If so what do I tell Serial to print?
Also without any of this I'm receiving output like so:

145:154:145,228,362,356
156:148:154,278,360,356
134:133:145,283,362,356
154:145:152,285,361,356
148:154:135,286,361,357
133:145:154,286,360,356
145:152:148,287,362,355

As far as I can tell, it looks like the 3 bytes are being jumbled up and printed in random order.
(This is with the uno giving the time, not me doing it manually anymore)
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8621
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

From an on-line C page

Quote
char *itoa(int value, char *string, int radix);
DESCRIPTION
The itoa() function constructs a string representation of an integer.
PARAMETERS
value
    Is the integer to be converted to string representation.
string
    Points to the buffer that is to hold resulting string. The resulting string may be as long as seventeen bytes.

radix
    Is the base of the number; must be in the range 2 - 36.

You have

Code:
itoa(hours,2,10);

So 2 is a pointer to a string?

Try

Code:
char strHours[10];
...
itoa(hours, strHours, 10);
...
Serial.print (strHours);


______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Dublin, Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I've tried that so the code now has strings for each
Code:
hours = mySerial.read();
          minutes = mySerial.read();
          seconds = mySerial.read();
          
          //convert to string
        itoa(hours, strHours, 10);
        itoa(minutes, strMinutes, 10);
        itoa(seconds, strSeconds, 10);
        
        //Print time back
        Serial.print(strHours);
        file.print(strHours);
        Serial.print(":");
        file.print(":");
        Serial.print(strMinutes);
        file.print(strMinutes);
        Serial.print(":");
        file.print(":");
        Serial.print(strSeconds);
        file.print(strSeconds);
        delay(200);

The output still looks like this though:
145:154:148,220,363,355
152:145:133,271,365,356
133:145:154,278,360,356
148:152:145,281,363,356
133:133:145,282,361,355
154:148:152,284,363,355

the values are the same as they were before and are still coming out in a random order.. :/
« Last Edit: July 04, 2012, 09:06:20 am by AndrewJM » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8621
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I admit that has me baffled, the numbers aren't random but I can't see a pattern either.

Firstly let's get rid of most of the code because it's just confusing the issue, and only send a single value.

Code:
hours = mySerial.read();
Serial.print(hours, DEC);
delay (200);

If that shows a bogus value then we have a problem with the data being received. If not it's atio() or the definition of strHours that's wrong.

How have you defined strHours?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Dublin, Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
char strHours[10];

I really appreciate the help but my time with the hardware is limited so I doubt I'll be able to finish the project. I hope to try again in about a month but, if not, thanks for the advice
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8621
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, sorry we couldn't get it to work this time.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: 1 [2]   Go Up
Jump to: