Confusing Processing / Arduino serial behaviour

I'm new to Arduino and Processing but I have been steadily working through the tutorials and have found it relatively successful until now!!

I copy and pasted the code to this tutorial for controlling LED RGB values through sliders in Processing:

http://anthonymattox.com/serial-communication-sending-variables-to-the-arduino

into Processing and Arduino. Uploaded to my Mega2560 and then ran the processing script. Nothing!

So after a couple of hours of fiddling I clicked on the serial monitor in the arduino software - it randomly kicks into life. Try unplugging everything then repeating - NOTHING AGAIN!! After a bit more testing it turns out that my serial communication for this code doesn't seem to work unless I jump start it through the serial monitor in Arduino. If I send an R G or B then a value to my board - the LED will light. Then if I go back to Processing and run the sketch it works flawlessly.

If I don't start up Arduino and just Processing - nothing happens.

My question is this:

It seems like a conflict between Arduino and Processing using the serial port. Am I missing something - is there something I should be doing to avoid this. Should I start the software in a particular order to avoid conflicts? Or should this not be happening?

Any suggestions would be greatly appreciated to avoid hours of hair pulling.

sorry first post so no active links allowed

Once you made the first post, the modify button became active. Try it out.

Processing and the Serial Monitor can not use the serial port at the same time. Processing should be able to initiate communications to the serial port.

What operating system are you using?

Thanks. I've updated the link above.

I'm on OS X Snow Leopard. I thought it would be a conflict so I did a search and found that the serial monitor in Arduino can't be used at the same time. But having read this no amount of unplugging/plugging and software restarts in different orders seems to help.

Like I say the only consistent way of getting this working is to send something to the Arduino from the serial monitor to light the light and then start the Processing sketch.

No Arduino at work with me today, and I don't use a Mac OS or own a Mega, so I'm not going to be much help, I'm afraid.

Tonight, when I get home, I'll install Arduino and Processing on my son's Mac, and try talking to a Duemilanove.

Okay thanks very much for offering to take a look.

I just wandered if there was anything obvious it could be. I can't find anything about the basics of this other than the necessary code.

Is there anything else that could stop the communication on my mac? Like I say all I have to do is send a couple of commands to the Arduino in the serial monitor and then it works. Up till that point - nothing!!

I've had other things working in with serial communications - it just seems to be this example so far.

I installed Processing 1.2.1 and Arduino 22 on a Mac running 10.6.6. I copied the Arduino code and Processing code to the respective applications, and added extra Serial.print() statements to the Arduino sketch, and port.readString() to the Processing sketch. Uploaded and ran. Moving the sliders sent data to the Arduino (Duemilanove) and resulted in data streaming back. I never opened the Serial Monitor.

Thanks for looking into this. I think I'm a bit confused by the whole serial monitor thing!!

Can you explain what the two additional commands you added do? Are you able to get the Arduino Software to print results without the Serial monitor? And then also Processing? Being able to see how the two communicate would be very useful.

Do you get the lights to light up straight away or did you just look at the data between them?

I've been playing about some more tonight and I have been trying the single LED dimmer example:

Again the lights don't light up. If I try sending data with the Serial monitor and ignore the processing part - the LED lights but no matter what value I send via serial monitor the Light remains at the same brightness.

Am I missing something completely here? I am completely new to the Arduino side of things - but all the coding seems to make sense - its just the serial doesn't seem to be behaving as it should.

Thanks for all your help - much appreciated.

I didn't actually hook up any LEDs - too lazy to figure out where my proto shields are and find the LEDs and resistors.

What I did do was add Serial.print() statements in the Arduino code, to echo the data that was received. Every character that was received was printed out.

Then, I added code to the Processing application that would read the data that the Arduino wrote to the serial port, and print it to the console window.

As soon as I started the Processing application, it started printing stuff in the console window, so I could see that Processing and the Arduino were talking to each other.

I didn't pay a lot of attention to whether the data was any good.

The Dimmer example expects that the brightness level will be sent as binary data. The Serial Monitor can not send binary data. It can only send ASCII data, so it's hard to figure out what characters to use. A # and a z should produce noticeable differences in brightness, assuming that you have the LED connected to a PWM pin.