Eclipse with Udoobuntu And Arduino Communication Tutorial

Discussion in 'UDOO 101' started by emrebektas, Jun 19, 2014.

  1. emrebektas

    emrebektas New Member

    Joined:
    Jan 27, 2014
    Messages:
    19
    Likes Received:
    4
    Hello friends,
    Udoobuntu beta 2.0 is much more powerful distribution and udoo team installed lubuntu software center. I tried install eclipse on udoo and the result is great. it is very stable and i worked on java-arduino communication via eclipse. i will try to tell about this project. if you develop software with java i think this tutorial is useful for you.
    Firstly, you should install eclipse forum lubuntu software center. you can type eclipse search area and install it.
    Secondly, you should write this code "sudo apt-get install librxtx-java" on terminal and open eclipse.
    Thirdly, you should install RXTXcomm-2.2pre2 file, this include essential library for communication (gnu.io.SerialPort ....).
    Fourthly, you should create project and create new java class SerialTest and you copy below java code.
    Finallly, you should open properties->Java Build Path->Add External JaRs..-> select RXTXcomm-2.2pre2.java. After that you compile the project.
    Good Works ... :=)

    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]


    Java code is

    Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import gnu.io.CommPortIdentifier; 
    import gnu.io.SerialPort;
    import gnu.io.SerialPortEvent; 
    import gnu.io.SerialPortEventListener; 
    import java.util.Enumeration;
    
    public class SerialTest implements SerialPortEventListener {
    	SerialPort serialPort;
            /** The port we're normally going to use. */
    	private static final String PORT_NAMES[] = { 
    		//	"/dev/tty.usbserial-A9007UX1", // Mac OS X
            //                "/dev/ttyACM0", // Raspberry Pi
    	     "/dev/ttymxc3", // Udoo
    	//		"/dev/ttyUSB0", // Linux
    		//	"COM3", // Windows
    	};
    	/**
    	* A BufferedReader which will be fed by a InputStreamReader 
    	* converting the bytes into characters 
    	* making the displayed results codepage independent
    	*/
    	private BufferedReader input;
    	/** The output stream to the port */
    	private OutputStream output;
    	/** Milliseconds to block while waiting for port open */
    	private static final int TIME_OUT = 2000;
    	/** Default bits per second for COM port. */
    	private static final int DATA_RATE = 9600;
    
    	public void initialize() {
                    // the next line is for Raspberry Pi and 
                    // gets us into the while loop and was suggested here was suggested http://www.raspberrypi.org/phpBB3/viewtopic.php?f=81&t=32186
                    System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttymxc3");
    
    		CommPortIdentifier portId = null;
    		Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
    
    		//First, Find an instance of serial port as set in PORT_NAMES.
    		while (portEnum.hasMoreElements()) {
    			CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
    			for (String portName : PORT_NAMES) {
    				if (currPortId.getName().equals(portName)) {
    					portId = currPortId;
    					break;
    				}
    			}
    		}
    		if (portId == null) {
    			System.out.println("Could not find COM port.");
    			return;
    		}
    
    		try {
    			// open serial port, and use class name for the appName.
    			serialPort = (SerialPort) portId.open(this.getClass().getName(),
    					TIME_OUT);
    
    			// set port parameters
    			serialPort.setSerialPortParams(DATA_RATE,
    					SerialPort.DATABITS_8,
    					SerialPort.STOPBITS_1,
    					SerialPort.PARITY_NONE);
    
    			// open the streams
    			input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
    			output = serialPort.getOutputStream();
    
    			// add event listeners
    			serialPort.addEventListener(this);
    			serialPort.notifyOnDataAvailable(true);
    		} catch (Exception e) {
    			System.err.println(e.toString());
    		}
    	}
    
    	/**
    	 * This should be called when you stop using the port.
    	 * This will prevent port locking on platforms like Linux.
    	 */
    	public synchronized void close() {
    		if (serialPort != null) {
    			serialPort.removeEventListener();
    			serialPort.close();
    		}
    	}
    
    	/**
    	 * Handle an event on the serial port. Read the data and print it.
    	 */
    	public synchronized void serialEvent(SerialPortEvent oEvent) {
    		if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
    			try {
    				String inputLine=input.readLine();
    				System.out.println(inputLine);
    			} catch (Exception e) {
    				System.err.println(e.toString());
    			}
    		}
    		// Ignore all the other eventTypes, but you should consider the other ones.
    	}
    
    	public static void main(String[] args) throws Exception {
    		SerialTest main = new SerialTest();
    		main.initialize();
    		Thread t=new Thread() {
    			public void run() {
    				//the following line will keep this app alive for 1000 seconds,
    				//waiting for events to occur and responding to them (printing incoming messages to console).
    				try {Thread.sleep(1000000);} catch (InterruptedException ie) {}
    			}
    		};
    		t.start();
    		System.out.println("Started");
    	}
    }
    Arduino example code is
    Code:
    void setup() {
    Serial.begin(9600);
    }
    
    void loop() {
      // put your main code here, to run repeatedly: 
      Serial.println("I Love UDOO :-)");
      delay(2000);
    }
     

    Attached Files:

  2. benjamin_aslamy

    benjamin_aslamy New Member

    Joined:
    Jun 19, 2014
    Messages:
    4
    Likes Received:
    0
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    Hi
    Thanks that is exactly what I was looking for.
     
  3. MinhQuoc

    MinhQuoc New Member

    Joined:
    Dec 23, 2013
    Messages:
    3
    Likes Received:
    0
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    How about the eclipse c++? I want to do something like this with c++
     
  4. emrebektas

    emrebektas New Member

    Joined:
    Jan 27, 2014
    Messages:
    19
    Likes Received:
    4
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    i can not ınstall c++ plugin in eclipse. You can use geany.
     
  5. benjamin_aslamy

    benjamin_aslamy New Member

    Joined:
    Jun 19, 2014
    Messages:
    4
    Likes Received:
    0
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    Hi!

    I get some Errors:

    java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
    Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1044)
    at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:123)
    at SerialTest.initialize(SerialTest.java:39)
    at SerialTest.main(SerialTest.java:107)
     
  6. emrebektas

    emrebektas New Member

    Joined:
    Jan 27, 2014
    Messages:
    19
    Likes Received:
    4
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    open terminal write "sudo apt-get install librxtx-java" and reopen eclipse.
     
  7. benjamin_aslamy

    benjamin_aslamy New Member

    Joined:
    Jun 19, 2014
    Messages:
    4
    Likes Received:
    0
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    [/attachment]



    I have already done that but unfortunately I still get the same error.
     

    Attached Files:

  8. delba

    delba Administrator Staff Member

    Joined:
    May 8, 2013
    Messages:
    1,064
    Likes Received:
    9
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    emrebektas i'll try it asap but this is a great news!!!!!!
     
  9. mikelangeloz

    mikelangeloz Member

    Joined:
    Jul 9, 2013
    Messages:
    129
    Likes Received:
    1
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    That is awesome! Good work!!
     
  10. emrebektas

    emrebektas New Member

    Joined:
    Jan 27, 2014
    Messages:
    19
    Likes Received:
    4
    hi benjamin_aslamy,
    i install udoobuntu v1.0 and i try this steps for you.
    before the installition txrx java

    ı got your error;
    [​IMG]

    After the installation;
    [​IMG]

    (arduino side Serial.println("emreee"))

    Everything works...

    Your problem is distribution.
     
  11. damoreluc

    damoreluc New Member

    Joined:
    Dec 9, 2013
    Messages:
    15
    Likes Received:
    1
    Hi emrebektas

    have you tried to install WindowsBuilder plugin from the suggested download site?
    When I do, Eclipse Indigo crashes while downloading the plugin.

    I've investigated the problem, but no luck until now.
     
  12. emrebektas

    emrebektas New Member

    Joined:
    Jan 27, 2014
    Messages:
    19
    Likes Received:
    4
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    hi damoreluc
    I can not install WindowsBuilder or other package. I get error everytime.
     
  13. emrebektas

    emrebektas New Member

    Joined:
    Jan 27, 2014
    Messages:
    19
    Likes Received:
    4
    Re: Eclipse with Udoobuntu And Arduino Communication Tutoria

    hi MinhQuoc,
    Today, I could install c and c++ plugin with eclipse and I can successfully compile c++ project. I will explain how to install c/c++ plugin with eclipse.
     
    Matt_Neo likes this.

Share This Page