Problem reading QTR-8RC with MSP432 and Energia

I bought a Qtr-8RC a few days ago. I want to detect black and white lines. However I cannot get any response from the sensors. I went through all of the descriptions and instructions on your website. But I cannot make it works. My micro-controller is MSP432. I’m using Energia IDE which is completely the same with Arduino IDE. But I coudn’t get any response when I used your library’s examples. The result is always around 0. No matter how far the sensor is from the line and white paper.

I suspected that Energia has some differences with Arduino, So I went through your library cpp code and test all of the commands and functions, like Micros(), pinMode(), etc. separately on my Micro-controller. They work properly and there is no problem with the compatibility of Energia and Arduino.

However, I thought that maybe there is something incompatible with your library that I cannot recognize. So, I wrote my own code also. My code is really simple. Here is my code for testing one of the sensors which was connected to pin 3.

int timee;
int sensor_values;
void setup() {
  Serial.begin(9600);
}

void loop() {
  pinMode(3, OUTPUT);
  digitalWrite(3, HIGH);
  delayMicroseconds(20);
  pinMode(3, INPUT);
  digitalWrite(3, LOW);
  timee = micros();
  unsigned long startTime = micros();
    while (micros() - startTime < 2500)
    {
        timee = micros() - startTime;
        if (digitalRead(3) == LOW)
          sensor_values = timee;   
    }
   Serial.println(timee);
  delay(500);
}

However, again the response was always around zero and there wasn’t any change when I hold black and white paper in front of it. I know that the optimal distance is 0.3mm.

Then I thought maybe I can use pulseIn() function. I wrote the following code.

void setup() {
  Serial.begin(9600);
}

void loop() {
  pinMode(3, OUTPUT);
  digitalWrite(3, HIGH);
  delayMicroseconds(20);
  pinMode(3,INPUT);
  digitalWrite(3, LOW);
  Serial.println(pulseIn(3, HIGH));
}

Again no response. I wrote another code to check whether the sensor works. I used a LED and connect it to the 4th pin. and I wrote the following code.

void setup() {
  pinMode(4, OUTPUT);
}

void loop() {
  pinMode(3, OUTPUT);
  digitalWrite(3, HIGH);
  delayMicroseconds(20);
  pinMode(3, INPUT);
  digitalWrite(3, LOW);
  if(digitalRead(3)){
    digitalWrite(4, HIGH);
  }
  delay(500);
  digitalWrite(4, LOW);
}

It simply check whether the sensor works. But the led didtn’t turn on at all.

In none of the aforementioned situations, your library and my own codes, I haven’t received any response from the sensors. In all situation LED ON pin was disconnected and I checked the LEDs with my camera and they were on.

Then I thought maybe the sensors are QTRA, though according to your instruction they are QTR-8RA. So, I checked the sensors with ADC. moreover I used your library and examples for QTR-8A but no response again.

I don’t know what should I do to make the sensors working. I’m struggling with them for a couple of days but no progress at all.

The wire connections are really simple. VCC to 5V, GND to GND and sensor1 to pin 3. nothing special. Also I’m pretty sure about my soldering. everything is in good condition.
I bought another sensor and it didn’t work also. I really appreciate your help.

regards,
Mehdi

I also upload your test code that you have posted here to my Microcontroller. But again no response.

Hello, Mehdi.

I am sorry you are having trouble using your QTR-8RC arrays. We test all of our electronics before they ship, so they were likely working at some point. And since multiple units are not working, it seems like this is likely an issue with your setup or how you are using them. Can you post pictures that clearly show your connections and soldered joints? What is your 5V supply and how much current can it provide?

By the way, you probably made a typo, but to be clear: the optimal sensing distance for the QTR sensors is 3mm, not 0.3mm. Also, I split your posts off from that other topic and added them to this new topic that I created for your issue. It is generally easier for us to help troubleshoot your system if you create a new topic instead of posting in someone’s thread.

-Jon

Thanks for your response.

Today I tested the sensor with 3.3 volt. again I didn’t get any response. here is the picture of my boards and connections (for 3.3v).

I’m using my laptop’s USB port. It can provide more than 100mA. However, I tested it with batteries as well. I couldn’t get any response in both cases.

Can you try commenting out or removing digitalWrite(3, LOW); from your Energia code? I want to be sure that your microcontroller I/O line is a high impedance input, as opposed to it being driven low.

-Jon

Dear Jon,

Thanks for your response.

I did the a few changes in the readPrivate function of your library. Then the sensors stared working. please find the new readPrivate function in the following lines.

void QTRSensorsRC::readPrivate(unsigned int *sensor_values)
{
    unsigned char i;

    if (_pins == 0)
        return;

    for(i = 0; i < _numSensors; i++)
    {
        sensor_values[i] = _maxValue;
				pinMode(_pins[i], OUTPUT);// make sensor line an output
        digitalWrite(_pins[i], HIGH); // drive sensor line high  
    }

    delayMicroseconds(10);              // charge lines for 10 us

    for(i = 0; i < _numSensors; i++)
    {
        pinMode(_pins[i], INPUT);       // make sensor line an input
        //digitalWrite(_pins[i], LOW);        // important: disable internal pull-up!
    }

    unsigned long startTime = micros();
    while (micros() - startTime < _maxValue)
    {
        unsigned int time = micros() - startTime;
        for (i = 0; i < _numSensors; i++)
        {
            if (digitalRead(_pins[i]))
                sensor_values[i] = time;
        }
    }
}

I commented out digitalWrite(_pins[i], LOW); Also I removed the second part of the last if statement. And most importantly, I changed the condition of digitalRead(_pins[i]) of the last if statement from LOW to HIGH.

I don’t know why it was LOW before.

1 Like

I am glad things are working; thanks for letting me know.

-Jon

1 Like