help with getting MLX90614 to work with Wire.h

I have been programming in C# and C++ on and off for years. I am trying to run an MLX90614 and BME sensor on the I2C bus of a Nano Every. The MLX sensor is a 3.3V one and I have voltage level conversion on SDA/SCL.
With both physically connected, I can get one or other but not both to work.

I only seem to be able to get the MLX to work via SoftWire (SteveMarple GIT) but no luck with Adafruit or other library/examples. As soon as I try and enable a Wire object, it ceases to work. I have found and fixed a few library and example gremlins but still no joy.

The MLX is not technically an I2C bus but has anyone found a way to make it work with Wire library? (I have successfully disabled the PWM mode by writing to the EEPROM, which I guess is what Adafruit do to their modules. ) If I can get it to work with the standard wire library, I should be able to connect other I2C devices too.

thanks
Chris

The MLX sensor is a 3.3V one and I have voltage level conversion on SDA/SCL.

Post a (complete) wiring diagram/schematics of that setup!

The MLX is not technically an I2C bus but has anyone found a way to make it work with Wire library?

It is technically an I2C bus and yes, for me it works with the Wire library.

The MLX90614 works exactly as advertised for me, using the Wire library and a 5V Pro Mini.

Thanks folks
I am confident the issue is not the electronics. The standard module has a 3.3V regulator for the MLX supply and pull up resistors on SCA/SDA. I'm using the standard N-channel FET circuit to change levels with the Nano and used a Picoscope to confirm waveforms and levels. The issue with the MLX90614 also persists without the BME attached.

I have tried all the libraries and examples that the Arduino IDE library manager identifies. Only the examples using SoftWire work. Some of the library/examples are buggy (library and example files out of step and so on) and don't compile but I managed to work through that.

Some libraries are obviously for special boards but it is possible to work around that too.
I suspect it is a timing thing, as I can probe the signals and see that the Nano is trying to communicate on the right pins.

A pointer to a example that works with wire.h on the standard module would be a great starting point.

The standard module has a 3.3V regulator for the MLX supply

What "standard module"? The most commonly available MLX90614, A series, is a 5V device.

I am confident the issue is not the electronics.

I'm not. See "How to use the forum" for instructions on how to provide the information that forum members need, in order to help.

Thanks for trying to help. I am an experienced electronics and software designer for over 30 years, mostly in embedded systems but also as far back as CP/M and OCCAM on Transputers.

I am using the BAA part - which is 3.3V. It is fitted to a standard GY906 module that is found all over Amazon and eBay. On the board are four SMDs. One is a 3.3V regulator, with two caps, which allows the sensor IC to operate with 5V supply. The two SMD pull up resistors are to 3.3V, however, so a voltage translation is required for the Nano. I am using the typical active translator using two FETs.

The logic levels are perfect. A digital storage scope confirms that the voltages are swinging perfectly 0- 3.3V on the module and 0-4.7V on the Nano side. The waveforms are clean and there is little parasitic capacitance.

The MLX has an SMB bus - which is not quite identical to I2C. It also has the complication of a default PWM output on the SDA line, which has to be disabled for I2C communication.

The Adafruit library, which uses Wire, specifically says it is exclusively for their bare sensor. I suspect they program their ICs EEPROM 0x22 location to disable the default PWM output which would otherwise conflict with I2C.

I have done the same and confirmed that PWM is disabled at power on - but the wire-base library examples continue to return 0xff from all RAM locations. This is why I am puzzled.

Ahhh, yes, one of those "standard modules", i.e. designed, made and sold cheaply on Amazon and eBay to unsuspecting hobbyists, by some combination of unknown Chinese firms, very likely using custom, reject or counterfeit parts.

The Arduino forum has many interesting threads documenting the woes encountered with other Amazon and eBay "standard modules", the latest being on counterfeit ATmega328s, commonly found on $2 eBay Pro Mini clones.

