What is the sequence of steps to read from QTRX sensors

I cannot use the arduino library for the QTRX sensors (RC version) so i have to write my own way of reading for the sensors, Can you help me know the steps in order to have a basic reading on the sensors ? Power consumption is not a problem i just need the easiest way to read from the sensors.

I use a 3v3 logic MCU and interface the sensors through a MCP23S17 port expanders and adafruit MCP23S17 library

Following your recommendation in the product page

//Set pins to output
  expander1.pinMode(0, OUTPUT);
  expander1.pinMode(1, OUTPUT);
  expander1.pinMode(2, OUTPUT);
  expander1.pinMode(3, OUTPUT);
  expander1.pinMode(4, OUTPUT);
  expander1.pinMode(5, OUTPUT);
  expander1.pinMode(6, OUTPUT);
  expander1.pinMode(7, OUTPUT);
  expander1.pinMode(8, OUTPUT);
  expander1.pinMode(9, OUTPUT);
  expander1.pinMode(10, OUTPUT);
  expander1.pinMode(11, OUTPUT);
  expander1.pinMode(12, OUTPUT);
  expander1.pinMode(13, OUTPUT);
  expander1.pinMode(14, OUTPUT);
  expander1.pinMode(15, OUTPUT);
  
//set all pins high
  expander1.writeGPIOAB(0xFF);
  delayMicroseconds(20);

//set back to input
  expander1.pinMode(0, INPUT);
  expander1.pinMode(1, INPUT);
  expander1.pinMode(2, INPUT);
  expander1.pinMode(3, INPUT);
  expander1.pinMode(4, INPUT);
  expander1.pinMode(5, INPUT);
  expander1.pinMode(6, INPUT);
  expander1.pinMode(7, INPUT);
  expander1.pinMode(8, INPUT);
  expander1.pinMode(9, INPUT);
  expander1.pinMode(10, INPUT);
  expander1.pinMode(11, INPUT);
  expander1.pinMode(12, INPUT);
  expander1.pinMode(13, INPUT);
  expander1.pinMode(14, INPUT);
  expander1.pinMode(15, INPUT);

//immediatly read the ports
  uint16_t data=0;
  //unsigned long startTime = micros();
  // while (micros() - startTime < readingTimeOutus )
    data = expander1.readGPIOAB();

  return data; //returns 0b0000000000000000 

Assuming I followed the instructions correctly and what is said there is correct. I am unforetunatly not seeing the decay fast enough??

sensors are hovering on white paper and 1/2 of the sensors are on the black space.

The basic steps you are taking in the code above look right to me. The MCP23S17 might be adding a bit of complexity into the mix. I haven’t tried controlling these sensors with such an expander.

When I consider your setup/code some thoughts do come to mind:

  • How long does it take the expander to go through all of those pinMode() calls? If that was taking a long time it could be allowing the capacitors to fully discharge. I wouldn’t have expected the higher numbered pins to be affected by this as much though.
    • Can you look at the charge/discharge cycle of one of these pins with an oscilloscope?
    • If you don’t have an oscilloscope, maybe try running the above code in a loop and increase the delay to 1/2 a second and use a multimeter to look at the voltage on one of the pins to make sure that it is going high and low twice a second as you expect. This would make sure that the I/O expander is working as expected.
  • I can understand you not having the needed pins for all 16 sensors on your Arduino but could you connect up a few of the sensors to an Arduino board and use Pololu’s Arduino library to see if it works that way? This lets you know if the port expander is somehow responsible for the issue.

Hello, JakeQ.

Isn’t this line setting only the first 8 pins high? It looks like you’d want a value of 0xFFFF to set all 16. That might explain why you aren’t getting any high readings from the higher-numbered pins, even though they should be less affected by the time it takes to talk to the expander (like AdamGreen mentioned).

If you fix that and start seeing some activity on some of the sensor channels, there might be some hope that you could speed things up by setting all of the pin directions at once (it looks like the MCP23S17 should allow you to change the direction of 8 pins with a single register write, though the Adafruit library doesn’t support that).

Kevin