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
