[Urgent] Sensor Splitter on lejos ev3

This is where you talk about the EV3 hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: roger, gloomyandy, skoehler

New User
Posts: 2
Joined: Wed Jun 29, 2016 7:28 am

[Urgent] Sensor Splitter on lejos ev3

Postby michaellee8 » Wed Jun 29, 2016 7:32 am

Hi everyone
I am developing some program for my robot competition a few days after, so please help me.
i get a SPLIT-Nx-v2 from my teacher and use it to connect a HT Color Sensor and mindsensors LSA, however, when i opened the same port 3 for these sensors in my program as usual, the program states an error when it is exceuted on the ev3. Here are my codes.I tried both SensorPort and ev3.getPort()

MindsensorsLightSensorArray ASensor = new MindsensorsLightSensorArray(SensorPort.S3,20);
HiTechnicColorSensor2 FSensor = new HiTechnicColorSensor2(SensorPort.S3,2);

I uses my own implenatation on the HT Sensor as i didn't find the address parameter in the original implentation. Here are some related parts of them. I just changed the constructor.

public HiTechnicColorSensor2(Port port, int address){
super(port, address);

public HiTechnicColorSensor2(Port port) {
this(port, FACTORY_DEFAULT);

It states
unable to open port

Please help me to solve the problem, thanks.

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

Re: [Urgent] Sensor Splitter on lejos ev3

Postby gloomyandy » Wed Jun 29, 2016 10:33 am

firstly welcome to the forum, secondly I have moved your post to a more appropriate location. The section you posted in is intended for discussions about actually developing leJOS not using it.

OK now to your problem. You can't open a port more than once. If you have multiple i2c devices attached to a port (as in this case) then you need to use the alternate constructor that all i2c sensors have that allows for the use of an already open port. As to why there is no constructor for the HiTechnics colour sensor that takes an address this is because you can not change the i2c address of this device, so there is no need to have a constructor that allows for a different address.

So to open the two sensors you need code that looks something like this...

Code: Select all

MindsensorsLightSensorArray ASensor = new MindsensorsLightSensorArray(SensorPort.S3); // use default i2c address of 0x14
HiTechnicColorSensor2 FSensor = new HiTechnicColorSensor(ASensor.getPort());

Note I have not tested the above code and have not tested using the two sensors you are trying to use with the Port splitter. Not all hardware devices will work with the splitter so there is no guarantee that you will be able to get things working, but opening things as above may help.

You should probably test that both of your sensors work when plugged directly into the EV3 to ensure that they are using the i2c address that you think they are, before trying to use them via the splitter.
leJOS news https://lejosnews.wordpress.com/

New User
Posts: 2
Joined: Wed Jun 29, 2016 7:28 am

Re: [Urgent] Sensor Splitter on lejos ev3

Postby michaellee8 » Wed Jun 29, 2016 1:46 pm

Thank you for helping such lejos noob like me, you just saved me from losing the competition, real thanks.

Return to “EV3 Hardware”

Who is online

Users browsing this forum: No registered users and 1 guest