MLX90393

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mromeo12
 
Posts: 5
Joined: Fri Jan 21, 2022 1:47 pm

MLX90393

Post by mromeo12 »

Hello I need an help with with the sensor MLX90393.

I use photon Argon anche I need to connect five of this sensor with Grove I2c 6 port https://www.kiwi-electronics.nl/nl/grov ... ugQAvD_BwE .
I have a problem with the i2C address of the sensor when I connect more than one sensors together.. How can I solve and read the measures from all the sensor at the same time?
Thanks a lot !

this code for a single sensor works:

Code: Select all

// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// MLX90393
// This code is designed to work with the MLX90393_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/products

#include <math.h>

// MLX90393 I2C Address is 0x0C(12)
#define Addr 0x0C

int xMag = 0, yMag = 0, zMag = 0;

int MagInt = 0;

void setup()
{
  // Set variable
  Particle.variable("i2cdevice", "MLX90393");
  Particle.variable("xMag", xMag);
  Particle.variable("yMag", yMag);
  Particle.variable("zMag", zMag);

  // Initialise I2C communication as MASTER
  Wire.begin();
  // Initialise serial communication, set baud rate = 9600
  Serial.begin(9600);

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select Write register command
  Wire.write(0x60);
  // Set AH = 0x00, BIST disabled
  Wire.write(0x00);
  // Set AL = 0x5C, Hall plate spinning rate = DEFAULT, GAIN_SEL = 5
  Wire.write(0x5C);
  // Select address register, (0x00 << 2)
  Wire.write(0x00);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Request 1 byte of data
  Wire.requestFrom(Addr, 1);

  // Read status byte
  if (Wire.available() == 1)
  {
    unsigned int c = Wire.read();
  }

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select Write register command
  Wire.write(0x60);
  // Set AH = 0x02
  Wire.write(0x02);
  // Set AL = 0xB4, RES for magnetic measurement = 0
  Wire.write(0xB4);
  // Select address register, (0x02 << 2)
  Wire.write(0x08);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Request 1 byte of data
  Wire.requestFrom(Addr, 1);

  // Read status byte
  if (Wire.available() == 1)
  {
    unsigned int c = Wire.read();
  }
  delay(300);
}

void loop()
{
  unsigned int data[7];

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Start single meaurement mode,  ZYX enabled
  Wire.write(0x3E);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Request 1 byte of data
  Wire.requestFrom(Addr, 1);

  // Read status byte
  if (Wire.available() == 1)
  {
    unsigned int c = Wire.read();
  }
  delay(100);

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Send read measurement command, ZYX enabled
  Wire.write(0x4E);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Request 7 bytes of data
  Wire.requestFrom(Addr, 7);

  // Read 7 bytes of data
  // status, xMag msb, xMag lsb, yMag msb, yMag lsb, zMag msb, zMag lsb
  if (Wire.available() == 7);
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
    data[2] = Wire.read();
    data[3] = Wire.read();
    data[4] = Wire.read();
    data[5] = Wire.read();
    data[6] = Wire.read();
  }

  // Convert the data
  xMag = data[1] * 256 + data[2];
  if (xMag > 32767)
  {
    xMag -= 65536;
  }

  yMag = data[3] * 256 + data[4];
  if (yMag > 32767)
  {
    yMag -= 65536;
  }

  zMag = data[5] * 256 + data[6];
  if (zMag > 32767)
  {
    zMag -= 65536;
     }
     
      MagInt = sqrt(xMag*xMag + yMag*yMag + zMag*zMag); 
      
  Particle.publish("Magnetic Field in X-Axis : ", String(xMag));
  Particle.publish("Magnetic Field in Y-Axis : ", String(yMag));
  Particle.publish("Magnetic Field in Z-Axis : ", String(zMag));
   delay(1000);
  Particle.publish("Magnetic field Intensity: ", String(MagInt));
  delay(1000);
}
Last edited by adafruit_support_carter on Fri Jan 21, 2022 2:07 pm, edited 1 time in total.
Reason: added [code] tags

User avatar
adafruit_support_carter
 
Posts: 29483
Joined: Tue Nov 29, 2016 2:45 pm

Re: MLX90393

Post by adafruit_support_carter »

I2C requires each device on the bus have a unique address. You can set alternate addresses for the MLX90393 using the A0/A1 solder jumpers:
https://learn.adafruit.com/mlx90393-wid ... ter/pinout

However, this will only allow up to 4 unique addresses.

To get around address conflicts, and I2C muxer can be used:
https://learn.adafruit.com/adafruit-tca ... r-breakout

User avatar
mromeo12
 
Posts: 5
Joined: Fri Jan 21, 2022 1:47 pm

Re: MLX90393

Post by mromeo12 »

I will use also this one? https://www.berrybase.de/it/sensori-mod ... ca9548a-41
But becouse I need only five ports, can I break the board?
Thanks

User avatar
adafruit_support_carter
 
Posts: 29483
Joined: Tue Nov 29, 2016 2:45 pm

Re: MLX90393

Post by adafruit_support_carter »

The linked board uses the same TCA9548 muxer as the Adafruit board. So should work. You do not need to use all 8 ports.

User avatar
mromeo12
 
Posts: 5
Joined: Fri Jan 21, 2022 1:47 pm

Re: MLX90393

Post by mromeo12 »

yes but is soo long. you think that I can break the blu part and use only 5 ports?

User avatar
adafruit_support_carter
 
Posts: 29483
Joined: Tue Nov 29, 2016 2:45 pm

Re: MLX90393

Post by adafruit_support_carter »

Unknown. You'd need to contact the vendor to determine if that is possible.

User avatar
mromeo12
 
Posts: 5
Joined: Fri Jan 21, 2022 1:47 pm

Re: MLX90393

Post by mromeo12 »

okay thanks... have you ever use this multi with the argon?

User avatar
adafruit_support_carter
 
Posts: 29483
Joined: Tue Nov 29, 2016 2:45 pm

Re: MLX90393

Post by adafruit_support_carter »

I have not used that specific combination of hardware. But known no reason(s) why a TCA muxer should not work with MLX90393's.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”