Skip to content

nopnop2002/esp-idf-hmc5883l

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esp-idf-hmc5883l

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.
hmc5883l-calib-1

And display the orientation.
hmc5883l-heading-1

Software requiment

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.

Hardware requirements

HMC5883L 3-axis Electronic Compass

Note
HMC5883L and QMC5883L are completely incompatible chips.

Wireing

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.

Caribration

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

Configuration

To find the offset value, set the compass offset to 0.
config-top config-app

Execute 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/

As you move the compass it plots the X, Y and Z values.
X, Y, Z offset are displayed.

hmc5883l-calib-1

Execute calibration again

If you set the offset you got from the calibration and run it again, the circle position will change.

hmc5883l-calib-2

Display the orientation

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

Configuration

Sets the compass offset obtained by calibration.
config-top config-app

View orientation

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.
hmc5883l-heading-1 hmc5883l-heading-2

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.