GY-273 HMC5883L compass with ESP32

Supply 3.3-5 V Bus I2C I2C address 0x1E Measures magnetic field, heading
VCCGNDSCLSDADRDY

Pins and ESP32 wiring

PinRoleESP32 pinNotes
VCCPower3V3
GNDGroundGND
SCLI2C clock (SCL)D22
SDAI2C data (SDA)D21
DRDYInterruptD35Data ready, optional

Suggested wiring for the 30-pin ESP32 DevKit, avoiding flash, input-only and strapping pins. BoardPilot checks it for you as you wire.

Check it is the real chip

Read register 0x0A: a genuine part answers 0x48. BoardPilot does this automatically in “Debug a problem”.

Starter code (Arduino)

#include <Wire.h>

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);  // SDA = GPIO 21, SCL = GPIO 22
  Wire.beginTransmission(0x1E);
  bool found = Wire.endTransmission() == 0;
  Serial.println(found ? "GY-273 HMC5883L compass found at 0x1E" : "Not found: check power, GND and SDA/SCL");
}

void loop() {}

Sources

Try it in 3D in BoardPilot

BoardPilot Part data (JSON)

Related parts

Part data: CC BY 4.0, free to reuse with credit to BoardPilot.