Joystick with MLX90393 Magnetometer

Hello!

I currently have set myself the project to build a 3d printed joystick.
and I'm nearly finished with the CAD design.

Today my sensor arrived and I wanted to quickly test it so I followed the instructions
from SparkFuns hompage. (Bottom of the page)
(Qwiic Magnetometer (MLX90393) Hookup Guide - SparkFun Learn)

/*

  3.3V = 3.3V
  GND = GND
  SDA = A4
  SCL = A5

*/

#include <Wire.h>
#include <MLX90393.h>

MLX90393 mlx;
MLX90393::txyz data; //Create a structure, called data, of four floats (t, x, y, and z)

void setup()
{
  Serial.begin(9600);
  Serial.println("MLX90393 Read Example");
  Wire.begin();
  //Connect to sensor with I2C address jumpers set: A1 = 1, A0 = 0
  //Use DRDY pin connected to A3
  //Returns byte containing status bytes
  byte status = mlx.begin(1, 0, A3);
  delay(2000);

  //Report status from configuration
  Serial.print("Start status: 0x");
  if(status < 0x10) Serial.print("0"); //Pretty output
  Serial.println(status, BIN);
  
  mlx.setGainSel(1);
  mlx.setResolution(0, 0, 0); //x, y, z
  mlx.setOverSampling(0);
  mlx.setDigitalFiltering(0);
  //See MLX90393.h and .cpp for additional functions including:
  //set/getOverSample, set/getTemperatureOverSample, set/getDigitalFiltering, set/getResolution
  //set/getTemperatureCompensation, setOffsets, setWThresholds
}

void loop()
{
  mlx.readData(data); //Read the values from the sensor

  Serial.print("magX[");
  Serial.print(data.x);
  Serial.print("] magY[");
  Serial.print(data.y);
  Serial.print("] magZ[");
  Serial.print(data.z);
  Serial.print("] temperature(C)[");
  Serial.print(data.t);
  //Serial.print("] status[");
  //Serial.print(status);
  Serial.print("]");

  Serial.println();

  delay(100);
}

I use an Arduino Leonardo and a breakout module for the MLX90393.

But all I get in the serial monitor is "Start status: 0x11111111" and then nothing else happens
or if I just take out the sensor module of the breadboard I get unrealistic high values (440°C at room temperature).
That tells me that the sensor is doing something but that it is unable to execute the main loop or is getting stuck in the setup.

I would be really happy if anyone could help me here because I don't know what is the error here.

Pictures below for circuit:



Sensor is powered externally by 3.3V

1 Like

EDIT:
Reconnect SDA to the SDA pin and SCL to the SCL pin on the Leonardo but still not working.

Edited the code so I get the line as output were the programm is currently at
and it gets stuck on "mlx.readData(data);" in line 51.

/*
/*

  3.3V = 3.3V
  GND = GND
  SDA = D2
  SCL = D3

*/

#include <Wire.h>
#include <MLX90393.h>

MLX90393 mlx;
MLX90393::txyz data; //Create a structure, called data, of four floats (t, x, y, and z)

void setup()
{
  Serial.begin(9600);
  Serial.println("19");
  Serial.println("MLX90393 Read Example");
  Serial.println("21");
  Wire.begin();
  Serial.println("23");
  //Connect to sensor with I2C address jumpers set: A1 = 1, A0 = 0
  //Use DRDY pin connected to A3
  //Returns byte containing status bytes
  byte status = mlx.begin(1, 0, A3);
  Serial.println("28");
  delay(2000);
  Serial.println("30");

  //Report status from configuration
  Serial.print("Start status: 0x");
  if (status < 0x10) Serial.print("0"); //Pretty output
  Serial.println(status, BIN);
  Serial.println("36");

  mlx.setGainSel(1);
  mlx.setResolution(0, 0, 0); //x, y, z
  mlx.setOverSampling(0);
  mlx.setDigitalFiltering(0);
  Serial.println("42");
  //See MLX90393.h and .cpp for additional functions including:
  //set/getOverSample, set/getTemperatureOverSample, set/getDigitalFiltering, set/getResolution
  //set/getTemperatureCompensation, setOffsets, setWThresholds
}

void loop()
{
  Serial.println("50");
  mlx.readData(data); //Read the values from the sensor
  Serial.println("52");
  Serial.print("magX[");
  Serial.println("54");
  Serial.print(data.x);
  Serial.println("56");
  Serial.print("] magY[");
  Serial.println("58");
  Serial.print(data.y);
  Serial.println("60");
  Serial.print("] magZ[");
  Serial.println("62");
  Serial.print(data.z);
  Serial.println("64");
  Serial.print("] temperature(C)[");
  Serial.println("66");
  Serial.print(data.t);
  Serial.println("68");
  //Serial.print("] status[");
  //Serial.print(status);
  Serial.print("]");
  Serial.println("72");

  Serial.println();

  delay(100);
}

What could be the reason that the arduino is unable to read the data?

Don't cross post! I already answered in your other thread.