mcauser / micropython-mlx90614

MicroPython driver for the MLX90614 IR temperature sensor
MIT License
33 stars 14 forks source link

the '_B_' version has two sensor zones #1

Closed ckuethe closed 7 years ago

mcauser commented 7 years ago

My A version's config register 0x05 has bit 6 = 1, which according to the datasheet means Dual IR sensor, however, when I try to read two bytes from 0x08, it always returns 0.

>>> i2c.readfrom_mem(address, 0x05, 2)
b'\xc3\xb2'
>>> "{0:b}".format(ustruct.unpack('<H', i2c.readfrom_mem(address, 0x05, 2))[0])
'1011001011000011'
>>> i2c.readfrom_mem(address, 0x08, 2)
b'\x00\x00'
ckuethe commented 7 years ago

Section 7.4.1 of the datsheet says that the indicates that EEPROM starts at 0x20, thus config register 1 (0x05 in the EEPROM space) is address 0x25. On my MLX90614BAA:

>>> cfg = bus.readfrom_mem(0x5a, 0x25, 2)                                                                                                             
>>> cfg                                                                                                                                               
b'\xb4\x9f'                                                                                                                                           
>>> "{0:b}".format(ustruct.unpack('<H', cfg)[0])                                                                                                      
'1001111110110100'                                                                                                                                    
>>> "{0:b}".format(ustruct.unpack('<H', cfg)[0] & 0x40)                                                                                               
'0'                                                                                                                                                   
>>>    
ckuethe commented 7 years ago

I might have been confusing in the title when I said _B_ ... I meant to suggest xBx rather than Bxx

mcauser commented 7 years ago

It appears we are working off different datasheets. Would you mind posting a link to yours?

I have been using: https://www.melexis.com/-/media/files/documents/datasheets/mlx90614-datasheet-melexis.pdf

ckuethe commented 7 years ago

https://www.sparkfun.com/datasheets/Sensors/Temperature/MLX90614_rev001.pdf

mcauser commented 7 years ago

You'd assume the one linked to on their website would be the most recent: https://www.melexis.com/en/product/MLX90614/Digital-Plug-Play-Infrared-Thermometer-TO-Can ~Not in this case!~ My mistake. I misread the SparkFun datasheet date as 2016 when it was actually 2006! Thanks for the contribution. I'll review and merge shortly.

ckuethe commented 7 years ago

The Melexis datasheet is more recent than the Sparkfun version, but they do eventually express the same information. I found their use of "opcode" to be kind of confusing and would have preferred them to simply say that RAM is mapped starting at address 0x00 and EEPROM is mapped starting at 0x20.

Thanks for pointing me to the Melexis version; that explains some behavior I was seeing.

Just as a heads up, I'll have a few more changes for you: