31#ifdef ARDUINO_T_BEAM_S3_SUPREME
32#include <XPowersAXP2101.tpp>
47#if defined(ARDUINO_T_BEAM_S3_SUPREME)
49 power.
begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
53 power.setALDO1Voltage(3300);
55 power.setALDO2Voltage(3300);
63 Serial.println(
"Failed to set output data rate");
67 Serial.println(
"========================================");
68 Serial.println(
"Calibration Instructions:");
69 Serial.println(
"1. Rotate sensor in FIGURE-8 pattern");
70 Serial.println(
"2. Cover all axes (X, Y, Z directions)");
71 Serial.println(
"3. Rotate slowly and completely");
72 Serial.println(
"4. Wait for progress bar to complete");
73 Serial.println(
"5. Expected: Magnetic Strength ~25-65 uT");
74 Serial.println(
"========================================");
77 Serial.println(
"Place the sensor on the plane and slowly rotate the sensor...");
78 Serial.println(
"Rotate in FIGURE-8 pattern to cover all directions!");
81 int32_t x_min = 65535;
82 int32_t x_max = -65535;
83 int32_t y_min = 65535;
84 int32_t y_max = -65535;
85 int32_t z_min = 65535;
86 int32_t z_max = -65535;
90 int32_t
x = 0,
y = 0, z = 0;;
105 z = (data.
raw.
z + z) / 2;
130 int j = round(10 *
i / range);
133 for (
int k = 0; k < j; ++k) {
141 x_offset = (x_max + x_min) / 2;
142 y_offset = (y_max + y_min) / 2;
143 z_offset = (z_max + z_min) / 2;
145 Serial.print(
"x_min:");
146 Serial.println(x_min);
148 Serial.print(
"x_max:");
149 Serial.println(x_max);
151 Serial.print(
"y_min:");
152 Serial.println(y_min);
154 Serial.print(
"y_max:");
155 Serial.println(y_max);
157 Serial.print(
"z_min:");
158 Serial.println(z_min);
160 Serial.print(
"z_max:");
161 Serial.println(z_max);
163 Serial.print(
"x_offset:");
164 Serial.println(x_offset);
166 Serial.print(
"y_offset:");
167 Serial.println(y_offset);
169 Serial.print(
"z_offset:");
170 Serial.println(z_offset);
177 Serial.println(
"Calibration complete!");
178 Serial.println(
"Check if Magnetic Strength is ~25-65 uT");
179 Serial.println(
"If too low, repeat calibration with better rotation");
185 Serial.begin(115200);
197 uint8_t address = QMC6310U_SLAVE_ADDRESS;
202 Serial.println(
"Failed to find QMC6310 - check your wiring!");
208 float data_rate_hz = 200.0f;
224 down_sample_ratio)) {
225 Serial.println(
"Magnetometer configured successfully.");
227 Serial.println(
"Magnetometer configuration failed.");
235 Serial.println(
"Calibration done.");
239 Serial.print(
"Manufacturer: "); Serial.println(info.
manufacturer);
240 Serial.print(
"Model: "); Serial.println(info.
model);
241 Serial.print(
"I2C Address: 0x"); Serial.println(info.
i2c_address, HEX);
242 Serial.print(
"Version: "); Serial.println(info.
version);
243 Serial.print(
"UID: 0x"); Serial.println(info.
uid);
247 Serial.print(
"DataRate: "); Serial.println(cfg.
sample_rate);
248 Serial.print(
"FullScaleRange: "); Serial.println(cfg.
range);
249 Serial.print(
"Mode: "); Serial.println((uint8_t)cfg.
mode);
257 Serial.print(
" Magnetic Declination: ");
258 Serial.print(declination_deg, 2);
261 Serial.print(
" Sensitivity: ");
263 Serial.println(
" Gauss/LSB");
267 Serial.println(
"Read data now...");
281 Serial.print(
"Mag:");
282 Serial.print(
" X:"); Serial.print(
x);
283 Serial.print(
" Y:"); Serial.print(
y);
284 Serial.print(
" Z:"); Serial.print(z);
287 Serial.print(
" Sensitivity: ");
289 Serial.print(
" Gauss/LSB");
291 Serial.print(
" Metadata:");
293 Serial.print(data.
raw.
x);
295 Serial.print(data.
raw.
y);
297 Serial.print(data.
raw.
z);
299 Serial.print(
" Heading (rad): ");
301 Serial.print(
" rad");
303 Serial.print(
" Heading (deg): ");
309 Serial.print(
" Magnetic Strength: ");
310 Serial.print(strength, 2);
311 Serial.println(
" μT");
314 Serial.println(
"\tWarning: Data Overflow occurred!");
OperationMode
Enumeration of sensor operation modes.
MagFullScaleRange
Enumeration defining full-scale range settings for the sensor.
MagDownSampleRatio
Enumeration defining down-sample ratios for the sensor.
@ DSR_1
1x down-sample ratio
MagOverSampleRatio
Enumeration defining over-sample ratios for the sensor.
@ OSR_1
1x over-sample ratio
bool begin(SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialize the sensor using custom callback interface.
virtual void setDeclination(float declination_deg)
Set the magnetic declination correction value.
void setOffset(int16_t x, int16_t y, int16_t z)
Set sensor calibration offsets.
virtual SensorConfig getConfig() const
Get current sensor configuration.
float getSensitivity() const
Get sensor sensitivity.
SensorInfo getSensorInfo() const
Get sensor information.
bool setOutputDataRate(float odr) override
Sets the output data rate for the magnetometer.
bool isDataReady() override
Checks if new data is available from the sensor.
bool configMagnetometer(OperationMode mode, MagFullScaleRange range, float odr, MagOverSampleRatio osr, MagDownSampleRatio dsr) override
Configures the magnetometer with multiple parameters.
bool readData(MagnetometerData &data) override
Reads the magnetic field data from the sensor.
static const char * typeToString(SensorType type)
Convert sensor type enumeration to string representation.
float dmsToDecimalDegrees(int degrees, int minutes, float seconds=0.0f)
Convert degrees-minutes-seconds to decimal degrees.
float calculateMagneticStrength(const MagnetometerData &data)
Calculate total magnetic field strength.
float gaussToMicroTesla(float gauss)
Converts Gauss to microTesla.
SensorQMC6310 magnetometer
Structure representing magnetometer data.
float heading_degrees
heading angle (degrees)
float heading
heading angle (radians)
SensorVector magnetic_field
magnetic field strength (Gauss)
bool overflow
data overflow flag
int16_t x
X-axis raw value.
int16_t y
Y-axis raw value.
int16_t z
Z-axis raw value.
Structure representing sensor configuration parameters.
float sample_rate
Sample rate in Hz.
float range
Measurement range.
OperationMode mode
Operation mode.
Structure containing sensor identification information.
uint8_t version
Hardware/firmware version.
uint8_t i2c_address
Default I2C address.
uint32_t uid
Unique identifier.
SensorType type
Sensor type.
const char * manufacturer
Manufacturer name.
const char * model
Model name/identifier.