how to get multiple floats from a string ?

how to get multiple floats from a string ?

i am sending multiple floats in a string between 2 x arduino via xbee's (Garage) to (House)
using this
garage temps,23.98,34.97,14.75,24.64,22.55,
all sent in ascii format.
i need to convert this info back into float values

Looks like you need strtok and atof.

Have a look at the parse example in Serial Input Basics

...R

PaulC:
all sent in ascii format.

Why ASCII? Why not put them in a struct and send as binary? No parsing required and you eliminate float --> ASCII conversion on TX side and ASCII --> float conversion on RX side.

EDIT: You would also probably end up sending few bytes and there'd be no loss of precision.

Because ascii is more portable and easier to troubleshoot.

Also, it gives you latitude for “out of band” control characters.

Also, it makes it much easier to insert termination characters to make sure you have a full set of data. If you send structs how do you know you are out of sync?

Control instructions can also be members of the struct.

KeithRB:
If you send structs how do you know you are out of sync?

if (numberOfBytesReceived == sizeof(myStruct)) {

}

gfvalvo:

if (numberOfBytesReceived == sizeof(myStruct)) {

}

Since libraries like RadioHead take care of packet-izing for you.

KeithRB:
Because ascii is more portable and easier to troubleshoot.

Also, it gives you latitude for “out of band” control characters.

Also, it makes it much easier to insert termination characters to make sure you have a full set of data. If you send structs how do you know you are out of sync?

+1

Sending data in human readable form makes debugging very much easier. I would only use binary data when it is the only way to get enough performance.

It is possible to have start- and end-markers with binary data but it requires extra work on the sending and receiving end.

…R

Robin2:
Sending data in human readable form makes debugging very much easier.

I would suppose so.

Probably most of the difficulty comes from the numbers being in floating-point form. It's much easier if you don't have to deal with a decimal-point character. If you want two decimal places, just multiply by 100 and convert to int. If int isn't big enough, use long instead. Then transmit the ints (or longs) as ordinary base-ten ASCII literals. On the other end, convert to float and divide by 100 to restore the original values.

gfvalvo:
Control instructions can also be members of the struct.

if (numberOfBytesReceived == sizeof(myStruct)) {

}

You could receive the correct number of bytes and still be out of sync.

Meh.

Sending packet-ized structs has worked pretty much flawlessly for me. The RadioHead Library does a lot of the heavy lifting. It takes a pointer to your data and a byte count. It then takes care of formatting packets with CRC, with encoding (if you like), sending them out, and then waiting for an acknowledgement (if you like). At the RX end, you just confirm the correct received byte count and then do a memcpy into your structure. Bam, your data is there in the exact format as on the transmit end.

You can define your payload struct to include as much extra redundancy and checking as you like. Put in a packet sequence number to determine if any packets have been dropped. Add an extra payload-only CRC to check for transmission errors. That’s way more assurance than you get blasting out ASCII strings. And, IMO, a much more elegant, solution.

gfvalvo:
Sending packet-ized structs has worked pretty much flawlessly for me. The RadioHead Library does a lot of the heavy lifting.

If you are not using a library like that you will need to do the heavy lifting - which is what the other comments here are about.

...R