adafruit-circuitpython-mlx90393 2.1.2__py3-none-any.whl → 2.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: adafruit-circuitpython-mlx90393
3
- Version: 2.1.2
3
+ Version: 2.3.2
4
4
  Summary: CircuitPython driver for the MLX90393 3-axis magnetometer.
5
5
  Author-email: Adafruit Industries <circuitpython@adafruit.com>
6
6
  License: MIT
@@ -14,7 +14,7 @@ Classifier: License :: OSI Approved :: MIT License
14
14
  Classifier: Programming Language :: Python :: 3
15
15
  Description-Content-Type: text/x-rst
16
16
  License-File: LICENSE
17
- Requires-Dist: Adafruit-Blinka >=7.0.0
17
+ Requires-Dist: Adafruit-Blinka>=7.0.0
18
18
  Requires-Dist: adafruit-circuitpython-busdevice
19
19
  Requires-Dist: adafruit-circuitpython-typing
20
20
  Provides-Extra: optional
@@ -0,0 +1,6 @@
1
+ adafruit_mlx90393.py,sha256=tTbuoICvkCIFWIm27sqrxMDyRm8CL6NLrma9Eeyv89U,21413
2
+ adafruit_circuitpython_mlx90393-2.3.2.dist-info/LICENSE,sha256=WeIXVkYWpdba3Boxrax8dB0s5qWg9GTxl7c5uTZQDUI,1105
3
+ adafruit_circuitpython_mlx90393-2.3.2.dist-info/METADATA,sha256=cw5kugTu2XX7j0lpXqxUFf3S8YQTPfkyVf51LnHRWkU,4084
4
+ adafruit_circuitpython_mlx90393-2.3.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
5
+ adafruit_circuitpython_mlx90393-2.3.2.dist-info/top_level.txt,sha256=5RT_YbHfXFo2Y6zVvz8MXsZLIHm1OxrjFJrzRaCTdNY,18
6
+ adafruit_circuitpython_mlx90393-2.3.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.2)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
adafruit_mlx90393.py CHANGED
@@ -28,6 +28,7 @@ Implementation Notes
28
28
  https://github.com/adafruit/Adafruit_CircuitPython_Register
29
29
 
30
30
  """
31
+
31
32
  import struct
32
33
  import time
33
34
 
@@ -36,12 +37,13 @@ from micropython import const
36
37
 
37
38
  try:
38
39
  from typing import Tuple
39
- from circuitpython_typing import ReadableBuffer
40
+
40
41
  from busio import I2C
42
+ from circuitpython_typing import ReadableBuffer
41
43
  except ImportError:
42
44
  pass
43
45
 
44
- __version__ = "2.1.2"
46
+ __version__ = "2.3.2"
45
47
  __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MLX90393.git"
46
48
 
47
49
  _CMD_SB = const(0b00010000) # Start burst mode
@@ -60,9 +62,12 @@ _CMD_AXIS_ALL = const(0xE) # X+Y+Z axis bits for commands
60
62
  _CMD_TEMP = const(0x01) # Temperature bit for commands
61
63
 
62
64
  _CMD_REG_CONF1 = const(0x00) # Gain
63
- _CMD_REG_CONF2 = const(0x01) # Burst, comm mode
65
+ _CMD_REG_CONF2 = const(0x01) # Burst, comm mode, temperature compensation
64
66
  _CMD_REG_CONF3 = const(0x02) # Oversampling, Filter, Resolution
65
67
  _CMD_REG_CONF4 = const(0x03) # Sensitivity drift
68
+ _CMD_REG_CONF5 = const(0x04) # X-axis Offset Correction
69
+ _CMD_REG_CONF6 = const(0x05) # Y-axis Offset Correction
70
+ _CMD_REG_CONF7 = const(0x06) # Z-axis Offset Correction
66
71
 
67
72
  # Gain settings
68
73
  GAIN_5X = 0x0
@@ -209,6 +214,8 @@ class MLX90393: # pylint: disable=too-many-instance-attributes
209
214
  resolution: int = RESOLUTION_16,
210
215
  filt: int = FILTER_7,
211
216
  oversampling: int = OSR_3,
217
+ temperature_compensation: bool = False,
218
+ offset: int = 0,
212
219
  debug: bool = False,
213
220
  ) -> None:
214
221
  self.i2c_device = I2CDevice(i2c_bus, address)
@@ -218,6 +225,8 @@ class MLX90393: # pylint: disable=too-many-instance-attributes
218
225
  self._filter = filt
219
226
  self._osr = oversampling
220
227
  self._gain_current = gain
228
+ self._temperature_compensation = temperature_compensation
229
+ self._off_x = self._off_y = self._off_z = offset
221
230
 
222
231
  # Put the device in a known state to start
223
232
  self.reset()
@@ -235,6 +244,12 @@ class MLX90393: # pylint: disable=too-many-instance-attributes
235
244
 
236
245
  # Set gain to the supplied level
237
246
  self.gain = self._gain_current
247
+ self.temperature_compensation = self._temperature_compensation
248
+
249
+ # Set offsets to supplied level
250
+ self.offset_x = self._off_x
251
+ self.offset_y = self._off_y
252
+ self.offset_z = self._off_z
238
253
 
239
254
  def _transceive(self, payload: ReadableBuffer, rxlen: int = 0) -> bytearray:
240
255
  """
