mattallen37 wrote:Electronically, not even all the sensors would support that. You'd have to go about it in different ways for the different sensors.
I've actually been curious about the possibility of auto dectection for sensors, could you expand on this? Specifically, is it that I2C sensors support autodetection? What are the different ways to do autodetection?
The I2C sensors should be easy for the master to detect. Do a simple read request, and see if you get a response. For the Lego, HT, and Mindsensors I2C sensors, they have identification registers so the master can tell which one it is communicating with (which one is plugged in). Look at the datasheets to see what I mean.
For analog sensors, some of them would support detection. For example, the light sensor will never have infinite resistance, so if you are reading 1023 raw, then it is not connected. The same should also be true for the sound sensor. The (semi digital) 2.0 Lego color sensor should also be able to be read in RAW mode (though a different method) to detect presence. The touch sensors however are completely open circuits until pressed. There is no way to detect if they are attached (unless they are also pressed).
All the Lego sensors (other than maybe the color sensor) themselves support a variation of auto-detection, but unfortunately the NXT HW does not allow for it. All the sensors that I have a schematic for show that pins 2 and 3 are tied together in the sensors (I don't have the schematic for the color sensor). If you were to ground pin 3, then you could potentially read pin 2 to look for ground (the NXT PCB doesn't support this though).
mattallen37 wrote:The I2C sensors should be easy for the master to detect. Do a simple read request, and see if you get a response. For the Lego, HT, and Mindsensors I2C sensors, they have identification registers so the master can tell which one it is communicating with (which one is plugged in). Look at the datasheets to see what I mean.
So you still need to set the sensor port as digital right? Otherwise you can't send the read sensor type command...
mattallen37 wrote:For analog sensors, some of them would support detection. For example, the light sensor will never have infinite resistance, so if you are reading 1023 raw, then it is not connected. The same should also be true for the sound sensor. The (semi digital) 2.0 Lego color sensor should also be able to be read in RAW mode (though a different method) to detect presence. The touch sensors however are completely open circuits until pressed. There is no way to detect if they are attached (unless they are also pressed).
All the Lego sensors (other than maybe the color sensor) themselves support a variation of auto-detection, but unfortunately the NXT HW does not allow for it. All the sensors that I have a schematic for show that pins 2 and 3 are tied together in the sensors (I don't have the schematic for the color sensor). If you were to ground pin 3, then you could potentially read pin 2 to look for ground (the NXT PCB doesn't support this though).
lizard381 wrote:So you still need to set the sensor port as digital right? Otherwise you can't send the read sensor type command...
Kami
Yes, it is an I2C transaction, the master reads the first 16 (I think 16 anyhow) registers. It would be like reading any other registers (like 0x42...).
I've tried a bit of sensor detection myself. At least to ensure that the sensors I've plugged into the robot, just might be correctly connected.
As mentioned before, the I2C sensors are pretty straight forward. It's the analog sensors that may cause problems. The analog sensors may however behave quite different. If your robot is equipped with two I2C sensors (eg. the ultrasonic sensor and an accelerometer), and two analog sensors (eg. a sound sensor and the classic light sensor), you might be able to detect all sensors correctly, given some knowledge about your actual set-up:
1) Look for the I2C sensors, and reserve the ports for them.
2) The analog sensors must (should) be connected to the remaining two ports.
All you will need to do with the remaining two ports is to do some clever guessing. For each port, you could obtain three values:
Depending on your set-up, how the sensors are connected, you should get very different readings, depending on the state of the port. Both the light sensor and the sound sensor behaves very different in active mode and in passive mode, and the a port with a disconnected sensor should be very easy to spot as well.
I beleive that some simple clever guessing could do the trick in such a scenario - where you have a limited set of sensors.
Regardless, you can not safely guess any analog sensor, and you cannot distinguish between two identical sensors (eg. left and right light sensor). Likewise, you cannot tell the motors apart, unless you have some more knowledge about your actual set-up. But some clever guessing might just be enough in some situations..
I don't think the idea here is to detect what analog sensor is connected. I think the idea is to detect if a sensor is connected.
For the digital sensors, you can detect if they are there by reading them. The manufacturer will sometimes use several registers that you can read to determine specifically what kind of digital sensor is connected.