Go Down

Topic: Serial communication between arduino uno and arduino SD Logger (Read 2168 times) previous topic - next topic

Graynomad

Rob Gray aka the GRAYnomad www.robgray.com

AndrewJM

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

Code: [Select]

          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)

Graynomad

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: [Select]
itoa(hours,2,10);

So 2 is a pointer to a string?

Try

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



______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

AndrewJM

#18
Jul 04, 2012, 04:03 pm Last Edit: Jul 04, 2012, 04:06 pm by AndrewJM Reason: 1
Ok, I've tried that so the code now has strings for each
Code: [Select]

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.. :/

Graynomad

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: [Select]
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
Rob Gray aka the GRAYnomad www.robgray.com

AndrewJM

Code: [Select]
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

Graynomad

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

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up