32#if defined(ARDUINO_ARCH_ESP32)
33#include "SH1106Wire.h"
34#ifdef ARDUINO_T_BEAM_S3_SUPREME
35#include <XPowersAXP2101.tpp>
58void arrow(
int x2,
int y2,
int x1,
int y1,
int alength,
int awidth, OLEDDISPLAY_COLOR color)
60 display.setColor(color);
62 int dx, dy, x2o, y2o, x3, y3, x4, y4, k;
63 distance = sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2));
64 dx = x2 + (x1 - x2) * alength / distance;
65 dy = y2 + (y1 - y2) * alength / distance;
73 display.drawLine(x1, y1, x2, y2);
74 display.drawLine(x1, y1, dx, dy);
75 display.drawLine(x3, y3, x4, y4);
76 display.drawLine(x3, y3, x2, y2);
77 display.drawLine(x2, y2, x4, y4);
82#if defined(ARDUINO_T_BEAM_S3_SUPREME)
84 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
88 power.setALDO1Voltage(3300);
90 power.setALDO2Voltage(3300);
109 uint8_t address = QMC6310U_SLAVE_ADDRESS;
114 Serial.println(
"Failed to find QMC6310 - check your wiring!");
120 float data_rate_hz = 200.0f;
136 down_sample_ratio)) {
137 Serial.println(
"Magnetometer configured successfully.");
139 Serial.println(
"Magnetometer configuration failed.");
144 Serial.print(
"Manufacturer: "); Serial.println(info.
manufacturer);
145 Serial.print(
"Model: "); Serial.println(info.
model);
146 Serial.print(
"I2C Address: 0x"); Serial.println(info.
i2c_address, HEX);
147 Serial.print(
"Version: "); Serial.println(info.
version);
148 Serial.print(
"UID: 0x"); Serial.println(info.
uid);
152 Serial.print(
"DataRate: "); Serial.println(cfg.
sample_rate);
153 Serial.print(
"FullScaleRange: "); Serial.println(cfg.
range);
154 Serial.print(
"Mode: "); Serial.println((uint8_t)cfg.
mode);
165 Serial.print(
" Magnetic Declination: ");
166 Serial.print(declination_deg, 2);
169 Serial.print(
" Sensitivity: ");
171 Serial.println(
" Gauss/LSB");
179 static int last_angle = -1;
184 if (angle != last_angle) {
187 display.setFont(ArialMT_Plain_10);
188 display.setTextAlignment(TEXT_ALIGN_CENTER);
189 display.drawString(32, 0,
"N");
190 display.drawString(0, 28,
"W");
191 display.drawString(64, 28,
"E");
192 display.drawString(32, 53,
"S");
194 display.drawCircle(32, 32, 20);
201 int arrow_x = 32 +
static_cast<int>(25 * cosf(arrow_angle_rad));
203 int arrow_y = 32 -
static_cast<int>(25 * sinf(arrow_angle_rad));
205 display.drawLine(32, 32, arrow_x, arrow_y);
206 display.fillCircle(arrow_x, arrow_y, 2);
208 display.setTextAlignment(TEXT_ALIGN_LEFT);
209 display.drawString(75, 5,
"Angle:" + String(angle) +
"°");
212 display.drawString(75, 45,
"Str:" + String(strength, 1) +
"uT");
216 Serial.print(
"Heading: ");
218 Serial.print(
"°, Raw: ");
220 Serial.print(
"°, Declination: ");
233 Serial.begin(115200);
238 Serial.println(
"The graphics library may not be supported on the esp32 platform"); delay(1000);
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
SensorBMM150 magnetometer
bool begin(CommInterface interface, SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback, uint8_t addr=0)
Initialize the sensor using custom callback interface.
virtual float getDeclinationDeg() const
Get the currently set magnetic declination in degrees.
virtual void setDeclination(float declination_deg)
Set the magnetic declination correction value.
bool readData(MagnetometerData &data) override
Read one magnetometer sample.
bool configMagnetometer(OperationMode mode, MagFullScaleRange range, float odr, MagOverSampleRatio osr, MagDownSampleRatio dsr=MagDownSampleRatio::DSR_1) override
Apply combined magnetometer configuration.
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.
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.
Structure representing magnetometer data.
float heading_degrees
heading angle (degrees)
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.