npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-bmm150

v1.2.0

Published

Node JS package for the BMM150 magnetometer unit using I2C

Downloads

1

Readme

node-BMM150

Node JS package for the BMM150 magnetometer unit using I2C

BMM150 Class Documentation

Constructor

constructor(busNumber = 1, address = 0x13)
  • busNumber: The I2C bus number (default is 1).
  • address: The I2C address of the BMM150 sensor (default is 0x13).

Methods

initialize()

Initializes the sensor by setting the power on, reading the chip ID, and setting the operation mode to normal.

async initialize()
setPower(enabled)

Enables or disables the power.

setPower(enabled)
  • enabled: true to enable power, false to disable power.
setOperationMode(mode)

Sets the operation mode of the sensor.

setOperationMode(mode)
  • mode: Operation mode (e.g., BMM150.OP_MODE_NORMAL).
setPresetMode(mode)

Sets the preset mode for the sensor.

setPresetMode(mode)
  • mode: Preset mode (e.g., BMM150.PRESETMODE_HIGHACCURACY).
setRate(rate)

Sets the data rate for the sensor.

setRate(rate)
  • rate: Data rate (e.g., BMM150.RATE_10HZ).
setMeasurementXYZ()

Enables measurement on the X, Y, and Z axes.

setMeasurementXYZ()
readMagnetometerData()

Reads the raw magnetometer data from the sensor.

readMagnetometerData()
  • Returns an object with x, y, and z properties representing the raw data.
getGeomagnetic()

Gets the compensated geomagnetic data.

getGeomagnetic()
  • Returns an object with x, y, and z properties in microteslas (µT).
getCompassDegree()

Gets the compass degree based on geomagnetic data.

getCompassDegree()
  • Returns the degree value indicating the angle between the pointing direction and north.
streamLiveData(rate)

Streams live data from the sensor at the specified rate.

async streamLiveData(rate = 100)
  • rate: The interval rate in milliseconds (default is 100ms).
stopStream()

Stops the live data stream.

stopStream()

Example Usage

Here’s how to use the different methods to get raw data, geomagnetic data, and compass degree.

Example Script

const BMM150 = require('./path/to/bmm150');

(async () => {
    try {
        const bmm150 = new BMM150(1, 0x13); // Specify the I2C bus and address
        await bmm150.initialize();
        console.log('BMM150 initialized successfully');

        // Setup sensor configuration
        bmm150.setOperationMode(BMM150.OP_MODE_NORMAL);
        bmm150.setPresetMode(BMM150.PRESETMODE_HIGHACCURACY);
        bmm150.setRate(BMM150.RATE_10HZ);
        bmm150.setMeasurementXYZ();

        // Get raw data
        const rawData = bmm150.readMagnetometerData();
        console.log(`Raw Magnetometer Data: X=${rawData.x}, Y=${rawData.y}, Z=${rawData.z}`);

        // Get geomagnetic data
        const geomagneticData = bmm150.getGeomagnetic();
        console.log(`Geomagnetic Data: X=${geomagneticData.x} µT, Y=${geomagneticData.y} µT, Z=${geomagneticData.z} µT`);

        // Get compass degree
        const compassDegree = bmm150.getCompassDegree();
        console.log(`Compass Degree: ${compassDegree.toFixed(2)}°`);

        // Stream live data
        bmm150.streamLiveData(100); // Stream data at 10 Hz (100ms interval)

        // Stop streaming after 10 seconds (example)
        setTimeout(() => bmm150.stopStream(), 10000);
    } catch (error) {
        console.error('Error initializing BMM150:', error);
    }
})();

Explanation

  1. Initialization:

    • Initialize the sensor using await bmm150.initialize().
  2. Setup Configuration:

    • Set the sensor to normal operation mode, high accuracy preset mode, and 10 Hz data rate.
    • Enable measurement on the X, Y, and Z axes.
  3. Get Raw Data:

    • Use readMagnetometerData() to get the raw magnetometer data.
  4. Get Geomagnetic Data:

    • Use getGeomagnetic() to get the compensated geomagnetic data in microteslas (µT).
  5. Get Compass Degree:

    • Use getCompassDegree() to get the compass degree.
  6. Stream Live Data:

    • Use streamLiveData(rate) to start streaming live data at the specified rate.
    • Use stopStream() to stop streaming data.

By following this documentation and example usage, you can easily integrate the BMM150 sensor into your Node.js applications and retrieve different types of data as needed.