commit d0a569be1e8ff811b2179132428b27fdd58df139 Author: Limor Fried Date: Fri Jul 18 17:24:41 2025 -0400 Initial commit: Add basic QMC5883P library - Add core library files (Adafruit_QMC5883P.h/.cpp) - Add basic example sketch with chip detection - Add standard Adafruit project files (.clang-format, README.md, GitHub workflows) - Library successfully tests I2C communication and chip ID verification 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ed70f56 --- /dev/null +++ b/.clang-format @@ -0,0 +1,13 @@ +Language: Cpp +BasedOnStyle: Google +IndentWidth: 2 +ColumnLimit: 80 +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +BinPackArguments: true +BinPackParameters: true +BreakBeforeBraces: Attach +DerivePointerAlignment: false +PointerAlignment: Left +SpacesBeforeTrailingComments: 1 \ No newline at end of file diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml new file mode 100644 index 0000000..720aed4 --- /dev/null +++ b/.github/workflows/githubci.yml @@ -0,0 +1,32 @@ +name: Arduino Library CI + +on: [pull_request, push, repository_dispatch] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-python@v1 + with: + python-version: '3.x' + - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + with: + repository: adafruit/ci-arduino + path: ci + + - name: pre-install + run: bash ci/actions_install.sh + + - name: clang + run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . + + - name: test platforms + run: python3 ci/build_platform.py main_platforms + + - name: doxygen + env: + GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} + PRETTYNAME : "Adafruit QMC5883P Arduino Library" + run: bash ci/doxy_gen_and_deploy.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc24d87 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Datasheets +*.pdf +*.txt + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# IDE files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# Build artifacts +build/ +bin/ +*.o +*.a \ No newline at end of file diff --git a/Adafruit_QMC5883P.cpp b/Adafruit_QMC5883P.cpp new file mode 100644 index 0000000..abc162a --- /dev/null +++ b/Adafruit_QMC5883P.cpp @@ -0,0 +1,70 @@ +/*! + * @file Adafruit_QMC5883P.cpp + * + * @mainpage Adafruit QMC5883P 3-axis magnetometer library + * + * @section intro_sec Introduction + * + * This is a library for the QMC5883P 3-axis magnetometer + * + * These sensors use I2C to communicate, 2 pins (SCL+SDA) are required + * to interface with the breakout. + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * @section author Author + * + * Written by ladyada for Adafruit Industries. + * + * @section license License + * + * MIT license, all text here must be included in any redistribution. + * + */ + +#include "Adafruit_QMC5883P.h" + +/*! + * @brief Instantiates a new QMC5883P class + */ +Adafruit_QMC5883P::Adafruit_QMC5883P(void) { i2c_dev = NULL; } + +/*! + * @brief Cleans up the QMC5883P + */ +Adafruit_QMC5883P::~Adafruit_QMC5883P(void) { + if (i2c_dev) { + delete i2c_dev; + } +} + +/*! + * @brief Sets up the hardware and initializes I2C + * @param i2c_addr + * The I2C address to be used. + * @param wire + * The Wire object to be used for I2C connections. + * @return True if initialization was successful, otherwise false. + */ +bool Adafruit_QMC5883P::begin(uint8_t i2c_addr, TwoWire *wire) { + if (i2c_dev) { + delete i2c_dev; + } + + i2c_dev = new Adafruit_I2CDevice(i2c_addr, wire); + + if (!i2c_dev->begin()) { + return false; + } + + // Check chip ID + Adafruit_BusIO_Register chip_id_reg = Adafruit_BusIO_Register(i2c_dev, QMC5883P_REG_CHIPID); + uint8_t chip_id = chip_id_reg.read(); + if (chip_id != 0x80) { + return false; + } + + return true; +} \ No newline at end of file diff --git a/Adafruit_QMC5883P.h b/Adafruit_QMC5883P.h new file mode 100644 index 0000000..59e7f73 --- /dev/null +++ b/Adafruit_QMC5883P.h @@ -0,0 +1,61 @@ +/*! + * @file Adafruit_QMC5883P.h + * + * This is a library for the QMC5883P 3-axis magnetometer + * + * These sensors use I2C to communicate, 2 pins (SCL+SDA) are required + * to interface with the breakout. + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Written by ladyada for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * + */ + +#ifndef _ADAFRUIT_QMC5883P_H_ +#define _ADAFRUIT_QMC5883P_H_ + +#include "Arduino.h" +#include +#include + +/*========================================================================= + I2C ADDRESS/BITS + -----------------------------------------------------------------------*/ +#define QMC5883P_DEFAULT_ADDR 0x2C ///< Default I2C address +/*=========================================================================*/ + +/*========================================================================= + REGISTERS + -----------------------------------------------------------------------*/ +#define QMC5883P_REG_CHIPID 0x00 ///< Chip ID register +#define QMC5883P_REG_XOUT_LSB 0x01 ///< X-axis output LSB register +#define QMC5883P_REG_XOUT_MSB 0x02 ///< X-axis output MSB register +#define QMC5883P_REG_YOUT_LSB 0x03 ///< Y-axis output LSB register +#define QMC5883P_REG_YOUT_MSB 0x04 ///< Y-axis output MSB register +#define QMC5883P_REG_ZOUT_LSB 0x05 ///< Z-axis output LSB register +#define QMC5883P_REG_ZOUT_MSB 0x06 ///< Z-axis output MSB register +#define QMC5883P_REG_STATUS 0x09 ///< Status register +#define QMC5883P_REG_CONTROL1 0x0A ///< Control register 1 +#define QMC5883P_REG_CONTROL2 0x0B ///< Control register 2 +/*=========================================================================*/ + +/*! + * @brief Class for hardware interfacing with the QMC5883P 3-axis magnetometer + */ +class Adafruit_QMC5883P { +public: + Adafruit_QMC5883P(void); + ~Adafruit_QMC5883P(void); + + bool begin(uint8_t i2c_addr = QMC5883P_DEFAULT_ADDR, TwoWire *wire = &Wire); + +private: + Adafruit_I2CDevice *i2c_dev; ///< Pointer to I2C bus interface +}; + +#endif \ No newline at end of file diff --git a/QMC5883P.pdf:Zone.Identifier b/QMC5883P.pdf:Zone.Identifier new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..ce42ce3 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# Adafruit QMC5883P Library [![Build Status](https://github.com/adafruit/Adafruit_QMC5883P/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_QMC5883P/actions) + +
+ +This is a library for the QMC5883P 3-axis magnetometer + +## Features + +- 3-axis magnetic field sensing +- 16-bit resolution +- I2C interface +- Multiple full-scale ranges (±2G, ±8G, ±12G, ±30G) +- Built-in self-test capability +- Temperature compensation + +## Installation + +To install, use the Arduino Library Manager and search for "Adafruit QMC5883P" and install the library. + +## Dependencies + +This library depends on the [Adafruit BusIO library](https://github.com/adafruit/Adafruit_BusIO) + +## Hardware + +The QMC5883P is a 3-axis magnetometer with I2C interface. It requires a 3.3V or 5V power supply. + +## Contributing + +Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit_QMC5883P/blob/master/CODE_OF_CONDUCT.md) before contributing to help this project stay welcoming. + +## License + +MIT license, all text above must be included in any redistribution. See license.txt for more information. \ No newline at end of file diff --git a/examples/test_QMC5883P/test_QMC5883P.ino b/examples/test_QMC5883P/test_QMC5883P.ino new file mode 100644 index 0000000..d4f658a --- /dev/null +++ b/examples/test_QMC5883P/test_QMC5883P.ino @@ -0,0 +1,27 @@ +/* + * QMC5883P Test Sketch + * + * Basic test for the QMC5883P 3-axis magnetometer + */ + +#include + +Adafruit_QMC5883P qmc; + +void setup() { + Serial.begin(115200); + while (!Serial) delay(10); + + Serial.println("QMC5883P Test"); + + if (!qmc.begin()) { + Serial.println("Failed to find QMC5883P chip"); + while (1) delay(10); + } + + Serial.println("QMC5883P Found!"); +} + +void loop() { + delay(1000); +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..043bb30 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "Adafruit_QMC5883P", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/package.json @@ -0,0 +1 @@ +{}