I tried hard to get 2 mindsensors distnx running using a mindsensors port splitter - without success.
I used the reference implementation OpticalDistanceSensor.java by mindsencors.com (http://www.mindsensors.com/index.php?module=documents&JAS_DocumentManager_op=viewDocument&JAS_Document_id=65).
If you use a dist-nx sensor on one port it works fine.
But I haven't found a solution to use 2 dist-nx using a port splitter.
Calling "setAPDAOn();" to switch APDA seems to change nothing.
What does it do at all? DOes it change any address ? If so, then I haven't noticed it. Dead end !
Changing the address with code like this neither works:
- Code: Select all
byte[] newAddress = {(byte) 0xA0, (byte) 0xAA, (byte) 0xA5, (byte) 0x08};
OptDistSensorSR optDistSen = new OptDistSensorSR(SensorPort.S1);
optDistSen.sendData(0x41, newAddress, 4);
optDistSen.setAddress(0x04);
OptDistSensorSR is my name for the OpticalDistanceSensor class by mindsensors.
Other adresses like 0x04 neither work.
It seems to me that sendData(..) doesn't work in this case at all!
Why? You can always read wrong values from the sensors which are the result of interference between those.
I read several threads but it didn't help me:
http://lejos.sourceforge.net/forum/viewtopic.php?t=688
http://lejos.sourceforge.net/forum/viewtopic.php?t=489
http://lejos.sourceforge.net/forum/viewtopic.php?t=742
http://lejos.sourceforge.net/forum/viewtopic.php?t=813
Of course I noticed there is/was a mistake in the setaddress-method.
So I added the modified setaddress-method by gloomyandy to OptDistSensorSR and used it:
- Code: Select all
public int sendData(int address, int register, byte [] buf, int len) {
// AS Fix to allow write to work correctly. Avoid using the
// automatic internal address. Instead send the address as
// part of the data
if (len >= 5) return -1;
byte[] byteBuff = new byte[len+1];
for(int i=0; i < len; i++ )
byteBuff[i+1] = buf[i];
byteBuff[0] = (byte)register;
int ret = getPort().i2cStart(address, 0, 0, byteBuff, len+1, 1);
if (ret != 0) return ret;
while (getPort().i2cBusy() != 0) {
Thread.yield();
}
return 0;
}
- Code: Select all
byte[] newAddress = {(byte) 0xA0, (byte) 0xAA, (byte) 0xA5, (byte) 0x08};
OptDistSensorSR optDistSen = new OptDistSensorSR(SensorPort.S1);
optDistSen.sendData(0x01,0x41, newAddress, 4);
optDistSen.setAddress(0x04);
Once again: Doesn't work. Besides I tried several combinations without success. I'm desperating.
Have you advice for me please?
It must work anyway but I don't know how ....
Thank you in advance,
burti
