This NXC driver for the HiTechnic Sensor MUX has SMUX-equivalents of all the standard NXC functions for the supported sensors. For example, to read the HiTechnic Colour Sensor without the SMUX, you’d use ReadSensorHTColor(). The SMUX version is called smuxReadSensorHTColor() and has pretty much the same arguments.
I’ve also added some Doxygen-generated documentation to go with it and two examples, one for the standard LEGO Ultrasound sensor and one for the HiTechnic Colour Sensor.
UPDATE 15 APRIL 2012: Version 0.5 can be downloaded here: [LINK].
Thanks so much for this Xander – really great stuff! I was dreading having to have to make my own drivers for the HiTechnic SMUX!
I have been running some tests and only have a couple issues thus far:
1) I can’t get a standard Lego light sensor working when connected via the SMUX. smuxSensorLegoLightRaw returns values between 1015 & 1019. The fact that they do change a bit suggests to me that it is some sort of calibration or scaling issue? I’ve confirmed that the block is not defective.
2) Perhaps tied to the above, there does not appear to be a way to turn the light brick on (ie. turn one or more of the LEDs on). Is that outside the capabilities of the SMUX anyway? To be honest the HiTechnic colour sensing block looks much better anyway but I thought this might trip some other people up.
3) I think you missed out functions for the standard Lego touch sensors (the basic switches)? After banging my head against it trying to use readDigital function I bothered to read the SMUX NXC tutorial and noticed that the touch sensor is analogue. :$ After that it was plain sailing. This is the function I created to read the touch sensor:
#define TOUCH_SENSOR_THRESHOLD 500
bool smuxReadSensorLegoTouch(const byte muxport)
{
if ( HTSMUXreadAnalogue(muxport) < TOUCH_SENSOR_THRESHOLD )
return TRUE;
else
return FALSE;
}
FYI, the "off" value was 1023 and the "on" (pressed) value was 188-199 on my bricks (I tried 4). 500 seemed like a reasonably threshold but <1023 might be more accurate (though I didn't find any edge cases).
Hi Kate,
1: You are looking for the percentage thing? You can use smuxSensorLegoSoundNorm() for that.
2: Are you using the LEGO Colour Sensor or the LEGO Light Sensor? The Colour sensor is NOT supported by the HT SMUX at all. It’s not a true analogue sensor, nor is it a digital one. LEGO, in all their wisdom, have created a strange chimera of a sensor that uses a different mechanism. The SMUX does not support this. As for turning the light on or off on a Light Sensor, you can use smuxSetSensorLegoLight(). Use false to turn the light off, true to turn it on:
/**
* Set sensor as LEGO Light sensor.
*
* Configure the sensor on the specified port as a LEGO Light sensor.
* @param muxport The SMUX sensor port number.
* @param active Configure in active or inactive mode.
* @return True if no error occured, false if it did
*/
bool smuxSetSensorLegoLight(const byte muxport, const bool active) {
if (!active)
return HTSMUXsetAnalogueInactive(muxport);
else
return HTSMUXsetAnalogueActive(muxport);
}
3: Yeah, the Touch Sensor didn’t get added, for some reason. I don’t really do much with this driver anymore. The original plan was to add this functionality to NXC but that never seemed to happen. I will ping John Hansen about it again. Thanks for the function.
– Xander
Kate,
Just FYI, I have added the Touch Sensor to the driver and have asked HiTechnic to update the driver on their site.
Thanks again for the feedback 🙂
– Xander
[…] touch sensors (the one connected in the picture, distinguished by a lack of a battery).I found a NXC driver for the multiplexer by Xaander Soldaat which was a Godsend – I’d ben dreading having to write one myself after reading some of […]
I was trying the light sensor that comes with the default NXT Mindstorms kit – it can be active (ie the RGB LED can be on) or it can detect light intensite. I don’t think it detects colour. It is a bastardised hybrid sensor though (ie. it can output) so perhaps that is the one you are referring to?
Also, I forgot that I had ordered HiTechnic’s touch sensor multiplexer too! *facepalm* The code they supplied did not work though but I’ve managed to fix it mostly. You may want to incorporate that too – see this post:
http://www.katescomment.com/hitechnic-sensor-multiplexer-nxc/
You should be using ReadSensorHTTouchMultiplexer() for the TMUX sensor. It’s the NXC built-in function. If there are issues with that, you should contact John Hansen. He’s very easily pinged on the Mindboards Forums: https://sourceforge.net/apps/phpbb/mindboards
– Xander
Also, before asking to return the device, please verify that it _doesn’t_ work with NXT-G as well. If it still gives you issues there then there’s a problem with the unit, otherwise it’s your code.
– Xander
Hi, Xander! Thank you very much for this driver. It was very helpful! I could program almost all the sensor I wanted, but I’m still having problems with the Lego Light Sensor. Can you help me? I’m new at programming, so I don’t know very much. What I need is making my robot follow a line while using the multiplexer with the Light Sensor in ports 1 and 2, but I can’t make them work…
First try to make the robot follow the line without the use of the multiplexer. You should take a look at this document here: [LINK]. This should prove quite useful in understanding line followers.
I made a program to follow the line (NXC) without the multiplexer and it worked. Also I made the same program with the multiplexer (NXT-G) and it worked too.
But I can’t do it with the first one (I use Bricx), because I don’t know how to make the light go on and off and the sensor work (while using the multiplexer). I saw your other post and I still couldn’t make it. In fact, what I need is a way to program this with NXC. Can you help me? I think that I’m just missing something, but I don’t know what.
Post your question on the Mindboards forums and include your code. I will take a look at it there.
OK! Thank you!
Trinfactor3 is a new open-source sensor multiplexor for NXT. You’d find it quite useful. Please take a look at trinfactor3.appspot.com
It certainly looks interesting. I couldn’t find the CAD files or a BOM on your site. The connectors don’t look like standard NXT connectors or is it for a different range of sensors?
Hello, I will participate in a robotics championship, and need to know how to install the drivers on nxt brick. I am new to programming. I downloaded your driver (and even open it in DevC ++), but did not understand almost anything and I do not know how to install the nxt brick. Please help me.
The driver only works with BrixCC. I wrote that driver more than 5 years ago, I am not sure how it’s used anymore. The drivers are not “installed”, you simply include them in the NXC program you have written and they get compiled in.
Okay, so I know this thread is realy old but I need to know the answer to a question regarding the multiplexer.
That is how do I set an active Light sensor in the smux?
Using a normal port without the smux I use
SetSensorType(S3, SENSOR_TYPE_LIGHT_ACTIVE); but I can’t get it to work with the smux. I can read the sensor but I can’t activate the red light.
Thanks in advance.
Okay I’m sorry but I just realized that the reason
smuxSetSensorLegoLight
didn’t work was beause I scanned the ports after wich for some reason inactivated it.
Sry for this unnecessary question.