Page 1 of 3

NXT Sensor Input Ports

Posted: 22 Jul 2011, 14:15
by andrew1019
Has anyone ever tried using the analog and digital inputs on the same port at the same time?

Re: NXT Sensor Input Ports

Posted: 22 Jul 2011, 15:26
by haydenstudios
It is possible, and can be achieved quite easily with a multiplexer. A multiplexer of your description can be bought here.

Re: NXT Sensor Input Ports

Posted: 22 Jul 2011, 16:05
by HaWe
I guess he might be thinking more of using a port splitter for A & D.
Although I never tried it, it may be sth like

Code: Select all

int myvalue;
while (true) {
  SetSensor(port, SensorLightActive);  // or how ever this is in NXC for NXT 1.0 Light Sensor 
  Wait(10); // never tried how long to wait to initialize the sensor to analog
  myvalue=SensorValue(port); // or how ever this is in NXC
  SetSensor(port, SensorLowSpeed); // or how ever this is in NXC
  Wait(10); // never tried how long to wait to initialize the sensor to i2c
  myvalue=SensorUS(port); // or how ever this is in NXC for US sensor
}
(I do not know the NXC sensor commands by heart, I always have to look into the NXT docs to see how to do it)

Re: NXT Sensor Input Ports

Posted: 22 Jul 2011, 16:39
by andrew1019
Yes Helmut, I am thinking along the lines of port spliters. Running a digital and an analog sensor off one port to save ports. I just started with mindstorms and was woundering if this has been tried using G Blocks to give you more ports with out multiplexing. Thanks Andy

Re: NXT Sensor Input Ports

Posted: 22 Jul 2011, 16:49
by HaWe
Andy,
I'm sure this works with cascated G-blocks by the same way.
Just try it out, you can't damage anything.
Be sure that your port splitters support multiplying both analog and digital lines!

Re: NXT Sensor Input Ports

Posted: 22 Jul 2011, 18:55
by afanofosc
What you cannot do with the standard NXT firmware is configure a port as a lowspeed (I2C) or highspeed (RS485) port and read analog sensor values while the port is configured for that type. The firmware just doesn't bother to copy over the AD raw value from the AVR into the Input module IOMap structure if a port's SensorType is LOWSPEED, LOWSPEED_9V, or HIGHSPEED. Today I added a couple of lines of code to the enhanced NBC/NXC firmware so that it does copy over the ADRaw value even when the sensor type is one of these three values.

John Hansen

Re: NXT Sensor Input Ports

Posted: 22 Jul 2011, 22:36
by haydenstudios
andrew1019 wrote:Yes Helmut, I am thinking along the lines of port spliters. Running a digital and an analog sensor off one port to save ports. I just started with mindstorms and was wondering if this has been tried using G Blocks to give you more ports with out multiplexing.
Ah, ok. Then I was not very helpful.

Re: NXT Sensor Input Ports

Posted: 22 Jul 2011, 23:56
by andrew1019
Today I added a couple of lines of code to the enhanced NBC/NXC firmware so that it does copy over the ADRaw value even when the sensor type is one of these three values.
John; Does all that mean I can not read the analog and digital inputs of the same port at the same time with the standerd firmware? Will I/ should I switch to a different programing language to get this to work?
I know I have alot to learn.
Thanks Andy

Re: NXT Sensor Input Ports

Posted: 22 Jul 2011, 23:58
by andrew1019
[quoteAh, ok. Then I was not very helpful.][/quote]
Thats fine you tried.

Re: NXT Sensor Input Ports

Posted: 23 Jul 2011, 08:00
by HaWe
John,
I'm not clear about what you replied to my suggestion.
I did not suggest to read analog when the port was configured as i2c (your post sounded like that).

I suggested to:
configure as analog, then read analog,
then configure as i2c, and read i2c,
then again configure as analog, then read analog,
and so on.

why shouldn't this work?