Hello,
soon I'm going to get Adafruit magnetometer mentioned in the title and I want to set up sampling rate.
I've downloaded MLX90393 library and opened the demo.
In the datasheet - (Overview | MLX90393 Wide-Range 3-Axis Magnetometer | Adafruit Learning System) - it says on page 28 I can set up sampling rate 171.5Hz (Based on OSR=2, DIG_FILT=2, HALLCONF=2x2).
I dont understand where should I put these parameters in the coding.
Also I want to use a high-pass filter using a 2nd order Butterworth filter (cut-off frequency: 1.5 Hz) but that means putting 3 filters on each axes and due to magnetometer there are no 3 pins coming from magnetometer (axes) and connecting to Arduino. I'm looking at this toturial - (Arduino | MLX90393 Wide-Range 3-Axis Magnetometer | Adafruit Learning System) - the only pins coming out of magnetometer to Arduino are SCL and SDA. So 1.5Hz cut off is probably not doable.
I dont understand where should I put these parameters in the coding.
You need to go through the library documentation and/or code, to find a function that sets those parameters. Adafruit's documentation is often pretty good. If there isn't one, you need to use the Wire (I2C) library to write the desired values directly to the device registers.
If you wish to apply a custom filter to the data, that can be done only on the Arduino, after the data have been read. There are on line calculators to give you coefficients or C code for just about any type of filter.
I'm still a beginner in this Arduino field. I successfully completed programming simple projects but I have never tried to change sensor settings in the sketch.
I used the basic getting started demo sketch from the library and inserted the parameters from the library. Can someone take a look and confirm if I did it right? In the upcoming days I will receive the sensor so I haven't tested it yet.
So this is my code:
#ifndef ADAFRUIT_MLX90393_H
#define MLX90393_CONF1 (3x0C) // /**< Gain */ //The MLX90393 has GAIN_SEL=0 and RES=3, for a maximum full-scale range of according to the datasheet.
#define MLX90393_HALL_CONF (2x2C) // /**< Hall plate spinning rate adj. */ //2x2C = 171.5Hz - Based on OSR=2, DIG_FILT=2, HALLCONF=2x2
#include "Arduino.h"
#include <Wire.h>
#include <SPI.h>
#include "Adafruit_MLX90393.h"
Adafruit_MLX90393 sensor = Adafruit_MLX90393();
void setup(void)
{
Serial.begin(9600);
/* Wait for serial on USB platforms. */
while(!Serial) {
delay(10);
}
Serial.println("Starting Adafruit MLX90393 Demo");
if (sensor.begin())
{
Serial.println("Found a MLX90393 sensor");
}
else
{
Serial.println("No sensor found ... check your wiring?");
while (1);
}
}
void loop(void)
{
float x, y, z;
if(sensor.readData(&x, &y, &z)) {
Serial.print("X: "); Serial.print(x, 4); Serial.println(" uT");
Serial.print("Y: "); Serial.print(y, 4); Serial.println(" uT");
Serial.print("Z: "); Serial.print(z, 4); Serial.println(" uT");
} else {
Serial.println("Unable to read XYZ data from the sensor.");
}
delay(500);
}
#endif /* ADAFRUIT_MLX90393_H */
It did compile successfully with the redefined warnings.
This is the message the compiler wrote:
In file included from C:\Users\....\Documents\Arduino\Magnetometer_basicdemo_vaja\Magnetometer_basicdemo_vaja.ino:9:0:
C:\Users\....\Documents\Arduino\libraries\Adafruit_MLX90393/Adafruit_MLX90393.h:28:0: warning: "MLX90393_CONF1" redefined
#define MLX90393_CONF1 (0x00) /**< Gain */
^
C:\Users\.....\Documents\Arduino\Magnetometer_basicdemo_vaja\Magnetometer_basicdemo_vaja.ino:3:0: note: this is the location of the previous definition
#define MLX90393_CONF1 (3x0C) // /**< Gain */ //The MLX90393 has GAIN_SEL=0 and RES=3, for a maximum full-scale range according to the datasheet.
^
In file included from C:\Users\.......\Magnetometer_basicdemo_vaja.ino:9:0:
C:\Users\....\Documents\Arduino\libraries\Adafruit_MLX90393/Adafruit_MLX90393.h:34:0: warning: "MLX90393_HALL_CONF" redefined
#define MLX90393_HALL_CONF (0x0C) /**< Hall plate spinning rate adj. */
^
C:\Users\.....\Arduino\Magnetometer_basicdemo_vaja\Magnetometer_basicdemo_vaja.ino:4:0: note: this is the location of the previous definition
#define MLX90393_HALL_CONF (2x2C) // /**< Hall plate spinning rate adj. */ //2x2C = 171.5Hz - Based on OSR=2, DIG_FILT=2, HALLCONF=2x2
^
Sketch uses 6262 bytes (19%) of program storage space. Maximum is 32256 bytes.
Global variables use 826 bytes (40%) of dynamic memory, leaving 1222 bytes for local variables. Maximum is 2048 bytes.
I don't know if I inserted the parameter correctly for :#define MLX90393_CONF1 (3x0C) or should it be (0x3C), luckily for MLX90393_HALL_CONF it doesn't matter because parameter is (2x2).
Datasheet - page 27
Hey, did it really work?
I'm currently with the same problem, and I can't get past of it...
my setup code below:
#include<Wire.h>
#include <ros.h>
#include <std_msgs/String.h>
// MLX90393 I2C Address is 0x0C(12)
#define Addr 0x0C
void setup() {
// 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);
}