@@ -383,6 +398,62 @@ class MLX90393: # pylint: disable=too-many-instance-attributes
383
398
  self.write_reg(_CMD_REG_CONF3, reg)
384
399
  self._osr = level
385
400
 
401
+ @property
402
+ def temperature_compensation(self) -> bool:
403
+ """The temperature compensation setting"""
404
+ return self._temperature_compensation
405
+
406
+ @temperature_compensation.setter
407
+ def temperature_compensation(self, temperature_compensation: bool) -> None:
408
+ reg = self.read_reg(_CMD_REG_CONF2)
409
+ t_cmp_bit = 10
410
+ reg &= ~(1 << t_cmp_bit)
411
+ reg |= temperature_compensation << t_cmp_bit
412
+ self.write_reg(_CMD_REG_CONF2, reg)
413
+ self._temperature_compensation = temperature_compensation
414
+
415
+ @property
416
+ def offset_x(self) -> int:
417
+ """The X axis offset."""
418
+ return self._off_x
419
+
420
+ @offset_x.setter
421
+ def offset_x(self, offset: int) -> None:
422
+ self._set_offset(0, offset)
423
+ self._off_x = offset
424
+
425
+ @property
426
+ def offset_y(self) -> int:
427
+ """The Y axis offset."""
428
+ return self._off_y
429
+
430
+ @offset_y.setter
431
+ def offset_y(self, offset: int) -> None:
432
+ self._set_offset(1, offset)
433
+ self._off_y = offset
434
+
435
+ @property
436
+ def offset_z(self) -> int:
437
+ """The Z axis offset."""
438
+ return self._off_z
439
+
440
+ @offset_z.setter
441
+ def offset_z(self, offset: int) -> None:
442
+ self._set_offset(2, offset)
443
+ self._off_z = offset
444
+
445
+ def _set_offset(self, axis: int, offset: int) -> None:
446
+ if offset < 0x0000 or offset > 0xFFFF:
447
+ raise ValueError("Incorrect offset setting.")
448
+ if axis == 0:
449
+ self.write_reg(_CMD_REG_CONF5, offset)
450
+ elif axis == 1:
451
+ self.write_reg(_CMD_REG_CONF6, offset)
452
+ elif axis == 2:
453
+ self.write_reg(_CMD_REG_CONF7, offset)
454
+ else:
455
+ raise ValueError("Incorrect axis setting.")
456
+
386
457
  def display_status(self) -> None:
387
458
  """
388
459
  Prints out the content of the last status byte in a human-readable
@@ -406,15 +477,12 @@ class MLX90393: # pylint: disable=too-many-instance-attributes
406
477
 
407
478
  :param int reg: The register to read
408
479
  """
