How to split an incoming serial into int

Hello I recently started using Arduino and have run into a problem. I have an incoming serial in the form of 00,00,00,0000,0000,00000. Numbers change as time goes on but each number is always separated by a ",". I need to be able to do something like this.

void loop(){
String data = "22300,5230,934232,10050,20203,03428";
String value2 = getValue(data, ",", 2);
Serial.println(value2);
}

Were printing value2 returns 5230 or I can then say something like

if (value2 > 50){
do something;
}

Thanks for your help in advance.

Hi and welcome.

Is this some school project ?

First of all, you need more information.
Is the data a constant stream of data, or do you get a new line too ?
If you get a new line, are all lines of the same length ?
That means are there a fixed number of fields, delimited by a comma ?
Do you need to process all fields, or are you just interested in certain fields ?

These are some things you need to ask yourself.

Further, you need to know that you are receiving characters, ASCII values.
You need to convert these to some variables, which is the core of your question.
The comma's are a great help while doing this.

Serial.parseInt() may be what you need. Look in the Reference under serial.

MAS3:
Hi and welcome.

Is this some school project ?

First of all, you need more information.
Is the data a constant stream of data, or do you get a new line too ?
If you get a new line, are all lines of the same length ?
That means are there a fixed number of fields, delimited by a comma ?
Do you need to process all fields, or are you just interested in certain fields ?

These are some things you need to ask yourself.

Further, you need to know that you are receiving characters, ASCII values.
You need to convert these to some variables, which is the core of your question.
The comma's are a great help while doing this.

Yes it is a constant stream of data from one line but updates every second. I am interested in all of the fields and there are 11 fields total. This is partially a school project but mostly for enjoyment, I am trying to create my own neuro-controlled device using an old Mindflex headset and can currently run small rc helicopter motors based on meditation level. Which can always be determined by the fourth character. When the headset is sending data it sends it in 00(double digit connection level),00(double digit meditation level,00(double digit attention level), (rest of fields directly represent respective brain waves in unknown digit amounts). Currently if my arduino uno receives a serial such as 30,50,45,7373,8493,373,738,927,968,628,82655 it recognizes meditation at 50%.

This is great but I want to be able to utilize the actual brain waves, unfortunately I can't predict how many digits each value will have at a given time so I can't tell the adruino to look at the 23 digit (for example) like I can tell it to look at the fourth digit.

Thanks again for your help.

...And that's where those comma's come in.
Count the comma's.
But you'll need to find a way to synchronise first.
I bet you can do that using timing.

I'm not quite sure what you mean by synchronize but currently an if statement causes the uno to recheck the fourth digit every time the data updates, it's all in the void loop.

Cw160:
I'm not quite sure what you mean by synchronize

Let's say I wanted to tell you what the lottery numbers were for the last 50 years. Say its 5 numbers per lottery. I start talking, and you start writing:

120, 12, 76, 23, 64, 23, 195, 123, 634, 136

At this point, since you know it's 5 numbers per lottery, and you started listening before I started talking, so you know that the first 5 numbers go to the first lottery, and the next 5 go to the next lottery. You write it down as such:

Lottery #1: 120, 12, 76, 23, 64,
Lottery #2: 23, 195, 123, 634, 136

But what happens if you don't start listening until after I've spoken the first two numbers. What you hear, instead, is

76, 23, 64, 23, 195, 123, 634, 136, 1, 99

So you write it down as such

Lottery #1: 76, 23, 64, 23, 195,
Lottery #2: 123, 634, 136, 1, 99

That's what is meant by synchronization; you need a way for the receiver to know where in the data set the sender is when the receiver starts listening. How you do this will depend on the sender. Does it send a delimited character like a new line? Is there a temporal break in time between sets of data? Could the value tell you something about its placement in the set?

Ok I got you now. It does do something like, here is 11 numbers pause for a second and ok here is the next set of 11 numbers pause new 11 and so on.

It doesn't just constantly give numbers, it just sends a set of 11 every second.

Thanks

i think you can try to see if a certain amount of time has expired since the last character was received. if you are getting a burst of numbers, you should be able to set the timer to catch the whole group. If you have an expired timer, dump the message and start looking again.

unsigned long myTimer = 250UL;
//

//
void loop()
{
unsigned long elapsedTime = millis() - lastTime;
if (Serial.available() && elapsedTime < myTimer)
{
  char myChar = Serial.read();
  //process your character int your buffer
  lastTime = millis();
}
else
{
  //empty your buffer
}

make sure you have no delays that may affect this

I was involved in another project here that needed to check the interval between transmissions.

I think the simplest way is to record micros() when every character is received and if the gap exceeds some threshold you set a variable that says newMessage = true.

unsigned long prevCharMicros;
unsigned long curCharMicros;
unsigned long transmissionGapMicros = 800000; // 0.8 secs

if (Serial.available > 0) {
   curCharMicros = micros();
   if (curCharMicros - prevCharMicros > transmissionGapMicros) {
       // new transmission has started
   }
   prevCharMicros = curCharMicros;
   // read the character
}

...R

That is exactly what i meant.
I got that you were receiving these value once every second, and expected a pause between them.
You need to find specific `recognition points´, and a pause is one of them.
A pause can be measured / found using a timer.
I hinted to a possibility, because it is a school project, and you didn't exactly tell about the pause.

School project means you need to do some thinking yourself, and you will not be helped by simply serving you some code.
You'll really learn when you do stuff yourself including the unavoidable errors and mistakes you'll make.

MAS3:
That is exactly what i meant.
I got that you were receiving these value once every second, and expected a pause between them.
You need to find specific `recognition points´, and a pause is one of them.
A pause can be measured / found using a timer.
I hinted to a possibility, because it is a school project, and you didn't exactly tell about the pause.

School project means you need to do some thinking yourself, and you will not be helped by simply serving you some code.
You'll really learn when you do stuff yourself including the unavoidable errors and mistakes you'll make.

I appreciate your comments, however sometimes postulating isn't quite enough...

you make a good point, though.