Giter VIP home page Giter VIP logo

adafruit_mlx90393_library's Introduction

Adafruit MLX90393 Magnetic Field Sensor Driver Build StatusDocumentation

This driver is for use with the Adafruit MLX90393 Breakout, and has been designed specifically for these boards:

----> https://www.adafruit.com/product/4022

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

About this Driver

Written by Kevin Townsend for Adafruit Industries.
MIT license, all text above must be included in any redistribution

adafruit_mlx90393_library's People

Contributors

billpugh avatar caternuson avatar evaherrada avatar ladyada avatar maxmaeder avatar microbuilder avatar shawnhymel avatar tyeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

adafruit_mlx90393_library's Issues

Default CONF3 setting is not usable?

This is somewhat related to #3.

Seems odd they'd do this, but the power on / reset value for CONF3 appears to be unusable. Specifically for OSR and DIG_FILT. Register map for reference, CONF3 = 0x02.

image

And then, there's a key bit of info buried in this app note: MLX90393 Getting Started Guide

image

OK, so let's dump the power on / reset register values (sketch code below):

Screenshot from 2020-10-12 09-59-07

Note the odd readings. Ambient Earth mag field should be 10's of uT. The CONF3 register is all 0's. So DIG_FILT=0 and OSR=0. One of the combinations that is said to not work in the app note.

Sketch (library hacked to un-privatize readRegister):

#include "Adafruit_MLX90393.h"

Adafruit_MLX90393 sensor = Adafruit_MLX90393();
uint16_t data;

void setup(void)
{
  Serial.begin(115200);
  while (!Serial);

  Serial.println("Starting Adafruit MLX90393 Register Dump");
  if (! sensor.begin_I2C()) {
    Serial.println("No sensor found ... check your wiring?");
    while (1) { delay(10); }
  }
  Serial.println("Found a MLX90393 sensor");
 
  Serial.println("REGISTER DUMP");
  for (uint8_t reg=0; reg<=0x09; reg++) {
    sensor.readRegister(reg, &data);
    Serial.print(reg); Serial.print(" = 0b"); Serial.println(data, BIN);
  }
}

void loop(void) {
  float x, y, z;

  // get X Y and Z data at once
  if (sensor.readData(&x, &y, &z)) {
      Serial.print("X: "); Serial.print(x, 4); 
      Serial.print("\tY: "); Serial.print(y, 4);
      Serial.print("\tZ: "); Serial.print(z, 4);
      Serial.println(" uT");
  } else {
      Serial.println("Unable to read XYZ data from the sensor.");
  }

  delay(500);
}

MLX90393 resolution

Hi
I notes in the .cpp file RES=0 and RES=1 has not been defined. However in the .h file they are defined as RES-16 and RES-17. In the data sheet it doesn't provide hex register to call for RES=0 and RES=1. Based on the binary number they both should be 0x0? I just want to know if the library support RES-16 and RES-17 as I can't see them been defined in the .cpp file. Thanks

Capture
In the .h file they are defined.
Capture1
Capture2

Wake-Up on Change mode

Guys, this is a 'have you' question, I have just started to look at MLX90393.
I would like to have a play at Wake-Up on Change mode, any experience with this aspect of the chip?
all the best and thanks Jonathan

Incorrect gain coefficients

According to MLX90939 Datasheet REVISION 006 - JANUARY 8, 2020 the values set for HALLCONF = 0x0 in Adafruit_MLX90393.h are in fact the ones for HALLCONF = 0xC but at 35°C. Again in the same datasheet "For HALLCONF = 0x0, the sensitivity scales with a factor 98/75."

