Serial: Port busy

Hi there!

After googling for more than 3 hours, i will post my question to you. Before i do that, please execute my bad english.

I'm trying to communicatio with my arduino over /dev/ttyACM0. The code on the arduino is OK and the processing code also does its job if i run processing with sudo rights. I can talk to my arduino over this Port within the arduino GUI as a normal user.

BUT: I can't access this serial port as a normal user in processing. I also can't access a USB2Serial Device on /dev/ttyUSB0 in processing.

I'm running processing under Linux Mint (newest Version) and added my user to this groups:

adm uucp dialout cdrom floppy sudo dip plugdev fuse lpadmin sambashare

If i run this code:

import processing.serial.*;  // Import Serial library to talk to Arduino 
import processing.opengl.*; //  Import OpenGL to draw a gradient window

int channel1;  // create a variable to hold the data we are sending to the Arduino
int channel2;
Serial myPort; 

// Send new DMX channel value to Arduino
//
void setDmxChannel(int channel, int value) {
  // Convert the parameters into a message of the form: 123c45w where 123 is the channel and 45 is the value
  // then send to the Arduino
  myPort.write( str(channel) + "c" + str(value) + "w" );
}

// Draw gradient window
//
void drawGradient() {
  // Draw a colour gradient
  beginShape(QUADS);
  fill(0,0,255); vertex(0,0); // Top left BLUE
  fill(255,0,0); vertex(width,0); // Top right RED
  fill(255,255,0); vertex(width,height); // Bottom right RED + GREEN
  fill(0,255,255); vertex(0,height); // Bottom left BLUE + GREEN
  endShape(); 
}  

void setup() {
  println(Serial.list()); // shows available serial ports on the system
  // Change 0 to select the appropriate port as required.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

  size(512,512,OPENGL);  // Create a window
  drawGradient();
  setDmxChannel(4,0);
  setDmxChannel(5,255);
  setDmxChannel(6,0);
}

void draw() {
  channel1 = (255 * mouseX / width); // Use cursor X position to get channel 1 value
  channel2 = (255 * mouseY / height);// Use cursor Y position to get channel 2 value
  setDmxChannel(1,channel1); // Send new channel values to Arduino
  setDmxChannel(2,channel2);
  setDmxChannel(3,255-channel1);

  // You may have to set other channels. Some lamps have a shutter channel that should be set to 255.
  // Set it here:

  delay(50);  // Short pause before repeating
}

i get the following Error:

/dev/ttyACM0 /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3 /dev/ttyS4 /dev/ttyS5 /dev/ttyS6 /dev/ttyS7 /dev/ttyS8 /dev/ttyS9 /dev/ttyS10 /dev/ttyS11 /dev/ttyS12 /dev/ttyS13 /dev/ttyS14 /dev/ttyS15 /dev/ttyS16 /dev/ttyS17 /dev/ttyS18 /dev/ttyS19 /dev/ttyS20 /dev/ttyS21 /dev/ttyS22 /dev/ttyS23 /dev/ttyS24 /dev/ttyS25 /dev/ttyS26 /dev/ttyS27 /dev/ttyS28 /dev/ttyS29 /dev/ttyS30 /dev/ttyS31 /dev/ttyUSB0
libEGL warning: failed to create a pipe screen for i965
Smooth is not supported by this hardware (or driver)
/dev/ttyACM0 /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3 /dev/ttyS4 /dev/ttyS5 /dev/ttyS6 /dev/ttyS7 /dev/ttyS8 /dev/ttyS9 /dev/ttyS10 /dev/ttyS11 /dev/ttyS12 /dev/ttyS13 /dev/ttyS14 /dev/ttyS15 /dev/ttyS16 /dev/ttyS17 /dev/ttyS18 /dev/ttyS19 /dev/ttyS20 /dev/ttyS21 /dev/ttyS22 /dev/ttyS23 /dev/ttyS24 /dev/ttyS25 /dev/ttyS26 /dev/ttyS27 /dev/ttyS28 /dev/ttyS29 /dev/ttyS30 /dev/ttyS31 /dev/ttyUSB0
java.lang.RuntimeException: java.lang.RuntimeException: Error opening serial port /dev/ttyACM0: Port busy
    at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
    at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
    at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
    at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
    at javax.media.opengl.Threading.invoke(Threading.java:191)
    at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
    at processing.opengl.PJOGL.requestDraw(PJOGL.java:688)
    at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1651)
    at processing.core.PApplet.run(PApplet.java:2254)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Error opening serial port /dev/ttyACM0: Port busy
    at processing.serial.Serial.<init>(Unknown Source)
    at processing.serial.Serial.<init>(Unknown Source)
    at p1.setup(p1.java:51)
    at processing.core.PApplet.handleDraw(PApplet.java:2359)
    at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
    at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
    at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
    at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1289)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
    at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1300)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

