Processing.serial <-> Arduino Mega 2560 - fails

So I am doing various minor test to do serial processing between my WinXP and the Arduino. I have two, a small (older) ATmega328 and a new Mega2560.

The programs work fine if I use the Serial monitor with the Arduino IDE.
The programs work fine with my own serial connection using Delphi(Pascal)
The programs work fine with the (6 month old) Arduino Duemilanove ATMega328 and the Processing (latest) with the Serial calls
The programs do NOT work with the ATMega (that uses the ATMega8U2 chip) the Processing (latest) with the Serial calls

Yes, I have checked the correct COM port, the right Arduino board and serial baud rate. Umpteen times. It is only that specific combination The Mega/8U2 and Processing Serial lib.

Symptoms ? Thing goes haywire; the RX lights up nearly always, the LED13 lights up. Irrespectve of what program is or is not loaded in the Arduino (like the starter Blink code). I suspect something makes the Arduino go into its bootloader - some setting of the DTR/CTS/or-more-subtle item. Apart from that it will not talk to Processing.Serial the board works fine otherwise.

Bug in Serial? Unusal H/W failure on my board? Wrong phase of the moon ?

Which version of Processing? How are you selecting the COM port in the Processing application?

The latest 1.2.1. Same as all other examples; print serial.list, invoke new Serial ... and it is the right port ([1]->Com4 ). Tried the wrong one just for fun. And remember, it works when I use the other Arduino (and although the COM port# changes, it is the same serial-slot.)

hey all, just got my audrino last week as a learning tool for myself, anyway processing is giving me similiar hassle,
for example,
PhysicalPixel example will not run through processing, that is moving my mouse over the box fails to turn on the LED on pin 13,
however using the serial monitor and passing a the byte to turn off or on the led does the job,

Im using a MEGA 2560 and Windows7 starter on a netbook,

Aha - old case re-awoken.

Works fine on my Duemilanove ATMega328 and it does not work on the Mega 2560. (Yes, I have compiled for the right board, choosen the right port)

I have reduced down all the testing to a very simple Turn the LED On/Off, Show state of Switch in nice Processing/Arduino pair. They are easily modified (one line/comment change ONLY) for doing input (Arduino->Processing), output (Processing->Arduino) or both.

It shows the problem is - apparently - that Processing can not send to the Arduino. I hazard a guess that the CTS equivalent is not raised at the Arduino end, but why should only the Processing Serial be sensitive to that (it works with other software, like Serial Monitor)? I also note that tvisdead says it works on his UNO which also uses the new ATMega8U2 chip for USB … ?


/* Test program for Processing - Arduino Communication 

Hardware: USB connection to the Arduino, appropiatly eqipped (See Arduino program source)

You probably need to edit the "Port = new Serial..." line with your number

Edit the final test to choose one or both test 

final String test = "Both" ; // Set to one of: Input, Output, Both

import processing.serial.*;    // Get the Serial library

// The screen has two halves:
//  The left half is sensitive to the mousecursor:
//    it will send a "LED on" command to the Arduino if cursor is on it
//    The colour of the half left changes to confirm command is sent
//  The  right half does not care about the mouse cursor.
//    It's colour reflects the last switch sense recieved from the Arduino

Serial port; // "port" is now a Serial capable variable

void setup()  {
  size(200, 200);    // Size of interaction screen
  frameRate(4) ;     // Quarter Seconds updates/draw cycles
  println(Serial.list()); // Prints a list of serial ports (verify correct COM number is used)
 // Open the port that the Arduino board is connected to (in my case "1") 
 // Make sure to open the port at the same speed Arduino is using (9600bps) 
  port = new Serial(this, Serial.list()[1], 9600); 

 delay(2000) ;
void draw() { 
  int inChar;
  if ( test.equals("Input") || test.equals("Both") ) {
   // Colour the right half, depending on last received status
     while ( port.available() > 0) {
       inChar =;         // read it and store it in val
       println(inChar) ;             // optional debugging
       if (inChar == 'd') {          // If the serial byte received is a "d"
         fill(50);                   // set fill to dark Gray
         rect( width/2, 0, width/2, height);
       if (inChar == 'u') {          // If the serial byte received is a "u"
         fill(200);                  // set fill to light Gray
         rect( width/2, 0, width/2, height);
     // Which implies that any other characters are simply ignored/discarded
  // Test if the cursor is over the box 
  if ( test.equals("Output") || test.equals("Both") ) {
    if (mouseX > 1 && mouseX < (width/2 - 1) && 
        mouseY > 1 && mouseY < (height  - 1) ) {
      port.write('H');              // send an 'H' (LED on)
      fill(230);                    // set fill to very light Gray
      rect( 0, 0, width/2, height);
      else { // mouse is elsewhere
      port.write('L');              // send an 'L' (LED off)
      fill(20);                     // set fill to very dark Gray
      rect( 0, 0, width/2, height);
 // frameRate=4 implies a 250 ms delay before looping


/* Test program for Processing - Arduino Communication 

Hardware: USB connection to the computer
   For the Input test a switch that shorts pin 12 to ground (unless you redefine Input)
   For output the onboard LED is used (unless you redefine Output in which case you need a LED/resistor)

Comment the "#define" if you want input, output or both tests */

#define Input 12                 // Leave uncommented to test Input (Arduino -> Processing)
#define Output 13                // Leave uncommented to test Output (Processing -> Arduino)

/* The "#ifdef" "#endif" stuff will automagically  be ignored by the compiler if the above pindefintion is missing
   so you do NOT need to edit anything below to acitavate/deactiavte the two test */
char InByte ;                    // a variable to read incoming serial data into

void setup() {
  Serial.begin(9600);            // initialize serial communication:
#ifdef Output
  pinMode(Output, OUTPUT);       // LED output pin
#ifdef Input
  pinMode(Input, INPUT);         // Input pin to read switch
  digitalWrite(Input, HIGH);     // Activate the pullup resistor (so open switch reads HIGH)
  delay(2000) ;

void loop() {
#ifdef Output
  while (Serial.available() > 0) { // read any and all bytes from the serial line
    InByte =;
    if (InByte == 'H') {           // If an "H" then turn LED on
      digitalWrite(Output, HIGH);
    if (InByte == 'L') {           // If an "L" then turn LED Off
      digitalWrite(Output, LOW) ; 
    //Serial.print(InByte, DEC) ;    // optional debugging 
    // Which implies that any other characters (linefeed, spaces, junk) are simply ignored/discarded
#ifdef Input
  if (digitalRead(Input) == HIGH) {// test switch
    Serial.print('u', BYTE);       // If switch is open/high send "u" to Processing
  } else {     
    Serial.print('d', BYTE);       // else switch is closed/low, send "d" to Processing

  delay(250);                      // QuartetrSecond updates

(edit: Corrected Input/Output confusion, in error description)

i dont have an uno, but im glad someone is having a similiar issue, sorry Msquare,

i am going to tryin and see if i can get communication through matlab or labview to see if that works, but it seems to be an issue with processing, I know the mega is a new board, the pains of being an early adopter? :astonished:

tvisdead: i dont have an UNO

No, my confusion, that was twwong with “Mega 2560 can’t run ‘Dimmer’ example”. Anyhow, if we can get a few more people with the same problem on this thread, we/they/someone can find a common reason and thus the cause… <he wrote, hopefully :.> Could/have you tried my program pair and determined precisly in which direction or both you have a problem?

Bump. Still hoping for a clue...

Did you ever find a solution to this problem? I too am experiencing problems with processing and the arduino mega 2560. I just updated the firmware to rev0001 with no luck.

Nope. I haven't tried, I haven't used that combination of soft/hardware. Incidentally I also had serious hassle with getting Processing to do serial on a Win7 to anything, there is a magic combination of Java and Serialdrivers required. (much complicated by the fact that a given pc may have several Javas installed)

Well, now that this has resurfaced, I may indeed try again, after half-a-year, there must be newer versions for something.

Any luck yet?

No, and nothing on the Processing forum either.

There is a workaround - do not use the Mega :roll_eyes:

I have the same problem, no solution yet?

I need to control 16 servos with processing, that’s why I’ve bought a mega. I know I can control 16 servos with a UNO and an extra chip, but I wanted a cleaner way to do it.

the same sketch works fine with a Diecimila but doesn’t with MEGA (of course I’ve used the right serial port), anyway I’m not really sure the sketch is perfect, is the first time for me trying to do this. please have a check

I use a windows vista,

arduino code

#include <Servo.h>
Servo myservo;
void setup(){
void loop(){  
  if (Serial.available() > 0) {    
    int deg=;    

processing code:

import processing.serial.*;

Serial myPort;  // Create object from Serial class

void setup(){
   size(180, 200);
   myPort = new Serial(this, "COM8", 57600);

void draw(){
  int deg = mouseX;

thanks a lot

On the processing forum there was a reply (after about one year ?!) which basically sugessted to remove the auto-reset on the Mega.

pepperbilly33 has responded to Serial with new Arduino Mega 2560 in Forums: Integration and Hardware on 07-Jan-2012 03:28 PM
i had the same problem. after some hours of searching, i finally find the solution:

  1. Disable Auto Reset
  2. Give some Delay after the port is open

Arduino Playground - HomePage
Arduino Forum

I have not had time to play with that. Let me know if it works for you.

hi, if you still have this issue or anybody, this worked for me I have a mega 2560 (atmega2560 16au), conecting a 10uf capacitor (-) to GND and (+) to reset pin, I was able to run the processing examples with arduino, regards