Hey guys, I am making a project for school as a thesis. The idea is to use the TouchOsc App op my ipod to control the speed and direction of the two dc motors with the arduino Mega.Basically processing receives the data from touchosc app and sends for example port.write('1'). In my arduino code i have made a switchcase whereby i do a serial.read and uses this decide where button was pushed(like move forward/backwards). Which is working smoothly. My main problem is i have to send in addition to the port.write('1') also my pwmMotorA with is an integer from one the sliders on my touchOsc app.Is there a way to send them both in like port.write( '1',pwmMotorA)? when i do that arduino just sees it as an ASCII code..I have searched almost whole google for this..with no results. I have included my arduino and processing sketch.

by sending my variables one by one.To slow reaction on the arduino.The first line port.write('1') is actually a variabele i use to detect in arduino in which mode the motor is in(like forward/back/stop). Am considering is using seperators like i read somewhere. ie a

The port.write() function sends 1 byte to the serial port. IF one were to create an overloaded method that took multiple bytes as input, the overload would end up calling the existing method in a loop to send all the bytes.

The "delay" with that function is NOT with having to call it multiple times.

It's time to dispense with the academic questions, and post all of your Processing and Arduino code. There may be things that you are doing (unknowingly) that limit the speed that the data is transferred at. We can't tell that without seeing all of the code.

if (Serial.available() > 0) { // Check if there is a new message dirA= Serial.read(); // Put the serial input into the message dirB= Serial.read(); // Put the serial input into the message pwmMotorA = Serial.read(); pwmMotorB = Serial.read(); } Suppose Serial.available() returns 2, as in there are 2 bytes in the serial input buffer. What is going to happen when you try to read the 3rd and 4th values?

Yep. That's the key. Don't try to read data that isn't there. Doing so will get you all out of sync.

The next step is to change the 4 values being sent to 6 values - including a start of packet marker and an end of packet marker. With these, you can tell if a packet is complete. A start of packet marker followed by 4 value that are not end of packet markers followed by an end of packet marker defines a good packet. Anything else, and that data just gets dumped.

// read the serial portint GetFromSerial(){ while (Serial.available()<=0) { } return Serial.read();}the proble for me is the LCD did not display in proper ...if i remove the GetFromSerial for lcd.print("R :"+ GetFromSerial()); not do not have any problem, can i know any solution??i need my LCD to display the RED,GREEN,BLUE value from processingthank you

lcd.print("R :"+ GetFromSerial());Suppose that GetFromSerial() returns the value 12. What, exactly, do you expect adding 12 to "R :" to result in? + is NOT a concatenation operator. It is an addition operator.

No .i put + is just to let lcd continue print the variable (RED) i want my LCD to display the data from the Processing ..'which is RED,GREEN ,and BLUE...i have no idea how LCD and display 3 in same time?

port.write('R'); port.write(RED);

port.write('G'); port.write(GREEN);

port.write('B'); port.write(BLUE);

the RED is an interger value

if work perfect in case 'R': analogWrite(9, GetFromSerial());//arduino pin 9 for LED break;the intensity of the light will change according to the RED valuebut i do not know why it can not work in lcd to display out the RED valuei till keep give me the random char

but i do not know why it can not work in lcd to display out the RED value

It can. You MUST use TWO statements to print the "R :" part and the value. You can NOT use the addition operator HOPING that somehow it will magically be interpreted as a concatenation operator, just because that is what you want.

but i do not know why it can not work in lcd to display out the RED value

It can. You MUST use TWO statements to print the "R :" part and the value. You can NOT use the addition operator HOPING that somehow it will magically be interpreted as a concatenation operator, just because that is what you want.