Loading...
Logo
Processing Forum
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 ?

Replies(4)

Not exactly overflowing with replies, here ;-)
 
Ok, no answer on the Arduino forum either, although several have the same problem: Works on other boards (including the UNO which uses the same USB-IO-chip) but not on the Mega 2560. Same problem in Win7 as on Win XP. Meanwhile I have now boiled it down to some simple test programs. In fact a single edit lets you quickly change in which direction you want to test or both. It appears that Processing can not send to the Arduino 2560 .
 
Processing code
Copy code
  1. /* Test program for Processing - Arduino Communication
  2. Hardware: USB connection to the Arduino, appropiatly eqipped (See Arduino program source)
  3. You probably need to edit the "Port = new Serial..." line with your number
  4. Edit the final test to choose one or both test
    */
  5. final String test = "Both" ; // Set to one of: Input, Output, Both
  6. import processing.serial.*;    // Get the Serial library
  7. // 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
  8. Serial port; // "port" is now a Serial capable variable
  9. 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);
  10.  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 = port.read();         // 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
     }
Arduino Code
Copy code
  1. /* Test program for Processing - Arduino Communication
  2. 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)
  3. Comment the "#define" if you want input, output or both tests */
  4. #define Input 12                 // Leave uncommented to test Input (Arduino -> Processing)
    #define Output 13                // Leave uncommented to test Output (Processing -> Arduino)
  5. /* 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
  6. void setup() {
      Serial.begin(9600);            // initialize serial communication:
    #ifdef Output
      pinMode(Output, OUTPUT);       // LED output pin
    #endif
    #ifdef Input
      pinMode(Input, INPUT);         // Input pin to read switch
      digitalWrite(Input, HIGH);     // Activate the pullup resistor (so open switch reads HIGH)
    #endif 
      delay(2000) ;
    }
  7. void loop() {
    #ifdef Output
      while (Serial.available() > 0) { // read any and all bytes from the serial line
        InByte = Serial.read();
        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
      }
    #endif

  8. #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
      }
    #endif
  9.   delay(250);                      // QuartetrSecond updates
    }

 

It is one of these nasty situations where the problem could be a fix in the Arduino Serial implementation for 2560 OR a fix in the Processing Serial. Please note, Processing can send data (same COM-driver in the pc) when I use another serial interface software (Delphi coded) so it cant be the board code(?). It cant be my 2560 as others have the same problem.
 
 (edited confusing  Input/Output description)
Months have passed ... I did other things, but the problem is still there. Anyone has a workaround?

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


http://www.arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

http://arduino.cc/forum/index.php?topic=50484.0


thx


pb


Well, it seems a good workaround, but have not yet testet it. I still think it must be a weird timing issue done by the Processing Serial library when opening a port that should be fixed (as other host software does not require a disable the reset).