Had anyone had the same problem or can someone help me please?

Thank You.

Tasm_Devil

Answers

  • edited May 2014

    I am having similar issues with arduino and processing. If i run the following code I get:

    java.lang.RuntimeException: java.lang.RuntimeException: Error opening serial port /dev/ttyACM0: Port busy
    

    If I remove the "P3D" lines, I need for the keystone library to work, the connection to the arduino is successful. I guess there is something not working between P3D and arduino. as indicated here: http://stackoverflow.com/questions/20667410/arduino-com-port-keeps-getting-busysolved/20682377#20682377

    //Libraries
    import deadpixel.keystone.*; //keystone library
    import processing.serial.*; //arduino
    import cc.arduino.*; //arduino
    
    //Objects
    Keystone ks;
    CornerPinSurface surface;
    Arduino arduino;
    
    PGraphics offscreen;
    
    
    
    //variables
    int buttonPin = 2; //arduino read pin
    int sau; //arduino switch
    
    int surp = 0; //increase of colour
    
    
    //
    ///////////////////////////////// SETUP ////////////////////////////////
    //
    void setup() {
      //Arduino Setup
      //println(Arduino.list());
      arduino = new Arduino(this, Arduino.list()[0], 57600);
      arduino.pinMode(buttonPin, Arduino.INPUT);
    
      colorMode(HSB); //change the color mode, so the whole color change thing is easier
    
      //keystone surface
      size(1000,1000, P3D); //P§D important for keystone, since it relies on texture mapping to deform
      ks = new Keystone(this);
      surface = ks.createCornerPinSurface(1000, 1000, 20);
    
      // We need an offscreen buffer to draw the surface we
        // want projected
        // note that we're matching the resolution of the
        // CornerPinSurface.
        // (The offscreen buffer can be P2D or P3D)
      offscreen = createGraphics(1000, 1000, P3D);
    
    }
    
    
    //
    ///////////////////////////////// DRAW ////////////////////////////////
    //
    void draw() {
      //sau = arduino.digitalRead(buttonPin);
      background(0);
    
      offscreen.beginDraw();
    
    
      // Convert the mouse coordinate into surface coordinates
      // this will allow you to use mouse events inside the 
      // surface from your screen. 
      PVector surfaceMouse = surface.getTransformedMouse();
    
      // Draw the scene, offscreen
      offscreen.ellipse(surfaceMouse.x, surfaceMouse.y, 75, 75);
    
      offscreen.noStroke(); 
      //offscreen.fill(125,141,212); 
      offscreen.beginShape();
      offscreen.vertex(660, 260);
      offscreen.vertex(860, 260);
      offscreen.vertex(860, 580);
      offscreen.vertex(660, 580);
      offscreen.endShape();
    
      offscreen.endDraw();
    
    
      // render the scene, transformed using the corner pin surface
      surface.render(offscreen);  
    
    //ARDUINO BUTTON AS TRIGGER
    //if (sau == 1) {  // when the button is pushed
    //        surp+=20;   //...set the color to black
    //}
    
    
    }
    
    
    // MOUSE INSTEAD OF ARDUINO
    //void mousePressed(){ // pressing the mouse
    //  surp+=20; 
      //println(surp); 
    //}
    
    
    
    void keyPressed() { //function for keystone
      switch(key) {
      case 'c':
        // enter/leave calibration mode, where surfaces can be warped 
        // and moved
        ks.toggleCalibration();
        break;
    
      case 'l':
        // loads the saved layout
        ks.load();
        break;
    
      case 's':
        // saves the layout
        ks.save();
        break;
      }   
    }
    
  • I think I solved it, at least my problem.

    just moved the size() line to the beginning of void setup before the arduino stuff.

  • Yea. You got it.

    Your hint worked for me. "moved the size() line to the beginning of void setup". I'am still confused that it worked as root!?!?

    But Thank you very much sektionschef.

Sign In or Register to comment.