Page 2 of 3

Re: NXT Sensor Input Ports

Posted: 23 Jul 2011, 18:16
by afanofosc
I did not reply to your suggestion, Doc. That's why I didn't quote you. I was just reporting the way the firmware works. You can't read analog values while the port is configured as either lowspeed, lowspeed 9v, or highspeed. My impression from the OP is that they wanted to do exactly that. Switching the port configuration is a way to work around this limitation.

John Hansen

Re: NXT Sensor Input Ports

Posted: 23 Jul 2011, 18:28
by HaWe
thx. As you posted directly after my post I had misunderstood that.

I meanwhile tested the portsplitter with analog + i2c , but it doesn't work:
SensorUS is read correctly while the touch sensor is released, but in the moment the touch sensor is pressed both values are corrupted:
US value freezes, and analog raw is wrong (700-800 instead of ~ 200).

In the moment I unplug 1 sensor, the other one is fine again.

With SensorLight (active) or Sound sensor instead of SensorTouch nothing works at all.

(I tested with two different splitters from 2 different makers)

Code: Select all

#define printf1( _x, _y, _format1, _value1) { \
  string sval1 = FormatNum(_format1, _value1); \
  TextOut(_x, _y, sval1); \
}

task DisplayValues() {
  int myvalue;
  while (1) {
    ResetSensor(S1);                  //
    Wait(50);
    SetSensorTouch(S1);               //
    myvalue=SensorRaw(S1);            //
    printf1(0,48, "Analog =%5d ", myvalue);

    ResetSensor(S1);                  //
    Wait(50);
    SetSensorLowspeed(S1);            //
    myvalue=SensorUS(S1);             //
    printf1(0,40, "Digital=%5d ", myvalue);
  }
}


//********************************************************************

task main()
{

  start DisplayValues;
  while (1);
}

Re: NXT Sensor Input Ports

Posted: 23 Jul 2011, 18:29
by andrew1019
You can't read analog values while the port is configured as either lowspeed, lowspeed 9v, or highspeed.
What other port configuashoins are thare? Can I use a touch sensor and a color sensor on the same port at the same time?
Andy

Re: NXT Sensor Input Ports

Posted: 23 Jul 2011, 18:36
by HaWe
no, unfortunately, touch sensors are analog, too.
I had expected that the code will work (and could be imitated by G-code), but I have no idea why the sensors / ports are not switched correctly between i2c and analog.
https://sourceforge.net/apps/phpbb/mind ... 9315#p9312
Actually, it ought to have worked.

Re: NXT Sensor Input Ports

Posted: 24 Jul 2011, 21:16
by andrew1019
I will try this once I split a cable up, but I am not holding out for much hope of getting it to work. Andy

Re: NXT Sensor Input Ports

Posted: 26 Jul 2011, 10:43
by HaWe
I do neither -
maybe one of the NXT low-level specialists can tell us why this continuously switching between i2c and analog settings doesn't work as expected...?

Re: NXT Sensor Input Ports

Posted: 29 Jul 2011, 09:59
by sebi-mylegopage
It does work, but you must place the Waits on other places(where, you must try (Wo musst du ausprobieren)):
(From my Light Sensor Mux):

Code: Select all

int LSMuxReadSensor(char SensorPort,char Number,char SensorNumber)
{
Adressread=Adress[SensorNumber];
int result;
Command = Light[SensorNumber]+(hoch(2,Number));
ArrayBuild(I2CMsg,Adressread,Command);

//Look at this chapter:
I2CWrite(SensorPort,1,I2CMsg); 
Wait(8);
SetSensorLight(SensorPort);
result=SensorRaw(SensorPort);
SetSensorLowspeed(SensorPort);
Wait(8);
Command = Light[SensorNumber];
ArrayBuild(I2CMsg,Adressread,Command);
I2CWrite(SensorPort,1,I2CMsg);
Wait(8);
//

return result;
}

Re: NXT Sensor Input Ports

Posted: 29 Jul 2011, 10:46
by HaWe
can you please simplify your code just to show how read an analog sensor (e.g., a sound or a light sensor) and an i2c sensor (e.g., an US sensor) rapidly alternating?

Re: NXT Sensor Input Ports

Posted: 29 Jul 2011, 12:45
by sebi-mylegopage
I hope this works:
x=US, y=LS

Code: Select all

SetSensorLowspeed(S1);
Wait(8);
x=SensorUS(S1);
Wait(8);
SetSensorLight(S1);  
y=SensorRaw(S1);
SetSensorLowspeed(S1);
Wait(8);

Re: NXT Sensor Input Ports

Posted: 29 Jul 2011, 13:05
by HaWe
I applied it to my test program, but it still doesn't work yet:

Code: Select all

//********************************************************************

#define printf1( _x, _y, _format1, _value1) { \
  string sval1 = FormatNum(_format1, _value1); \
  TextOut(_x, _y, sval1); \
}



task DisplayValues() {
  int myvalue;
  while (1) {

    SetSensorLowspeed(S1);
    Wait(8);
    myvalue=SensorUS(S1);
    printf1(0,48, "Digital=%5d ", myvalue);
    Wait(8);
    
    SetSensorLight(S1);
    myvalue=SensorRaw(S1);
    Wait(8);
    printf1(0,40, "Analog =%5d ", myvalue);
    Wait(8);
  }
}


//********************************************************************

task main()
{

  start DisplayValues;
  while (1);
}
with an analog light sensor the US sensor gives no values at all, also the light sensor does not work.
using a touch instead of light , the US sensor seems to work, but the touch values are again faulty (700-800 if pressed instead of ~200)

Would you please test it by yourself and post again if you got it working?