If the chip does not perform according to the specs in the Melexis data sheet, the most sensible course of action is to assume that it is not a genuine, fully functional Melexis product, and proceed accordingly.

I understand the potential for counterfeit parts (I bought a genuine Arduino board BTW). Apart from this generalization, are there specific instances of this sensor being one of the victims?

As previously discussed, the part works well when I use the SoftWire library for comms and the results are accurate, giving me no reason to suspect a fake.

I have given up trying to get it to work with the Wire library, reconfigured my board and moved the MLX coms to standard digital I/O pins with SoftWire. I will keep the native I2C pins for the conforming modules and give it another go.

Given that you posted no details, I don’t know what your particular problem is.

No one, to my knowledge, has posted a problem on the Arduino forum, specifically due to the Wire library used in conjunction with a genuine MLX90614. Instead, people have reported successfully using the combination for several years.

Some people, however, have reported encountering apparent fakes.

Thanks, I followed up on the links. Mine has the correct engraved markings that suggest it is a genuine article. Covid has caused these sensors to be in short supply and it was quite expensive. I could only get the BAA version. It works perfectly, as designed, with the SoftWire library by Steve Marple, all of which strongly suggests it a functioning device. Let's move on.

My search also highlighted some users are not using the Wire library to communicate. I counted four alternative software I2C implementations. The Adafruit library is an exception - but that fails and the library documentation specifically . It is not clear why so many choose to design their own I2C interface.

Specifically -- my question was has anyone got the Adafruit library and MLXtest to work with a non-Adafruit IC? The library documentation says it is specifically for their devices and also mentions that the I2C implementation is unique and requires a micro that supports 'repeated start'.

The circuit is a Nano Every, solely connected to the sensor, with the FET voltage translation circuit that I described earlier. It works with the SoftWire library but after many hours of experimentation, I cannot read any EEPROM or RAM location using any library that itself uses the Wire library.

The search also indicated I am not alone, I have found several examples of others with the same issues on this forum and git. One user had success with Wire by lowering the I2C speed to 50000, which is plausible.

The MLX90614 I use came from Pololu, and works perfectly with the Adafruit library.

Thanks for that - I think I am getting there. I moved the MLX connections to GPIO (still works) but the native I2C fails to work with 5V modules on SDA/SCL. I'll sleep on it and when I have it sussed, report back, so that others may benefit.

cwoodhou:
I understand the potential for counterfeit parts (I bought a genuine Arduino board BTW). Apart from this generalization, are there specific instances of this sensor being one of the victims?

Over the last 10 to 5 years or so the prevalence of fakes/pulls/counterfeits on eBay/Amazon has risen to
extreme levels, I would never trust any semiconductor not bought from a reputable electronic components
supplier. There are obviously genuine devices out there, but the odds are too steep to be worth bothering
with eBay for chips/transistors any more unless you know the bona fides of the particular seller.

As previously discussed, the part works well when I use the SoftWire library for comms and the results are accurate, giving me no reason to suspect a fake.

Doesn’t have to be fake, can just be that someone’s bought up the reject bins (which are supposed to be
ground to dust) and packaged them themselves - easy money for the scammers as many rejects are borderline, not completely dead. There are also a lot of PCB pulls (used parts) out there, completely untested.

I have given up trying to get it to work with the Wire library, reconfigured my board and moved the MLX coms to standard digital I/O pins with SoftWire. I will keep the native I2C pins for the conforming modules and give it another go.

To conclude - the I2C works with my BME280 sensor. After two false starts, I found a library/example that functions. With the prototype hardware working, I can look for code efficiencies for the Nano.

If I have time, I will move the MLX back to the I2C and lower the Wire bus speed, as a few other forum posts suggest.

I have to say I am surprised at the quality of the dozen or so example/libraries I have looked at. Some simply do not work or compile, some even have glaring errors, like mismatched declarations and very few are well documented.

For educational purposes (I'm trying to prototype some designs for school projects) it is not helpful