409
- # Write 'value' to the specified register
480
+ # Read register
410
481
  payload = bytes([_CMD_RR, reg << 2])
411
- with self.i2c_device as i2c:
412
- i2c.write(payload)
413
-
414
- # Read the response (+1 to account for the mandatory status byte!)
415
482
  data = bytearray(3)
416
483
  with self.i2c_device as i2c:
417
- i2c.readinto(data)
484
+ i2c.write_then_readinto(payload, data)
485
+
418
486
  # Unpack data (status byte, big-endian 16-bit register value)
419
487
  self._status_last, val = struct.unpack(">BH", data)
420
488
  if self._debug:
@@ -446,9 +514,10 @@ class MLX90393: # pylint: disable=too-many-instance-attributes
446
514
  """
447
515
  Performs a software reset of the sensor.
448
516
  """
517
+ self._transceive(bytes([_CMD_EX]))
449
518
  if self._debug:
450
519
  print("Resetting sensor")
451
- time.sleep(2)
520
+ time.sleep(0.002)
452
521
  self._transceive(bytes([_CMD_RT]))
453
522
  # burn a read post reset
454
523
  try:
@@ -462,6 +531,22 @@ class MLX90393: # pylint: disable=too-many-instance-attributes
462
531
  """
463
532
  Reads a single X/Y/Z sample from the magnetometer.
464
533
  """
534
+
535
+ resolutions = {self.resolution_x, self.resolution_y, self.resolution_z}
536
+ valid_tcomp_resolutions = {RESOLUTION_16, RESOLUTION_17}
537
+ if self._temperature_compensation and not resolutions.issubset(
538
+ valid_tcomp_resolutions
539
+ ):
540
+ resolutions_output = f"""Current Resolutions:
541
+ \tresolution_x: {self.resolution_x}
542
+ \tresolution_y: {self.resolution_y}
543
+ \tresolution_z: {self.resolution_z}"""
544
+
545
+ raise ValueError(
546
+ "All resolutions must be RESOLUTION_16 or RESOLUTION_17"
547
+ f" if temperature compensation is enabled.\n {resolutions_output}"
548
+ )
549
+
465
550
  # Set conversion delay based on filter and oversampling
466
551
  delay = _TCONV_LOOKUP[self._filter][self._osr] / 1000 # per datasheet
467
552
  delay *= 1.1 # plus a little
@@ -493,6 +578,9 @@ class MLX90393: # pylint: disable=too-many-instance-attributes
493
578
  elif resolution == RESOLUTION_18:
494
579
  (value,) = struct.unpack(">H", data)
495
580
  value -= 0x8000
581
+ elif self.temperature_compensation:
582
+ (value,) = struct.unpack(">H", data)
583
+ value -= 0x8000
496
584
  else:
497
585
  value = struct.unpack(">h", data)[0]
498
586
  return value
@@ -1,6 +0,0 @@
1
- adafruit_mlx90393.py,sha256=zxCH6UDMo9r_4QBuECzvNMJ63qtcaWRKkyI8vI0yvY8,18430
2
- adafruit_circuitpython_mlx90393-2.1.2.dist-info/LICENSE,sha256=WeIXVkYWpdba3Boxrax8dB0s5qWg9GTxl7c5uTZQDUI,1105
3
- adafruit_circuitpython_mlx90393-2.1.2.dist-info/METADATA,sha256=0Vxyngqb5FMiz5zzgVRrQND25J13KJIEPKh-q-gtWrU,4085
4
- adafruit_circuitpython_mlx90393-2.1.2.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
5
- adafruit_circuitpython_mlx90393-2.1.2.dist-info/top_level.txt,sha256=5RT_YbHfXFo2Y6zVvz8MXsZLIHm1OxrjFJrzRaCTdNY,18
6
- adafruit_circuitpython_mlx90393-2.1.2.dist-info/RECORD,,