Giter VIP home page Giter VIP logo

adafruit_circuitpython_mlx90393's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

Adafruit CircuitPython driver for the MLX90393 3-axis magnetometer.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-mlx90939

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-mlx90939

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-mlx90939

Usage Example

import time
import board
import adafruit_mlx90393

i2c = board.I2C()  # uses board.SCL and board.SDA
SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X)

while True:
    MX, MY, MZ = SENSOR.magnetic
    print("[{}]".format(time.monotonic()))
    print("X: {} uT".format(MX))
    print("Y: {} uT".format(MY))
    print("Z: {} uT".format(MZ))
    # Display the status field if an error occured, etc.
    if SENSOR.last_status > adafruit_mlx90393.STATUS_OK:
        SENSOR.display_status()
    time.sleep(1.0)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_mlx90393's People

Contributors

brennen avatar caternuson avatar dhalbert avatar evaherrada avatar foamyguy avatar gamblor21 avatar jerryneedell avatar jposada202020 avatar kattni avatar ladyada avatar makermelissa avatar microbuilder avatar purepani avatar sak917 avatar siddacious avatar sommersoft avatar tannewt avatar tekktrik avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_mlx90393's Issues

Adding a toggle to enable temperature compensation

Currently there is no way to enable the temperature compensation feature of this sensor with this library. It's possible to write to the register directly, but the position of 0mT of the output changes from 0x0 to 0x8000, so it would be helpful for the library to figure out the logic for that instead of doing it manually.

Adding exit mode before reset

If you leave python script while measuring the MLX90393 a power-on reset is needed to communicate again with the MLX90393.

For avoid that i just put before the reset command the exit command.

see page 23 in MLX90393-Datasheet-Melexis-953267.pdf
" It is recommended to perform an ‘EX’ command before issuing a ‘RT’ command"

here my implementation
def reset(self) -> None:
"""
Performs a software reset of the sensor.
"""
self.exitMode()

    if self._debug:
        print("Resetting sensor")
    time.sleep(2)
    self._transceive(bytes([_CMD_RT]))
    # burn a read post reset
    try:
        self.magnetic
    except OSError:
        pass
    return self._status_last

def exitMode(self) -> None:
    """
    Performs a Exit to cancel a measurement.
    """
    if self._debug:
        print("Exit mode")
    self._transceive(bytes([_CMD_EX]))
    return self._status_last

MLX90393-Datasheet-Melexis-953267.pdf

Sensor init fails when using an I2C muxer

Re this thread:
https://forums.adafruit.com/viewtopic.php?t=209506

Adafruit CircuitPython 8.2.6 on 2023-09-12; Adafruit QT Py RP2040 with rp2040
>>> import board
>>> import adafruit_mlx90393
>>> import adafruit_tca9548a
>>> i2c = board.STEMMA_I2C()
>>> mux = adafruit_tca9548a.PCA9546A(i2c)
>>> SENSOR = adafruit_mlx90393.MLX90393(mux[2], address=0x0c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_mlx90393.py", line 226, in __init__
  File "adafruit_mlx90393.py", line 318, in resolution_x
  File "adafruit_mlx90393.py", line 351, in _set_resolution
  File "adafruit_mlx90393.py", line 417, in read_reg
  File "adafruit_tca9548a.py", line 74, in readfrom_into
OSError: [Errno 19] No such device
>>> 

OSError: [Errno 121] Remote I/O error on second run

When I run the adafruit_mlx90393_simpletest.py script for the first time, it runs correctly.

image
[note: I made some formatting changes, but I didn't touch the sensor communication instructions]

But when I run the exact same script again, I get "OSError: [Errno 121] Remote I/O error":
image

I tried to disable and re-enable the I2C bus on my Raspberry Pi 3 Model B, but the only thing that fixed it was restarting the Pi, so I need to restart it every single time I want to test the sensor.

DisplayIO Example Wanted

Add a Basic DisplayIO Based Example

We would like to have a basic displayio example for this library. The example should be written for microcontrollers with a built-in display. At a minimum it should show a Label on the display and update it with live readings from the sensor.

The example should not be overly complex, it's intended to be a good starting point for displayio based projects that utilize this sensor library. Try to keep all visual content as near to the top left corner as possible in order to best fascilitate devices with small built-in display resolutions.

The new example should follow the naming convention examples/libraryname_displayio_simpletest.py with "libraryname" being replaced by the actual name of this library.

You can find an example of a Pull Request that adds this kind of example here: adafruit/Adafruit_CircuitPython_BME680#72

We have a guide that covers the process of contributing with git and github: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

If you're interested in contributing but need additional help, or just want to say hi, feel free to join the Discord server to ask questions: https://adafru.it/discord

AttributeError: 'MLX90393' object has no attribute 'magnetic'

I'm a total newbie, so forgive me if it has an obvious solution :)

I followed the tutorial here:
https://learn.adafruit.com/mlx90393-wide-range-3-axis-magnetometer/circuitpython

I installed the Adafruit CircuitPython MLX90393 with the following command:
sudo pip3 install adafruit-circuitpython-mlx90939

Then I copied the adafruit_mlx90393_simpletest.py file to the Raspberry and run this:
sudo python3 ~/Documents/Work/adafruit_mlx90393_simpletest.py

And got this:

Traceback (most recent call last):
  File "/home/pi/Documents/Work/adafruit_mlx90393_simpletest.py", line 11, in <module>
    MX, MY, MZ = SENSOR.magnetic
AttributeError: 'MLX90393' object has no attribute 'magnetic'

Error when decoding _status_last when the `reset()` function fails

I ran into a particularly weird case where my chip was in a bad state. In my attempt to debug, I noticed that the status being set by the line:

self._status_last = self._transceive(bytes([_CMD_RT]))

aka self._status_last = self._transceive(bytes([_CMD_RT])). was slightly wrong and if I attempted to call the display_status I would get a type error.

I made a local change to address this:

data = self._transceive(bytes([_CMD_RT]))
self._status_last = data[0]

I am happy to make a PR to address this minor corner case and support the library if you would like.

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_mlx90393.py:198
  • adafruit_mlx90393.py:233
  • adafruit_mlx90393.py:288
  • adafruit_mlx90393.py:311
  • adafruit_mlx90393.py:321
  • adafruit_mlx90393.py:331
  • adafruit_mlx90393.py:335
  • adafruit_mlx90393.py:356
  • adafruit_mlx90393.py:371
  • adafruit_mlx90393.py:397
  • adafruit_mlx90393.py:419
  • adafruit_mlx90393.py:477

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.