Mindsensor Port Splitter

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

Moderators: 99jonathan, roger, imaqine

Mindsensor Port Splitter

Postby ChrisB01 » Sun Jun 08, 2008 12:38 pm

This in response to another post I made on the subject here
I now have a port splitter and a Lego ultrasonic sensor and a mindsensors accelerometer. I now have to tackle the problem of getting them to work with the port splitter. According to the mindsensors site the accelerometer supports Auto Detecting Parallel Architecture that means it can co-exist with another i2c sensor on the same port. What I need help with is if I need to change the i2c address of the accelerometer how do I do it with code and how do I access the data off both sensors.

Thanks

Chris
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby lawrie » Wed Jun 11, 2008 6:49 pm

My reply to your previous post explained what to do. If I get a chance I will try it myself, so I can give clearer instructions.

You need to change the address of the acceleration sensor by calling sendData with the sequence of bytes specified in the mindsensors documentation.

Something like this should work:

byte[] newAddress = {(byte) 0xA0, (byte) 0xAA, (byte) 0xA5, 0x04)};

I2CSensor s1 = new I2CSensor(SensorPort.S1);
s1.sendData(0x41, newAddress, 4); // Sets address to 0x04

You just need to do this once. I have not tried it.

Once you have done this, you can do:

UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S1);
TiltSensor tilt = new TiltSensor(SensorPort.S1);
tilt.setAddress(0x02); // NXJ address is divided by 2

However, there is a problem with the TitltSensor class. Its constructor sends a command to the device to see if it a Minsensors or HiTechnic device. It will do this before changing the address, so it will send it to the UltrasonicSensor (address 1) not the Acceleration (Tilt) sensor. You will need to subclass TiltSensor and change the address in the constructor, or produce your own version of the TitlSensor class.

Hope this helps. As I say, I have not tried this myself, and leJOS support for non-default addresses is not very good.
lawrie
leJOS Team Member
 
Posts: 842
Joined: Mon Feb 05, 2007 1:27 pm

Thanks

Postby ChrisB01 » Thu Jun 12, 2008 7:34 pm

I have created a new class for the tilt sensor call AccellTiltSensor and this overrides the set address method so that it rechecks the sensor type when it’s called as well as changing the address. This is all good but I still cant get data off it I think there might be a problem with he code you gave me to change the address of the sensor because I think the address it stored in non-volatile memory so if I successfully change it once it shouldn’t not need to be changed again, but I can try to change it and have it not work but just let it use the default address again and it works fine on its own.

Anyway no worries I'm not in any real hurry to get this done and I will just continue developing the other code I need to write but and thanks for all the help you have given me on this subject.

Chris
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby burti » Fri Jun 26, 2009 12:42 am

Have you been successful Chris or somebody else with this issue?
I'm desperating. I tried all nearly all combinations but it doesn't work.

I use LeJos 0.8 and want to use 2 sensors with the mindensors port splitter: a light sensor and the hitechnic compass sensor. That must theoretically work together. The first is an analog sensor, the second a digital one.

According to lawrie, something like :
Code: Select all
byte[] newAddress = {(byte) 0xA0, (byte) 0xAA, (byte) 0xA5, (byte) 0x04};

       I2CSensor s1 = new I2CSensor(SensorPort.S1);
       s1.sendData(0x41, newAddress, 4);      

      LightSensor lightSensor = new LightSensor(SensorPort.S1);
      CompassSensor compassSensor = new CompassSensor(SensorPort.S1);
      compassSensor.setAddress(0x02);
      
// ------------------------------------------------------------------------

// read out values
      while (!Button.ESCAPE.isPressed())
      {
         int x = 0;
         int y = 0;
         LCD.drawString(LABEL_COMPASS, x, y);
         x+=LABEL_COMPASS.length();
         LCD.drawInt((int)compassSensor.getDegreesCartesian(), 3, x , y);         
         x+=3;
         LCD.drawString(" Grad", x, y);
         
         x = 0;
         y++;         
         LCD.drawString(LABEL_LIGHT, x, y);
         x+=LABEL_LIGHT.length();
         LCD.drawInt(lightSensor.readValue(), 3, x , y);
         x+=3;
         LCD.drawString("cm", x, y);
         
         
         LCD.refresh();
         try {
            Thread.sleep(100);
         } catch (InterruptedException e) {
            // TODO Auto-generated catch block

         }
      }

must work. But it doesn't.

I suspect it writes on the wrong registers maybe. Could it be there is a hidden extra register where the i2c address is saved. If so, which one is it? There is no information about the I2C address register of the hitechnic compass sensor on the hitechnic website.
I don't know what to do. (By the way searching on google gives no further help - of course I tried it)

Has anybody advice or ideas ?

Michael
burti
Novice
 
Posts: 61
Joined: Thu Jun 25, 2009 11:41 pm

Postby gloomyandy » Fri Jun 26, 2009 1:13 am

Hi,
I don't think you can mix a Light Sensor with a Compass Sensor. Both will be trying to use the same digital I/O pins. The Light Sensor uses them to control the flood light, the Compass Sensor uses them for i2c. Also the hitechnic sensor is always at a fixed address, unlike the mindsensors i2c devices I don't think you can change the device address.

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

Postby burti » Fri Jun 26, 2009 1:17 am

thx for that important information, Andy.

I guess an ultrasonic and a compass sensor together isn't possible as well.
burti
Novice
 
Posts: 61
Joined: Thu Jun 25, 2009 11:41 pm

Postby ChrisB01 » Fri Jun 26, 2009 7:13 am

I think it is possible to get two digital sensors working together on the port splitter, I never managed it but I didn't try very hard.

The I2C communications system that digital sensors use gives each sensor an address, if the sensors have different addresses you can communicate with them separately.

If your compass sensor is a mindsensors compass sensor you might be able to change its address so it would work, if its a hitechnic sensor it has a fixed address so this wouldn't work. You also need to consider how much power to supply to the sensors.

Chris
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby ChrisB01 » Sat Jan 30, 2010 11:11 am

I've started trying to get this working again, I have changed the address of a mindsensors v2 tilt sensor to 0x02 using the .rxe executable and lego firmware (v1.5). This was successfully. I have been using the included program for testing.

I have really no idea where to start debugging this. Unlike before this is a actual project, I want to try and get the ultrasonic sensor and tilt sensor working together. I have checked the port power settings and they both use TYPE_LOWSPEED_9V so it should be ok?

I just cant work out why the sensors wont work together. Can anyone help?

Thanks,

Chris

The output:
Just the tilt sensor connected:
Code: Select all
T ACCL-NX
  mndsnsrs
  V2.00
U




Just the ultrasonic sensor connected:
Code: Select all
T


U
  LEGO
  V1.0


Both connected:
Code: Select all
T


U
  LEGO
  V1.0


Code: Select all
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import lejos.nxt.addon.TiltSensor;


public class SensorMuxTest {

   public static void main(String[] args) {
      LCD.clear();

      TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
      tiltSensor.setAddress(0x02);
      LCD.drawString("T " + tiltSensor.getSensorType(), 0, 0);
      LCD.drawString("  " + tiltSensor.getProductID() , 0, 1);
      LCD.drawString("  " + tiltSensor.getVersion() , 0, 2);
      
      UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(SensorPort.S1);
      LCD.drawString("U " + ultrasonicSensor.getSensorType() , 0, 3);
      LCD.drawString("  " + ultrasonicSensor.getProductID() , 0, 4);
      LCD.drawString("  " + ultrasonicSensor.getVersion() , 0, 5);

      LCD.refresh();
      
      while (!Button.ESCAPE.isPressed()) {}
   }

}
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby gloomyandy » Sat Jan 30, 2010 11:44 am

Hi Chris,
Have you tried turning ADPA mode on the mindsensors sensor on and off? I think this changes the value of the pull up resistors which may be what is causing your problem here...

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

Postby ChrisB01 » Sat Jan 30, 2010 2:38 pm

Thanks for your quick reply Andy. Unfortunately I don't think this has worked. However I might not have got the command right. I was a bit unsure how to do it anyway, I have included the new code.

Chris

Code: Select all
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import lejos.nxt.addon.TiltSensor;

public class SensorMuxTest {

   public static void main(String[] args) throws InterruptedException {
      LCD.clear();

      TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
      tiltSensor.setAddress(0x02);
      tiltSensor.sendData(0x41, (byte) 0x4E); // ADPA On
      Thread.sleep(100);
      LCD.drawString("T " + tiltSensor.getSensorType(), 0, 0);
      LCD.drawString("  " + tiltSensor.getProductID() , 0, 1);
      LCD.drawString("  " + tiltSensor.getVersion() , 0, 2);
      
      UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(SensorPort.S1);
      LCD.drawString("U " + ultrasonicSensor.getSensorType() , 0, 3);
      LCD.drawString("  " + ultrasonicSensor.getProductID() , 0, 4);
      LCD.drawString("  " + ultrasonicSensor.getVersion() , 0, 5);

      LCD.refresh();
      
      while (!Button.ESCAPE.isPressed()) {}
   }

}
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby gloomyandy » Sat Jan 30, 2010 3:41 pm

Hi Chris,
The command looks fine. The only thing is that you will have to issue it without the Ultrasonic sensor plugged in to the Mux... Other than that sorry I'm not sure what is going on. If I get chance I may try hacking some cables and trying two i2c devices on the same port. But I'm pretty busy at the moment (and about to go away climbing for a week), so it may take me a while to get to this....

The other things you could try would be to switch the mode used for the acceleration sensor to be standard mode...

Code: Select all
      TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
      SensorPort.S1.i2cEnable(0);
      tiltSensor.setAddress(0x02);
      tiltSensor.sendData(0x41, (byte) 0x4E); // ADPA On

You could also try setting the mode to no release mode, to do this change the 0 to be 4....

Good luck...

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

Postby ChrisB01 » Tue Feb 02, 2010 7:15 pm

