NXT Sensor Input Ports
Re: NXT Sensor Input Ports
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
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: NXT Sensor Input Ports
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)
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);
}
Last edited by HaWe on 24 Jul 2011, 10:24, edited 2 times in total.
-
- Posts: 7
- Joined: 22 Jul 2011, 14:10
Re: NXT Sensor Input Ports
What other port configuashoins are thare? Can I use a touch sensor and a color sensor on the same port at the same time?You can't read analog values while the port is configured as either lowspeed, lowspeed 9v, or highspeed.
Andy
Re: NXT Sensor Input Ports
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.
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.
-
- Posts: 7
- Joined: 22 Jul 2011, 14:10
Re: NXT Sensor Input Ports
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
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...?
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...?
-
- Posts: 16
- Joined: 29 Sep 2010, 13:47
- Location: Germany
- Contact:
Re: NXT Sensor Input Ports
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):
(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
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?
-
- Posts: 16
- Joined: 29 Sep 2010, 13:47
- Location: Germany
- Contact:
Re: NXT Sensor Input Ports
I hope this works:
x=US, y=LS
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
I applied it to my test program, but it still doesn't work yet:
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?
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);
}
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?
Who is online
Users browsing this forum: No registered users and 2 guests