Processing to Arduino

goose123456:
Sorry for the confusion yes I want a numerical value

Fine! I got that!

but I want to use the values on the serial monitor

? You mean the values, not characters, received by Arduino reading, Serial.read?

so in this case if the serial monitor has {100,1,10} I want the variable oct=100, variable sca=1 and variable tran =10.

Okey. You will send the 3 entities of data 100, 1 , 10 from the Pc and You want to store them in the Arduino array like:
values[0] = 100;
values[1] = 1;
values[2] = 10;

Can You confirm I've got it?

So the serial will receive a byte array of {100,1,10} I want to read it and then store them as values[0]=100, values[1]=1 and values[2]=10. I want the array to store them as integers as I can later use them for calculations( if it is easier to do as chars then chars are fine).

Chars or byte, no big difference I think. I'll take a second look at the coding.
My question is if the Pc can send values and not only characters?

A next step question. How do You intend to synchronize the 3 byte train? Suppose on transmitted byte is lost?

Looking at Your code I get confused.
Do You want to store all those 3 bytes values received into the Arduino and then use them some way?

Yes exactly that so I've sent the byte array to the serial for example {100,1,10} and the serial is read to then store each of these into separate variables.

My next try...

int currentIndex = 0;

#define LED 11
char values[] = {0, 0, 0};
char Oct;
char Sca;
char Tran;
void setup()  {
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
}

void loop() {
  if (Serial.available())
  {
    byte incomingValue = Serial.read();
    values[currentIndex] = incomingValue;//Store the value received
// received valus is stored. Let's use the values array

    if (currentIndex == 0)
    {
      Oct = values[currentIndex];
      analogWrite(LED, Oct);
    }
    else if (currentIndex == 1) 
    {
      Sca = values[currentIndex];
    }
    else if (currentIndex == 2) 
    {
      Tran = values[currentIndex];
    }
    currentIndex++ % 3;//advance index, wrap around to stay within the array,
  }
}

What do You think?

So I tried it and changed the values of the Byte array to see if anything would change when I typed in {0,0,0} for example the LED should turn off but it hasn't

Can You do some more tests?

Install the Serial.println in the code:

void loop() {
  if (Serial.available())
  {
    byte incomingValue = Serial.read();
    values[currentIndex] = incomingValue;//Store the value received

[b]    Serial.println(incomingValue);[/b]
    
    // received valus is stored. Let's use the values array

I am unable to use the Serialprint() function as the serial is busy receiving data from a different IDE

A hidden secret, hidden obstacle. Solve it! Find a way for the Arduino to tell what it received. That's a very useful debugging tool saving me during 25 years as a professional thrown into large, unknown systems.

The problem is to get the information required I need to run the GUI from the processing IDE which sends data to the serial continually in this case I won't be able to use Serial.print() as the Serial constantly needs updating to process the values that it receives. Is it is possible to send and then stop sending storing the values and printing it because I thought once the Serial has been read the values are no longer there.

You use a high level language and one thing looks wrong to me. Maybe not important.... The Arduino IDE is not doing any processing. It is not even involved I think.

I got an idea!
Disconnet the computer data flow and use Serial Monitor, via USB. From the IDE You manually send typed examples to the Arduino! Then Serial.print will work! When reception and data handling in the Arduino is debugged and work, go back to the "normal" setup. What do You say?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.