Go Down

Topic: I2C Scanner hanging (Read 230 times) previous topic - next topic

John26542

May 29, 2018, 01:39 am Last Edit: May 29, 2018, 04:21 am by John26542
Hi, I know others have had similar problems but I think I checked everything over and can't see what the problem is. Actually I'm trying to help my 8 year old son with this, but I have rewired everything from scratch twice, tried a different UNO in case the first one had the SDA/SCL fried, checked with a meter that he is using 10k ohm resistors, and added print statements to the scanner code.

We only have the one I2C device (which cost $30) so I am thinking maybe it is no good?

The sensor is a melexis MLX90614ESF-ACF-000-SP. (We've built a little "robot" and he wants to make it heat-seeking -- hey, he's 8 yr old, he wants it to follow people around.)

So, I am trying to attach halfway-decent pics of our set-up, and our board info. I have stared at this quite a bit and believe we are following https://learn.adafruit.com/using-melexis-mlx90614-non-contact-sensors?view=all#wiring-and-test (which is for a wide-angle sensor whereas ours is a 10-degree FOV which we had to get from Mouser).

Here is the code:

Code: [Select]

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop() {
  byte error, address;
  int nDevices;
  Serial.println("Scanning...");
  nDevices = 0;
  for (address = 1; address < 127; address++ ) {
    // The i2c_scanner uses the return value of the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Serial.print(address);
    Wire.beginTransmission(address);
    Serial.println(": After beginTransmission");
    error = Wire.endTransmission();
    Serial.print("After endTransmission, error=");
    Serial.println(error);

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address<16) {
        Serial.print("0");
      }
      Serial.print(address,HEX);
      Serial.println("  !");
      nDevices++;
    } else if (error==4) {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0) {
     Serial.println("No I2C devices found\n");
  } else {
     Serial.println("done\n");
  }
  delay(5000);           // wait 5 seconds for next scan
}


And this results in only the following monitor output:

I2C Scanner
Scanning...
1: After beginTransmission

After which it hangs.

If I unplug the yellow wire, it rolls right along (and says no devices found):

I2C Scanner
Scanning...
1: After beginTransmission
After endTransmission, error=2
2: After beginTransmission
After endTransmission, error=2
3: After beginTransmission
After endTransmission, error=2
4: After beginTransmission
After endTransmission, error=2
5: After beginTransmission
. . .
123: After beginTransmission
After endTransmission, error=2
124: After beginTransmission
After endTransmission, error=2
125: After beginTransmission
After endTransmission, error=2
126: After beginTransmission
After endTransmission, error=2
No I2C devices found

I'm an old programmer but fairly new to electronics, so I may be doing something stupid... would at this point be glad to be proven stupid if it means we can move forward.

Thanks.

I added the pinout from the Melexis datasheet, which is available in its entirety at https://www.melexis.com/en/product/MLX90614/Digital-Plug-Play-Infrared-Thermometer-TO-Can

el_supremo

That code works for me. It finds two devices on the I2C bus. A DS3231 RTC and the EEPROM on the same board.
You must have something wired incorrectly. The photos are useless - very blurred and poor lighting.

Pete
Don't send me technical questions via Private Message.

John26542

Thanks, Pete, for replying, and sorry about those grungy cell-phone photos. I hope the new ones will help. (My digital camera goes back to the CompactFlash days; I no longer had a working reader, but was able to dig up a cable.)

I think the wiring conforms to the Adafruit tutorial I linked to. I am usually slow to blame hardware, but I can't see what we did wrong. And it works (though it finds no I2C device) if the sensor is disconnected.

I suppose the sensor pinouts could be wrong, whether misinterpreted by me or misrepresented by Adafruit.

Wawa

VSS = ground
VDD = supply(+)

You seem to have reversed the power connections of the sensor.
Leo..

el_supremo

#4
May 29, 2018, 04:47 am Last Edit: May 29, 2018, 04:47 am by el_supremo
If those are 10k pullup resistors, they may be too high. The specified value of those for I2C is 4.7k and in some cases even lower values have to be used. Try changing the resistors.
The wiring looks correct otherwise. (but @Wawa has noticed a problem!)

Pete
Don't send me technical questions via Private Message.

Wawa

10k pull up is fine for that short distance.

Compare OP's wiring2.jpg with the breadboard view on the Adafruit site.
Leo..

John26542

@Wawa was right. We had the power supply backwards. Fixing this did not help. We now get rather erratic results. Given the max reverse voltage is 0.4V, I think we may have fried it.

We had this wired up and had to break it down for travel, and I rewired it before testing again and posting this question. So I can't really say whether it was right or wrong the first time.

The 51-page data sheet has a lot of info. The factory slave address is supposed to be 5A, but it configurable. And the whole thing is configurable for PWM output vs the SMBus output. I'd like to try reconfiguring it, but must admit the datasheet is stretching the limit of my understanding. If anyone wants to look at this and give a step-wise explanation of how to configure the EEPROM and read the PWM, I would be grateful. But maybe I'm just getting in over my head here.  :(


John26542

Ok, so in case anyone comes here with a similar problem, here's our follow-up. I gave Mouser another $30 and got the same exact Melexis sensor a 2nd time. My son and I were *very* careful not to reverse-voltage it. And it worked perfectly. Image attached in case anyone wants to see.

My son confesses he thinks he had it backwards.

It made me wonder why they don't slip a diode in there to goof-proof it. But I suppose a diode to handle up to 6V reverse voltage might make the can considerably larger. Curious if any EE out there can comment on that.

Thanks to everyone who replied to us.

John's dad

Go Up