/* HALLCONF = 0x0 */
{
/* GAIN_SEL = 0, 5x gain */
{{0.787, 1.267}, {1.573, 2.534}, {3.146, 5.068}, {6.292, 10.137}},
/* GAIN_SEL = 1, 4x gain */
{{0.629, 1.014}, {1.258, 2.027}, {2.517, 4.055}, {5.034, 8.109}},
/* GAIN_SEL = 2, 3x gain */
{{0.472, 0.760}, {0.944, 1.521}, {1.888, 3.041}, {3.775, 6.082}},
/* GAIN_SEL = 3, 2.5x gain */
{{0.393, 0.634}, {0.787, 1.267}, {1.573, 2.534}, {3.146, 5.068}},
/* GAIN_SEL = 4, 2x gain */
{{0.315, 0.507}, {0.629, 1.014}, {1.258, 2.027}, {2.517, 4.055}},
/* GAIN_SEL = 5, 1.667x gain */
{{0.262, 0.422}, {0.524, 0.845}, {1.049, 1.689}, {2.097, 3.379}},
/* GAIN_SEL = 6, 1.333x gain */
{{0.210, 0.338}, {0.419, 0.676}, {0.839, 1.352}, {1.678, 2.703}},
/* GAIN_SEL = 7, 1x gain */
{{0.157, 0.253}, {0.315, 0.507}, {0.629, 1.014}, {1.258, 2.027}},

Wrong Values for Register Reading When Using STM32

I'm using the STM32 Blackpill board. The library is adapted from the Adafruit Library.
The I2C address is 0x18 for the adafruit board I'm using for this test.

The X-Axis data seems to match the Arduino Values.
However, it's not the same for the Y and Z axes.

Below is the data from Arduino:
-3333.000,2152.500,6834.806
-3335.700,2158.800,6819.076
-3333.600,2153.700,6842.550
-3330.900,2162.100,6828.272
-3335.100,2152.200,6823.190
-3327.300,2154.300,6819.802
-3332.700,2159.100,6822.706
-3334.500,2158.800,6815.930
-3338.700,2160.000,6804.072
-3336.000,2151.600,6810.848
-3331.800,2153.400,6812.058
-3333.600,2156.700,6823.190
-3330.300,2156.400,6823.190
-3335.400,2156.700,6816.414
-3330.300,2154.600,6824.158
-3326.400,2150.100,6833.838
-3328.200,2147.400,6825.852
-3329.400,2152.200,6828.998
-3336.000,2160.300,6815.930
-3330.900,2158.800,6835.290
-3334.500,2157.000,6817.624

Below is the Data from STM32:
-3367.800, 72.000, 1053.184
-3368.400, 72.000, 1053.184
-3360.600, 72.000, 1053.184
-3364.500, 72.000, 1053.184
-3368.400, 72.000, 1053.184
-3363.600, 72.000, 1053.184
-3362.100, 72.000, 1053.184
-3369.900, 72.000, 1053.184
-3366.000, 72.000, 1053.184
-3363.600, 72.000, 1053.184
-3362.700, 72.000, 1053.184
-3362.100, 72.000, 1053.184
-3369.900, 72.000, 1053.184
-3368.400, 72.000, 1053.184
-3366.300, 72.000, 1053.184
-3369.300, 72.000, 1053.184
-3363.900, 72.000, 1053.184
-3367.200, 72.000, 1053.184
-3369.600, 72.000, 1053.184
-3368.100, 72.000, 1053.184
-3369.600, 72.000, 1053.184

The HAL_I2C code I adapted is as follows:
uint8_t dataX[3];
int16_t xi, yi, zi;
HAL_I2C_Mem_Read(&hi2c1, 0x18 << 1, 0x30 | 0x02, 1, dataX, 1,
HAL_MAX_DELAY);
HAL_I2C_Mem_Read(&hi2c1, 0x18 << 1, 0x40 | 0x02, 1, dataX, 3,
HAL_MAX_DELAY);
xi = dataX[2] | (dataX[1] << 8);

uint8_t dataY[3];
HAL_I2C_Mem_Read(&hi2c1, 0x18 << 1, 0x30 | 0x04, 1, dataY, 1,
HAL_MAX_DELAY);
HAL_I2C_Mem_Read(&hi2c1, 0x18 << 1, 0x40 | 0x04, 1, dataY, 3,
HAL_MAX_DELAY);
yi = dataY[2] | (dataY[1] << 8);

uint8_t dataZ[3];
HAL_I2C_Mem_Read(&hi2c1, 0x18 << 1, 0x30 | 0x08, 1, dataZ, 1,
HAL_MAX_DELAY);
HAL_I2C_Mem_Read(&hi2c1, 0x18 << 1, 0x40 | 0x08, 1, dataZ, 3,
HAL_MAX_DELAY);
zi = dataZ[2] | (dataZ[1] << 8);

Later, I scale it according to the gain and resolution:
I choose 1X gain and 16bit for Z-axis, 17bit for X&Y-Axis:

sprintf(msg, "%.3f, %.3f, %.3f\r\n", xi * 0.300, yi * 0.300, zi * 0.242);

What could be wrong here?
I doubt the register that I'm reading for magnetometer values.

NOTE: I did not move the sensor while reading values for Arduino and STM32 boards.

Thanks.

Reason for 10ms delay in startSingleMeasurement()

The startSingleMeasurement() function calls on the transceive() function to start a measurement. transceive() takes 5 arguments, the last one being the length of the delay between sending the data and receiving the status byte and optionally other data. When called in startSingleMeasurement(), this argument isn't specified, defaulting the delay to 10 ms.

Is there a reason for this delay in this function, or was the argument perhaps forgotten by mistake? I can't find any mention of this delay in the datasheet. I have also tested the library in I2C mode without this delay, and the sensor appears to be working correctly.

Thanks for taking a look at this. I can make a PR if necessary.

Resolution settings and data type

Hi,

I am having hard time to understand how to interpret properly the 16-bits output of the 19-bits ADC, how it is implemented in the library.

  • In the example given by Melexis (see below), for positive and negative numbers, the 19th bit (left-most) stays at 0. Why so ? Does it mean that this bit is useless ?
  • The 18th bit seems to represent the sign of the measurement data, is it correct ?
  • If yes, this means that it's not possible to know the sign of the magnetic field for RES = 0x1 0x0, because we don't have access to this bit. Isn't it ?
  • Therefore, in the readMeasurement method : xi,yi,zi should be declared as uint16_t for this resolution settings and int16_t for RES = 0x2 ?

Res_XYZ_App

Constant sampling rate when changing frequency

I am trying to increase the sampling rate by changing the frequency in the .cpp file from 1Mhz to 8Mhz. For each axis, I get 15 samples per second at 1Mhz. However, when I increase the frequency to 8Mhz the sample rate remain the same? Also when I force the library to return only one axis (x) using hex 0x08 in #define MLX90393_AXIS_ALL (0x0E) , the sampling rate does not increase. In the MLX90393 data sheet it say sampling rate will increase if a axis is ignored in the measurement. In the loop I set delay to 2ms.

Version 2.0.0 in Platform IO does not contain the changes made to the library in GitHub

Hi

I am using this library in the Platform IO + VSCode development environment. I installed the latest version of the library using the PIO library system, which is 2.0.0, as it is here in GitHub. However, the .h and .cpp files do not contain the changes made to the library since the previous version. I verified the library version is in fact 2.0.0 by checking the library.properties file in PIO.

This issue strikes me as odd since I imagine you guys are using some sort of CI process to publish to PIO, but I would appreciate it if you would look into this.

Thanks again!

Issues about the code in basicdemo

  • Arduino board: Arduino UNO
    The code that is present on the basicdemo example does not provide a sampling frequency of 500 Hz as said in the READ ME link, moreover it is not clear to me why the Z_SERIES command, that according to the datasheet should allow readings along the Z axis, is not activated anywhere.

P.s: the problem related to the wrong axises reported on the top of the board is still present on the available products, this leads people in error **

Need to be able to read data without being in single measurement mode

  • Arduino board: M5Stick-C

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.12

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): LIST REPRO STEPS BELOW

