How do I turn that servo with this application?!

Greetings!

So I've been trying to put together an app where I can turn a servo to either 90 or 0 degrees when it runs

So far I've had some good luck with Processing 2.2.1 where I'm able to send a arduino.servoWrite(9, 90); command in the to the UNO board and it turns the servo, Yay!

But I need it to be a stand alone app so I can execute it with a bat file. When I create the app (Ctrl+E) I get the 100mb folder with everything in it (I hope) But when I try to run it, the servo does nothing :(

Here is my Code:

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

void setup() {
  arduino = new Arduino(this, Arduino.list()[1], 57600);
  arduino.pinMode(9, Arduino.SERVO);
}

void draw() {
    arduino.servoWrite(9, 90);
}

Very simple nothing to extraordinary. But my success rate is declining now...

Oh and when I ran this for the first time it said it couldn't find cc.arduino so I had to click on Sketch - Add File - Arduino.jar for it to work. (not sure if this makes a difference or not)

I have tried to use the turn.java file in the source directory and javac turn.java to create a class so I can run it, but it said that it couldn't find any of the imports.

Any help with this will be amazing!

Answers

  • So when I try to compile with javac I get this

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\myapp\monitor_turn\application.windows64\source>javac monitor_turn.java
    monitor_turn.java:1: error: package processing.core does not exist
    import processing.core.*;
    ^
    monitor_turn.java:2: error: package processing.data does not exist
    import processing.data.*;
    ^
    monitor_turn.java:3: error: package processing.event does not exist
    import processing.event.*;
    ^
    monitor_turn.java:4: error: package processing.opengl does not exist
    import processing.opengl.*;
    ^
    monitor_turn.java:6: error: package processing.serial does not exist
    import processing.serial.*;
    ^
    monitor_turn.java:7: error: package cc.arduino does not exist
    import cc.arduino.*;
    ^
    monitor_turn.java:9: error: package org.firmata does not exist
    import org.firmata.*;
    ^
    monitor_turn.java:10: error: package cc.arduino does not exist
    import cc.arduino.*;
    ^
    monitor_turn.java:21: error: cannot find symbol
    public class monitor_turn extends PApplet {
                                      ^
      symbol: class PApplet
    monitor_turn.java:58: error: cannot find symbol
    Arduino arduino;
    ^
      symbol:   class Arduino
      location: class monitor_turn
    monitor_turn.java:69: error: cannot find symbol
      arduino = new Arduino(this, Arduino.list()[1], 57600);
                    ^
      symbol:   class Arduino
      location: class monitor_turn
    monitor_turn.java:69: error: cannot find symbol
      arduino = new Arduino(this, Arduino.list()[1], 57600);
                                  ^
      symbol:   variable Arduino
      location: class monitor_turn
    monitor_turn.java:77: error: cannot find symbol
      arduino.pinMode(9, Arduino.SERVO);
                         ^
      symbol:   variable Arduino
      location: class monitor_turn
    monitor_turn.java:94: error: cannot find symbol
          PApplet.main(concat(appletArgs, passedArgs));
                       ^
      symbol:   method concat(String[],String[])
      location: class monitor_turn
    monitor_turn.java:94: error: cannot find symbol
          PApplet.main(concat(appletArgs, passedArgs));
          ^
      symbol:   variable PApplet
      location: class monitor_turn
    monitor_turn.java:96: error: cannot find symbol
          PApplet.main(appletArgs);
          ^
      symbol:   variable PApplet
      location: class monitor_turn
    16 errors
    
    C:\myapp\monitor_turn\application.windows64\source>
    
  • Ok so I managed to get all those errors away and have created the class for monitor_turn.

    But I'm getting a new error.

    C:\myapp\monitor_turn\application.windows64\source>java -cp . monitor_turn
    Uncaught error fetching image:
    java.lang.NullPointerException
            at sun.awt.image.URLImageSource.getConnection(Unknown Source)
            at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
            at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
            at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
            at sun.awt.image.ImageFetcher.run(Unknown Source)
    

    Does anyone have any ideas?

  • edited March 2015

    HI, you have loaded the library "Firmata" in processing and arduino? Looking after the example "Arduino_Servo" in processing and load the sketch "ServoFirmata" in Arduino. "Arduino.cc" I think part of the Firmata library

  • @camperos Yes I have loaded the Firmata and uploaded it to my UNO board, that works from inside of Processing, but doesn't work out of it when an EXE

  • Hi, the app turn.exe works well. I have JDK 1.7.0_25, check if you have set the bin path of the JDK in the environment variable "path"

  • @camperos thanks for your help - now in my \Program Files\Java I have 4 directories jdk1.6.0_25 - jdk1.7.0_45 - jre6 - jre7 I've checked the Environment variable Path like you said and it points to jdk1.7.0_45/bin path but it's still not working :(

    I'm currently running Processing 2.2.1 64bit.

  • I figured a way around it :)

  • Mind telling us? People with the same problem would benifit...

  • Sure :)

    Create your Sketch file.

    Open notepad and add the following:

    c:\myapp\processing-2.2.1\processing-java --run --sketch=c:\myapp\turn\ --output=c:\myapp\run\ --force

    The first line "c:\myapp\processing-2.2.1\processing-java" is to locate the exe file processing-java which should be in the processing route directory. Run to tell it that you want to run this sketch file Sketch is the file that you have create and want to run. Output is the directory that it need to be outputted to. Force will forcibly remove the same directory and every time you run the command.

    Now save the file as a .bat in any directory (cause we have told it where to look for the exe file)

    Now run and enjoy the feeling :)

    Note: There is an issue where sometimes the COM port comes back as busy. Maybe it's because the USB goes into standby or switches off. Not 100% sure.

    +Note: All this is doing is uploading and running the sketch on the device, I still haven't figured out how to contently talk to the board.

Sign In or Register to comment.