Reading in Large Numbers from Serial

For the project I am currently working on I need to read in a group of large numbers and then store those numbers into an array. The numbers are separated by commas and the numbers range from 1-16777215.

An example string that would be coming across the Serial connection is: “255,1677215,55555,90000,1672166”.

Does anyone know the best way to do this using Serial.read() or if there is a better way to read in and store these numbers since they span anywhere from 1-3 bytes?

Thanks!

Store the characters in a buffer until you see a ',' then nul terminate the buffer and call strtoul() on it to convert it to an unsigned long. You can then take it from there.

Does anyone know the best way to do this using Serial.read()

One character at a time.

or if there is a better way to read in and store these numbers since they span anywhere from 1-3 bytes?

Presumably, you need these as numbers, not strings, so Serial.parseInt() is an alternative to Serial.read() and storing and parsing the data yourself.