The current library forces you into single measurement mode to do the readData command which slows the sampling rate down drastically. According to the data sheet I should be able to achieve 500 Hz. However, I can only get 90. After working on this for several days and chatting with a few people on the adafruit discord I believe we have arrived at this as the only problem. To double check I used Ted Yapo's MLX90393 library with identical settings and got ~500 Hz sampling rate because that library doesn't force you into single measurement mode. Could the library be modified to make it possible to read data without being in single measurement mode? I believe this causes the magnetometer to perpetually go to sleep and re-awaken each time data is supposed to be read and slows the sampling frequency down a lot. I have pasted my code below which is full of trouble shooting things like printing millis() frequently to show me what in the code is taking so long... Thanks!

/*
SDA: A4
SCL: A5
3v3: 3v3
GND: GND
DRDY (might be labeled Int): A3

*/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_MLX90393.h"
#include <M5StickC.h>

#define MAG_I2C_ADDRESS 0xC

Adafruit_MLX90393 mlx = Adafruit_MLX90393();
#define MLX90393_CS 10

int i =0;

void setup()
{
Serial.begin(115200);
Wire.begin();
Wire.setClock(1000000);
M5.begin();

byte status = mlx.begin_I2C(); //iic jumpers set

mlx.setGain(MLX90393_GAIN_5X);
mlx.setResolution(MLX90393_X, MLX90393_RES_16);
mlx.setResolution(MLX90393_Y, MLX90393_RES_16);
mlx.setResolution(MLX90393_Z, MLX90393_RES_16);
mlx.setOversampling(MLX90393_OSR_0);
mlx.setFilter(MLX90393_FILTER_2);

}

void loop()
{
Serial.print("1,");
Serial.println(millis());
float x, y, z;
Serial.print("2,");
Serial.println(millis());
mlx.readData(&x, &y, &z);
Serial.print("3,");
Serial.println(millis());

if(i>9){
Serial.print(millis()); Serial.print(", ");

Serial.print(x, 2); Serial.print(", ");
Serial.print(y, 2); Serial.print(", ");
Serial.print(z, 2); Serial.println(" ; ");
Serial.print("4,");
Serial.println(millis());
i=0;
}

//delay(500);
i++;
Serial.print("5,");
Serial.println(millis());
}

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.