Display the orientation of HMC5883L with ESP32.
I used this I2Cdev library collection by Jeff Rowberg.
First, find the offset value for each axis.
As you can see, each axis is quite off-center.
ESP-IDF V4.4/V5.x.
ESP-IDF V5.0 is required when using ESP32-C2.
ESP-IDF V5.1 is required when using ESP32-C6.
HMC5883L 3-axis Electronic Compass
Note
HMC5883L and QMC5883L are completely incompatible chips.
HMC5883L | ESP32 | ESP32-S2/S3 | ESP32-C2/C3/C6 | ||
---|---|---|---|---|---|
VCC | -- | 3.3V | 3.3V | 3.3V | |
GND | -- | GND | GND | GND | |
SCL | -- | GPIO22 | GPIO12 | GPIO5 | (*1) |
SDA | -- | GPIO21 | GPIO11 | GPIO4 | (*1) |
DRDY | -- | N/C | N/C | N/C |
(*1)You can change it to any pin using menuconfig.
git clone https://github.com/nopnop2002/esp-idf-hmc5883l
cd esp-idf-hmc5883l/calibrate
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash
To find the offset value, set the compass offset to 0.
ESP32 acts as a web server.
I used this component.
This component can communicate directly with the browser.
Enter the following in the address bar of your web browser.
http:://{IP of ESP32}/
or
http://esp32.local/
As you move the compass it plots the X, Y and Z values.
X, Y, Z offset are displayed.
If you set the offset you got from the calibration and run it again, the circle position will change.
git clone https://github.com/nopnop2002/esp-idf-hmc5883l
cd esp-idf-hmc5883l/heading
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash
Sets the compass offset obtained by calibration.
ESP32 acts as a web server.
I used this component.
This component can communicate directly with the browser.
Enter the following in the address bar of your web browser.
http:://{IP of ESP32}/
or
http://esp32.local/
Click the mouse to change the display.
WEB pages are stored in the html folder.
I used this for gauge display.
You can change the design and color according to your preference.