Doubt using a NXT TouchSensor in EV3 [SOLVED]

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

Doubt using a NXT TouchSensor in EV3 [SOLVED]

Postby esmetaman » Sun Sep 15, 2013 10:48 am

Hi everyone,

I am using in a EV3 brick NXT Touch Sensor and a new EV3 Touch Sensor. Using new sensor, I don't have any problem:

Code: Select all
import lejos.nxt.ADSensorPort;
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.EV3TouchSensor;

public class EV3TouchSensorTest {


   public static void main(String[] args) throws InterruptedException {
      EV3TouchSensor touch = new EV3TouchSensor((ADSensorPort) SensorPort.S1);

      LCD.clear();
      
      while (!Button.ESCAPE.isDown()) {
           LCD.drawString("TS: " + touch.isPressed(), 0, 0);
         System.out.println("TS: " + touch.isPressed());
         Thread.sleep(20);
       }

      LCD.clear();
      System.out.println("EXIT");      
      System.exit(0);

   }

}


but using NXT Sensor, I receive the following exception in shell:

Code: Select all
import lejos.nxt.ADSensorPort;
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.TouchSensor;

public class EV3TouchSensorTest2 {


   public static void main(String[] args) throws InterruptedException {
      TouchSensor touch2 = new TouchSensor((ADSensorPort) SensorPort.S2);

      LCD.clear();
      
      while (!Button.ESCAPE.isDown()) {
           LCD.drawString("TS: " + touch2.isPressed(), 0, 0);
         System.out.println("TS: " + touch2.isPressed());
         Thread.sleep(20);
       }

      LCD.clear();
      System.out.println("EXIT");      
      System.exit(0);

   }

}


Shell:

Code: Select all
root@EV3:~/lejos/examples/2# jrun EV3TouchSensorTest2
Exception in thread "main" java.lang.NullPointerException
        at lejos.nxt.TouchSensor.<init>(TouchSensor.java:24)
        at EV3TouchSensorTest2.main(EV3TouchSensorTest2.java:11)
root@EV3:~/lejos/examples/2#


Why I receive this exception?

Many thanks in advance
Last edited by esmetaman on Sun Sep 15, 2013 3:47 pm, edited 1 time in total.
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt using a NXT TouchSensor in EV3

Postby skoehler » Sun Sep 15, 2013 11:28 am

esmetaman wrote:Why I receive this exception?

Because the argument ot the constructor of TouchSensor is null.
Try using LocalEV3.openSensorPort instead of SensortPort.S2.
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm

Re: Doubt using a NXT TouchSensor in EV3

Postby gloomyandy » Sun Sep 15, 2013 11:38 am

Also make sure the sensor is actually plugged in when you run your program. On the Ev3 leJOS auto identifies the class of sensor attached to a port.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Doubt using a NXT TouchSensor in EV3

Postby esmetaman » Sun Sep 15, 2013 11:56 am

Yes, I have tested again using another wire and using other ports, but the result is the same.
I will try to find another NXT Touch Sensor and I will give feedback.

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt using a NXT TouchSensor in EV3

Postby gloomyandy » Sun Sep 15, 2013 12:03 pm

The code works fine for me, I've just run it. I assume you are using the latest SD card image and that you have downloaded leJOS from git and have compiled your project against the ev3classes project? You may also need to updated the ev3classes.jar file on the sd card with the one built as part of the ev3classes project. Please note that at the moment ev3classes.jar is *NOT* built as part of the ev3classes project. For now you will need to export it manually to a jar file . Right click on the ev3classes project and export it as a jar. When you do this uncheck all of the options to inclide classpath etc items in the jar.

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Doubt using a NXT TouchSensor in EV3

Postby esmetaman » Sun Sep 15, 2013 12:14 pm

Yes,

I followed Wiki to create the bootable SD Card without any problem, but I didn't update ev3Classes.jar which was updated some days ago.
http://sourceforge.net/p/lejos/wiki/Cre ... SD%20card/
http://sourceforge.net/p/lejos/ev3/ci/m ... v3classes/

I will update it and I will give you feedback.

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt using a NXT TouchSensor in EV3

Postby gloomyandy » Sun Sep 15, 2013 12:27 pm

But how are you building your programs? Please when reporting things give as much information as possible. I will try and help, but the more information you provide the less time it will take to work out what is going on.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Doubt using a NXT TouchSensor in EV3

Postby esmetaman » Sun Sep 15, 2013 12:41 pm

Hi Andy,

I am building examples using:

OS: Ubuntu 10 LTS
IDE: Eclipse
JDK: 1.6


This evening, i will create a new bootable SD Card with latest ev3classes.jar

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt using a NXT TouchSensor in EV3

Postby gloomyandy » Sun Sep 15, 2013 12:54 pm

Yes but are you building them using the code from git and referencing the ev3classes project? Or are you using the ev3classes.jar file directly?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Doubt using a NXT TouchSensor in EV3

Postby esmetaman » Sun Sep 15, 2013 3:28 pm

Hi Andy,

I referenciate ev3classes.jar in the project. Besides, the file is the same which I have used to update SD Card to avoid any problem.

I have just update SD with latest jar from git:
http://sourceforge.net/p/lejos/ev3/ci/m ... lasses.jar

Next week, I will test the sensor using NXT-G with a old NXT brick in another environment.
Maybe sensor is broken, I don't usually use Touch Sensor.

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt using a NXT TouchSensor in EV3

Postby gloomyandy » Sun Sep 15, 2013 3:33 pm

Just remove your sdcard and boot the standard EV3 firmware that way you can use that to test your touch sensor. The port viewer should show you the touch sensor.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Doubt using a NXT TouchSensor in EV3

Postby esmetaman » Sun Sep 15, 2013 3:47 pm

Yes, Original EV3 firmware doesn't detect the NXT Touch Sensor, maybe it was broken. I will try to find another one next week.

Many thanks Andy.

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff