33#ifdef ARDUINO_T_BEAM_S3_SUPREME
34#include <XPowersAXP2101.tpp>
48#if defined(ARDUINO_T_BEAM_S3_SUPREME)
54#if defined(ARDUINO_T_BEAM_S3_SUPREME)
56 SensorWireHelper::dumpDevices(Wire);
57 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
61 power.setALDO1Voltage(3300);
63 power.setALDO2Voltage(3300);
65 power.setChargingLedMode(XPOWERS_CHG_LED_OFF);
73 float data_rate_hz = 200.0f;
93 Serial.println(
"Failed to find QMC6310U - check your wiring!");
97 Serial.println(
"QMC6310U found!");
99 data_rate_hz = 200.0f;
114 Serial.println(
"Failed to find QMC6310 - check your wiring!");
118 Serial.println(
"QMC6310N found!");
120 data_rate_hz = 200.0f;
135 Serial.println(
"Failed to find QMC6309 - check your wiring!");
139 Serial.println(
"QMC6309 found!");
141 data_rate_hz = 200.0f;
154 Serial.println(
"No magnetometer found!");
164 down_sample_ratio)) {
165 Serial.println(
"Magnetometer configured successfully.");
167 Serial.println(
"Magnetometer configuration failed.");
175 Serial.println(
"Calibration done.");
181 Serial.print(
"Manufacturer: "); Serial.println(info.
manufacturer);
182 Serial.print(
"Model: "); Serial.println(info.
model);
183 Serial.print(
"I2C Address: 0x"); Serial.println(info.
i2c_address, HEX);
184 Serial.print(
"Version: "); Serial.println(info.
version);
185 Serial.print(
"UID: 0x"); Serial.println(info.
uid);
189 Serial.print(
"DataRate: "); Serial.println(cfg.
sample_rate);
190 Serial.print(
"FullScaleRange: "); Serial.println(cfg.
range);
191 Serial.print(
"Mode: "); Serial.println((uint8_t)cfg.
mode);
199 Serial.print(
" Magnetic Declination: ");
200 Serial.print(declination_deg, 2);
203 Serial.print(
" Sensitivity: ");
205 Serial.println(
" Gauss/LSB");
209 Serial.println(
"Read data now...");
224 Serial.print(
"Mag:");
225 Serial.print(
" X:"); Serial.print(
x);
226 Serial.print(
" Y:"); Serial.print(
y);
227 Serial.print(
" Z:"); Serial.print(z);
230 Serial.print(
" Metadata:");
232 Serial.print(data.
raw.
x);
234 Serial.print(data.
raw.
y);
236 Serial.print(data.
raw.
z);
238 Serial.print(
" Heading (rad): ");
240 Serial.print(
" rad");
242 Serial.print(
" Heading (deg): ");
248 Serial.print(
" Magnetic Strength: ");
249 Serial.print(strength, 2);
250 Serial.println(
" μT");
253 Serial.println(
"\tWarning: Data Overflow occurred!");
265 Serial.println(
"Failed to set output data rate");
269 Serial.println(
"========================================");
270 Serial.println(
"Calibration Instructions:");
271 Serial.println(
"1. Rotate sensor in FIGURE-8 pattern");
272 Serial.println(
"2. Cover all axes (X, Y, Z directions)");
273 Serial.println(
"3. Rotate slowly and completely");
274 Serial.println(
"4. Wait for progress bar to complete");
275 Serial.println(
"5. Expected: Magnetic Strength ~25-65 uT");
276 Serial.println(
"========================================");
279 Serial.println(
"Place the sensor on the plane and slowly rotate the sensor...");
280 Serial.println(
"Rotate in FIGURE-8 pattern to cover all directions!");
281 Serial.println(
"If the heading angle does not change with the direction, please rerun the calibration until it is normal.");
286#if defined(ARDUINO_T_BEAM_S3_SUPREME)
287 power.setChargingLedMode(XPOWERS_CHG_LED_BLINK_4HZ);
290 int32_t x_min = 65535;
291 int32_t x_max = -65535;
292 int32_t y_min = 65535;
293 int32_t y_max = -65535;
294 int32_t z_min = 65535;
295 int32_t z_max = -65535;
297 int32_t range = 1000;
299 int32_t
x = 0,
y = 0, z = 0;
300 int16_t x_offset = 0;
301 int16_t y_offset = 0;
302 int16_t z_offset = 0;
314 z = (data.
raw.
z + z) / 2;
339 int j = round(10 *
i / range);
342 for (
int k = 0; k < j; ++k) {
350 x_offset = (x_max + x_min) / 2;
351 y_offset = (y_max + y_min) / 2;
352 z_offset = (z_max + z_min) / 2;
354 Serial.print(
"x_min:");
355 Serial.println(x_min);
357 Serial.print(
"x_max:");
358 Serial.println(x_max);
360 Serial.print(
"y_min:");
361 Serial.println(y_min);
363 Serial.print(
"y_max:");
364 Serial.println(y_max);
366 Serial.print(
"z_min:");
367 Serial.println(z_min);
369 Serial.print(
"z_max:");
370 Serial.println(z_max);
372 Serial.print(
"x_offset:");
373 Serial.println(x_offset);
375 Serial.print(
"y_offset:");
376 Serial.println(y_offset);
378 Serial.print(
"z_offset:");
379 Serial.println(z_offset);
386 Serial.println(
"Calibration complete!");
387 Serial.println(
"Check if Magnetic Strength is ~25-65 uT");
388 Serial.println(
"If too low, repeat calibration with better rotation");
390#if defined(ARDUINO_T_BEAM_S3_SUPREME)
391 power.setChargingLedMode(XPOWERS_CHG_LED_ON);
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
virtual bool setOutputDataRate(float odr)=0
Sets the output data rate for the magnetometer.
bool readData(MagnetometerData &data) override=0
Checks if new data is available from the magnetometer.
virtual bool configMagnetometer(OperationMode mode, MagFullScaleRange range, float data_rate_hz, MagOverSampleRatio osr, MagDownSampleRatio dsr)=0
Configures the magnetometer with the specified settings.
virtual void setDeclination(float declination_deg)
Set the magnetic declination correction value.
bool isDataReady() override=0
Checks if new data is available from the magnetometer.
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.
static const char * typeToString(SensorType type)
Convert sensor type enumeration to string representation.
MagnetometerBase * magnetometer
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.
SensorQSTMagnetic SensorQMC6310
Typedef to create an alias for SensorQSTMagnetic specifically for QMC6310 compatibility.
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.