My first Project -Please help!

Sorry for my noob questions.

Iam reading the serial data, each second the PC send:


These are 8 Frequencies A-H (0 to 99999 is max.)

I want to set this string to the 8 variables A-H.

How can I do that?

int REC =0;

void setup() {  
  Serial.begin(9600);  //int serial port


void loop() {

  REC =;  //receife data




Declare a char array large enough to capture all the incoming data -> char array[nn] Read and store each character in the array until you read the end of line marker (CR == ASCII 013) Use a CSV (comma separated variable) parser to extract each value and assign to your variables.

Alternately, you could process each byte as received, look for commas (ASCII 044) and build your value until the next comma. Unless your serial connection is running at a crazy high speed, you'll have lots of time between each incoming character for processing.

This is not a complete solution and is not very robust but it may start you on the right road

long frequencies[10];

void setup()

void loop()
  if (Serial.available())
    for (int index = 0; index < 8; index++)
      frequencies[index] = Serial.parseInt();

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

Change the value of numChars to be a bit larger than the maximum size of a message.


There are three basic parts reading data via serial port - detecting data presence in Serial buffer, reading data from Serial buffer and saving it in program buffer, analyzing data when ALL received.

Serial (class) provides handy functions to accomplish such basic data collections.

In PSEUDO code Setup { . optionally set the Serial.readBytesUntil timeout - once in Setup make sure it is long enough to receive the data

int DataTimeout = 1000 default to 1000 uS Serial.setTimout(DataTimeout) set Data Timeout once in Setup


loop() .

time = current time in microseconds / milliseconds since program stated

is data present in Serial buffer ?

while(Serial.available()) while Serial buffer "loop" { yes, have data

startTime = current time in microseconds / milliseconds since program stated - "starts" Serial.readBytesUntil timer

read data from Serial buffer into Mybuffer terminating at character(s) or when optional number (length)of characters /bytes is received or Serial.readBytesUntil times out

NOTE need to verify if character can be ',' | CR

while(characterCount = Serial.readBytesUntil(character, Mybuffer*, length)* { read data and return count of data read from Serial buffer "loop" verify that data was read before timeout if( current time in microseconds - startTime > DataTimeout) (character, buffer, length) { process timeout error here , perhaps discard data received so far etc.. if data speed is known this could be used to adjust the readBytesUntil timeout } optionally verify number of characters received if constant and known needs work to monitor CR as single end character since "until" character is NOT written to MyBuffer if(characterCount != number of characters / bytes expected ) { process incorrect number of characters received } advance Mybuffer index to next member of array *} continue until end character ( CR) is retrieved * now check if data in MyBufffer - using MyBuffer index if(Mybuffer) { got data process data from Mybufffer.... reset Mybuffer back to zero } no data continue loop() . . } Last word - this is pseudo code , not to be "cut and paste".Just to give you an idea. Just read Resources Serial. Especially Serial.readBytesUntil and let the computer do the work.