Thanks, for you support Andy, I have some more info. When I connect a mindsensors line leader but make no reference to it in my program shown below, I get some weird output, however when its not connected all the output is normal (output and program included below). I cant work out why this would happen, my program should not communicate with the line leader at all but it influences the output.

Chris

Output with just the accelerometer connected:
Code: Select all
T ACCL-NX
  mndsnsrs
  V2.00


Output with both accelerometer and lineleader connected
Code: Select all
T mndsnsrs
  mndsnsrs
  mndsnsrs


Program used:
Code: Select all
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.addon.TiltSensor;

public class SensorMuxTest {

   public static void main(String[] args) throws InterruptedException {
      LCD.clear();

      TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
      tiltSensor.setAddress(0x04);
      tiltSensor.sendData(0x41, (byte) 'N'); // ADPA On
      Thread.sleep(100);

      //UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(SensorPort.S1);

      LCD.drawString("T " + tiltSensor.getSensorType(), 0, 0);
      LCD.drawString("  " + tiltSensor.getProductID(), 0, 1);
      LCD.drawString("  " + tiltSensor.getVersion(), 0, 2);

      //LCD.drawString("U " + ultrasonicSensor.getSensorType(), 0, 3);
      //LCD.drawString("  " + ultrasonicSensor.getProductID(), 0, 4);
      //LCD.drawString("  " + ultrasonicSensor.getVersion(), 0, 5);

      LCD.refresh();

      while (!Button.ESCAPE.isPressed()) {
      }
   }

}
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby ChrisB01 » Sun Feb 21, 2010 4:28 pm

I have found a problem, don't know if its the problem but its a clue none the less. Updated my program to feed back error codes. It produces some interesting output. Does anyone know what causes an "I2C Error" (-3)? This would explain why it isn't working.

Both Sensors Connected:
Code: Select all
T

Error Code: -3
U
  LEGO
  V1.0


Only the Accelerometer Connected:
Code: Select all
T ACCL-NX
  mndsnsrs
  V2.00
Error Code: 0
U
 



Program Used:
Code: Select all
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import lejos.nxt.addon.TiltSensor;

public class SensorMuxTest {

   public static void main(String[] args) throws InterruptedException {
      LCD.clear();

      TiltSensor tiltSensor = new TiltSensor(SensorPort.S1);
      tiltSensor.setAddress(0x04);
      int errorCode = tiltSensor.sendData(0x41, (byte) 'N'); // ADPA On
      Thread.sleep(100);

      UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(SensorPort.S1);

      LCD.drawString("T " + tiltSensor.getSensorType(), 0, 0);
      LCD.drawString("  " + tiltSensor.getProductID(), 0, 1);
      LCD.drawString("  " + tiltSensor.getVersion(), 0, 2);
      LCD.drawString("Error Code: " + errorCode, 0, 3);

      LCD.drawString("U " + ultrasonicSensor.getSensorType(), 0, 4);
      LCD.drawString("  " + ultrasonicSensor.getProductID(), 0, 5);
      LCD.drawString("  " + ultrasonicSensor.getVersion(), 0, 6);

      LCD.refresh();

      while (!Button.ESCAPE.isPressed()) {
      }
   }

}
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby gloomyandy » Sun Feb 21, 2010 6:34 pm

Hi Chris,
I was wondering how you have been getting on with this. I've finally got around to trying multiple i2c sensors with a set of hacked cables, more of which below.

Error code -3 means that the firmware detected a protocol error while talking to the device. Typically this means that the i2c ack was not seen. I suspect that this is all caused by the pull up resistors in the various devices. In my own tests I've been able to have both the Lego Ultrasonic sensor and a RFID sensor working on the same port, but if I switch the HiTechnics compass sensor for the Ultrasonic device then nothing works. Looking at the actual signals I can see that the 0V part of the connection is actually around 0.5V which I think is causing the issue. With the sensors I have it is not possible to turn off the pull up resistors and so having more than one seems to cause a problem (particularly for the HiTechnics sensor).

So it seems to me that the key to making this work is to get the pull up resistors disabled (which is what I think the ADPA mode is supposed to do). I'm not sure if that part of the code is working correctly with your sensors. I'm not sure if it is something that you set once or if you have to set it every time. Perhaps you could try sending the command multiple times before you attempt to talk to the other device. I don't have access to any sensors that have this feature so I can't really do much more to help here (though I may get one to try it out).

You may also want to try making the requests multiple times as I found that sometimes the sensors would start to work after a little while... Oh and in the case of the Ultrasonic sensor you probably need to add delay after talking to it as it seems to hang on to the i2c bus for a short while after being accessed...

All the best

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

Postby skoehler » Mon Feb 22, 2010 11:57 am

gloomyandy wrote:Oh and in the case of the Ultrasonic sensor you probably need to add delay after talking to it as it seems to hang on to the i2c bus for a short while after being accessed...


Is that something that we can detect? I mean, does "hang on the bus" mean, that it listens for a while (something we probably can't detect) or is it something else, that we can detect?

If we can detect it, then we should probably implement a way to wait until the I2C bus is "free" again before we send the next command.
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm

Next

Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff