NXT Sensor Input Ports

Discussion specific to the intelligent brick, sensors, motors, and more.
andrew1019
Posts: 7
Joined: 22 Jul 2011, 14:10

NXT Sensor Input Ports

Post by andrew1019 »

Has anyone ever tried using the analog and digital inputs on the same port at the same time?
haydenstudios
Posts: 252
Joined: 22 Oct 2010, 20:05
Location: The United States of America
Contact:

Re: NXT Sensor Input Ports

Post by haydenstudios »

It is possible, and can be achieved quite easily with a multiplexer. A multiplexer of your description can be bought here.
-Hayden
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXT Sensor Input Ports

Post 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)
andrew1019
Posts: 7
Joined: 22 Jul 2011, 14:10

Re: NXT Sensor Input Ports

Post 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
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXT Sensor Input Ports

Post 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!
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXT Sensor Input Ports

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
haydenstudios
Posts: 252
Joined: 22 Oct 2010, 20:05
Location: The United States of America
Contact:

Re: NXT Sensor Input Ports

Post 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.
-Hayden
andrew1019
Posts: 7
Joined: 22 Jul 2011, 14:10

Re: NXT Sensor Input Ports

Post 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
andrew1019
Posts: 7
Joined: 22 Jul 2011, 14:10

Re: NXT Sensor Input Ports

Post by andrew1019 »

[quoteAh, ok. Then I was not very helpful.][/quote]
Thats fine you tried.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXT Sensor Input Ports

Post 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?
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 15 guests