Arduino Forum

Using Arduino => Programming Questions => Topic started by: 41south on Mar 28, 2011, 04:10 am

Title: String value to ASCii via serial interface
Post by: 41south on Mar 28, 2011, 04:10 am
Hi all,

I know this is going to be easy, but my searching hasn't found the answer. I need to convert a string such as
CSp2134Sp7128Sp0SpCR (where Sp = space and CR = carriage return) to ascii and send it out the serial monitor (and later a second serial port) which would in this case be 673250495152325549505632483213

Can someone please point me in the right direction.

Many thanks
Colin.
Title: Re: String value to ASCii via serial interface
Post by: maniacbug on Mar 28, 2011, 07:07 am
The idea here is to consider each character of the string, and send its decimal value to the Serial.  Something like...

Code: [Select]

char* current_char = my_string;
while( *current_char )
  Serial.print( *current_char++, DEC );
Title: Re: String value to ASCii via serial interface
Post by: 41south on Mar 30, 2011, 12:09 am
Fantastic, works a treat, many thanks.  :)
Title: Re: String value to ASCii via serial interface
Post by: maniacbug on Mar 30, 2011, 12:57 am

Fantastic, works a treat, many thanks.  :)


Great!  Happy to hear it.