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 <noreply@anthropic.com>
This commit is contained in:
Limor Fried 2025-07-18 17:24:41 -04:00
commit d0a569be1e
10 changed files with 269 additions and 0 deletions

13
.clang-format Normal file
View file

@ -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

32
.github/workflows/githubci.yml vendored Normal file
View file

@ -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

25
.gitignore vendored Normal file
View file

@ -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

70
Adafruit_QMC5883P.cpp Normal file
View file

@ -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;
}

61
Adafruit_QMC5883P.h Normal file
View file

@ -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 <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
/*=========================================================================
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

View file

34
README.md Normal file
View file

@ -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)
<a href="https://www.adafruit.com/products/"><img src="assets/board.jpg?raw=true" width="500px"><br/></a>
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.

View file

@ -0,0 +1,27 @@
/*
* QMC5883P Test Sketch
*
* Basic test for the QMC5883P 3-axis magnetometer
*/
#include <Adafruit_QMC5883P.h>
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);
}

6
package-lock.json generated Normal file
View file

@ -0,0 +1,6 @@
{
"name": "Adafruit_QMC5883P",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}

1
package.json Normal file
View file

@ -0,0 +1 @@
{}