HT sensors ?

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

Moderators: roger, gloomyandy, skoehler

HT sensors ?

Postby EowynCarter » Sat Nov 02, 2013 8:36 pm

I tried to get the HT compass and accelerator sensor working, and in both cases i get only 0 as a return.

Are the sensor not working, or is my code wrong ?

Code: Select all
package test.ev3;

import lejos.nxt.Button;
import lejos.nxt.I2CPort;
import lejos.nxt.LCD;
import lejos.nxt.LocalI2CPort;
import lejos.nxt.Motor;
import lejos.nxt.SensorConstants;
import lejos.nxt.addon.AccelHTSensor;
import lejos.nxt.addon.CompassHTSensor;
import lejos.nxt.addon.SensorSelector;

public class EV3FirstProgram {

    public static void main(String[] args) {
        LCD.clear();
        LCD.drawString("First EV3 Program", 0, 5);
        Button.waitForAnyPress();
       
        I2CPort ii = new LocalI2CPort();
        ii.open(1);
        AccelHTSensor compasSensor = new AccelHTSensor(ii);
       
        LCD.clear();
        LCD.drawString("Done", 0, 5);

       
        while (true)
           {
           
           int angle = compasSensor.getXAccel();
             LCD.clear();
           LCD.drawString(String.valueOf(angle), 0, 5);
           
           try {
            Thread.sleep(1000);
         } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
           }
    }

}
EowynCarter
New User
 
Posts: 8
Joined: Sat Nov 02, 2013 10:27 am

Re: HT sensors ?

Postby gloomyandy » Sat Nov 02, 2013 8:50 pm

Sorry no idea and I don't have that sensor to try. I can tell you that the HT compass works fine for me.

The code looks sort of ok. Have you tried running this code from a terminal connection? Is there anything interesting displayed on the console? does the open call return success? Try printing out the sensor name/product strings and see if they can be obtained from the sensor. If they can then the i2c stuff is working, and the problem may be elsewhere. If all else fails you have the source of the class library try adding debug code into that (or use the remote debug capabilities to work out what is going on). I assume the sensor works if you use the Lego firmware and use the port view built in application?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3881
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: HT sensors ?

Postby EowynCarter » Sat Nov 02, 2013 9:00 pm

If the compass works for you, i'm probably doing someting wrong.

I'll try some debuging tomorow.
EowynCarter
New User
 
Posts: 8
Joined: Sat Nov 02, 2013 10:27 am

Re: HT sensors ?

Postby gloomyandy » Sat Nov 02, 2013 9:15 pm

Just a thought, but do you have the sensor in the correct port? when you call open(x) x is zero based, so open(1) will require the sensor to be plugged into the port marked 2 on the EV3...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3881
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: HT sensors ?

Postby EowynCarter » Sat Nov 02, 2013 9:41 pm

Damm.
Sensor is plugged in port one indeed.
EowynCarter
New User
 
Posts: 8
Joined: Sat Nov 02, 2013 10:27 am

Re: HT sensors ?

Postby gloomyandy » Sun Nov 03, 2013 8:59 am

Hi,
so are your sensor working now? Things have changed a lot in this area in the master version but we are not quite ready to release that just yet. Should be ready soon though...

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

Re: HT sensors ?

Postby EowynCarter » Sun Nov 03, 2013 9:43 am

Yes. Fist thing I tested when waking up ;)
Tanks for fixing my stupid mistake. Might be a good idea to mention the "zero based" in the javadoc.

Accelerator sensor readings looks OK as far as i can tel. So does the compass.

And yes, seam to have changed a lot when switching to master.
EowynCarter
New User
 
Posts: 8
Joined: Sat Nov 02, 2013 10:27 am


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff