# Memsic MMC56X3 Sensor [](/LICENSE) [](https://visualstudio.microsoft.com) [](https://platformio.org/) [](https://registry.platformio.org/libraries/k0i05/esp_mmc56x3) [](https://components.espressif.com/components/k0i05/esp_mmc56x3) This ESP32 espressif IoT development framework (esp-idf) i2c peripheral driver was developed for the Memsic MMC56X3 3-axis digital compass sensor. Information on features and functionality are documented and can be found in the `mmc56x3.h` header file and in the `documentation` folder. ## Repository The component is hosted on github and is located here: <https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/peripherals/i2c/esp_mmc56x3> ## General Usage To get started, simply copy the component to your project's `components` folder and reference the `mmc56x3.h` header file as an include. The component includes documentation for the peripheral such as the datasheet, application notes, and/or user manual where applicable. ```text components └── esp_mmc56x3 ├── CMakeLists.txt ├── README.md ├── LICENSE ├── idf_component.yml ├── library.json ├── documentation │ └── datasheets, etc. ├── include │ └── mmc56x3_version.h │ └── mmc56x3.h └── mmc56x3.c ``` ## Basic Example Once a driver instance is instantiated the sensor is ready for usage as shown in the below example. This basic implementation of the driver utilizes default configuration settings and makes a measurement request from the sensor at user defined interval and prints the results. ```c #include <mmc56x3.h> void i2c0_mmc56x3_task( void *pvParameters ) { // initialize the xLastWakeTime variable with the current time. TickType_t last_wake_time = xTaskGetTickCount (); // // initialize i2c device configuration mmc56x3_config_t dev_cfg = I2C_MMC56X3_CONFIG_DEFAULT; mmc56x3_handle_t dev_hdl; // // init device mmc56x3_init(i2c0_bus_hdl, &dev_cfg, &dev_hdl); if (dev_hdl == NULL) { ESP_LOGE(APP_TAG, "mmc56x3 handle init failed"); assert(dev_hdl); } // // // task loop entry point for ( ;; ) { ESP_LOGI(APP_TAG, "######################## MMC56X3 - START #########################"); // // handle sensor mmc56x3_magnetic_axes_data_t magnetic_axes; esp_err_t result = mmc56x3_get_magnetic_axes(dev_hdl, &magnetic_axes); if(result != ESP_OK) { ESP_LOGE(APP_TAG, "mmc56x3 device read failed (%s)", esp_err_to_name(result)); } else { ESP_LOGI(APP_TAG, "Compass X-Axis: %f mG", magnetic_axes.x_axis); ESP_LOGI(APP_TAG, "Compass Y-Axis: %f mG", magnetic_axes.y_axis); ESP_LOGI(APP_TAG, "Compass Z-Axis: %f mG", magnetic_axes.z_axis); ESP_LOGI(APP_TAG, "Compass Heading: %f °", mmc56x3_convert_to_heading(magnetic_axes)); ESP_LOGI(APP_TAG, "True Heading: %f °", mmc56x3_convert_to_true_heading(dev_hdl->dev_config.declination, magnetic_axes)); } // ESP_LOGI(APP_TAG, "######################## MMC56X3 - END ###########################"); // // // pause the task per defined wait period vTaskDelaySecUntil( &last_wake_time, I2C0_TASK_SAMPLING_RATE ); } // // free resources mmc56x3_delete( dev_hdl ); vTaskDelete( NULL ); } ``` Copyright (c) 2024 Eric Gionet (<gionet.c.eric@gmail.com>)
idf.py add-dependency "k0i05/esp_mmc56x3^1.1.7"