Can't turn emmiter on of QRTX-A sensor

I’m building a robot that uses the QTRX Sensor for line following. I use a Teensy 4.1 and, since I have two QTRX sensors, I have to use a GPIO multiplexer. Reading the sensor is no problem, but enabling the emitters is unreliable. Sometimes it works, but most of the time it doesn’t.

I have connected the odd and even emitter pins to channel 0 of the multiplexer.

void selectMuxChannel(int channel, int side = 0)
{
    digitalWrite(S0[side], (channel & 0x01) ? HIGH : LOW);
    digitalWrite(S1[side], (channel & 0x02) ? HIGH : LOW);
    digitalWrite(S2[side], (channel & 0x04) ? HIGH : LOW);
    digitalWrite(S3[side], (channel & 0x08) ? HIGH : LOW);
}

void setEmitter(bool state, int side = 0)
{
    delayMicroseconds(100);

    selectMuxChannel(0, side);
    delayMicroseconds(100);

    pinMode(SIG_d[side], OUTPUT);
    delayMicroseconds(100);

    digitalWrite(SIG_d[side], state ? HIGH : LOW);
    delayMicroseconds(state?300:1200);

    pinMode(SIG_d[side], INPUT);
    delayMicroseconds(100);
}

int readSensor(int channel, int side = 0)
{
    setEmitter(true, side);
    selectMuxChannel(channel + 1, side);
    return analogRead(SIG_a[side]) / normalize[0][channel + 1];
}

I know the pins are the right ones because reading works fine.

My assumption is that, since I’m not able to power the emitter pins all the time, they switch off, but I’m not sure.

My main question is whether it is possible to connect the odd and even pins directly to 3.3 V to turn the emitters on. I don’t need to control them; they just have to be on.

Thanks for helping

Hello.

As described on the QTRX sensor’s product page, the CTRL ODD and CTRL EVEN pins are tied together through a 1kΩ resistor and pulled high, so the emitters are enabled by default. Because of the pull-up, the emitters will only remain disabled during the time you are actively driving the CTRL pins low. So, when your code changes the mode of the Teensy pin back to an input at the end of setEmitter(), the pull-up will take over and enable the emitters again.

Unless you have a specific need to turn the emitters off (e.g. to save power), you should be able to just leave those pins disconnected. Otherwise, an alternative method that doesn’t require the pins be actively driven low would be to use the more advanced method of pulsing the pin low a number of times to set the dimming level really low. You can find more information about this in the “Emitter control” heading of the QTRX-HD-15A reflectance sensor array’s product page.

Brandon