Read Unsigned Long from Serial

Hello,

i´ve got a problem.... I want to read an unsigned long out from the serial. I can´t use functions like atoi() or Serial.parseInt(), because my Value isn´t an integer. Can anybody help me?

Thank you, bluefix

You could use atol() instead of atoi(). http://www.cplusplus.com/reference/cstdlib/atol/

strtol() is another option which is more robust, but has a larger footprint. http://www.cplusplus.com/reference/cstdlib/strtol/

Both functions return a long int, i think. I need an unsigned long. Can i change the code of that functions to get an unsigned long or do I have to find an other function?

Both functions return a long int, i think.

No need to think, when you can read: http://arduino.cc/en/Reference/StreamParseInt

parseInt() returns the first valid (long) integer number from the current position.

I need an unsigned long.

Are you really going to exceed 2,147,483,647? You can store the long in an unsigned long variable.

parseInt may look for a long, but according to its arduino page it returns an int as the op said.

For unsigned, you can use the unsigned version of strtol, called 'strtoul' http://www.cplusplus.com/reference/cstdlib/strtoul/

Example usage:

  unsigned long ul = strtoul(inputString,NULL,base);

Value isn´t an integer.

If it isn't an integer, why are you trying to store it in an integer datatype?

parseInt may look for a long, but according to its arduino page it returns an int as the op said.

No, it doesn't:

  long parseInt(); // returns the first valid (long) integer value from the current position.

In which case:

Returns

int

(From here: http://arduino.cc/en/Reference/StreamParseInt) Needs correcting.

From the linked reference page:

Description

parseInt() returns the first valid (long) integer number from the current position.