Overview
The compass_bn880 node interfaces with the BN-880 module, a dual-purpose
board combining a u-blox GPS receiver with a QMC5883L 3-axis magnetic compass. This provides both geographic
position and magnetic heading in a single module. The compass data is read via I2C while the GPS data comes
through UART, giving you latitude, longitude, altitude, magnetic heading, pitch, roll, and field strength.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| i2cBus | select | /dev/i2c-1 | I2C bus for compass (QMC5883L) |
| compassAddress | string | 0x0d | I2C address of the QMC5883L compass |
| serialPort | string | /dev/ttyS0 | Serial port for GPS data |
| baudRate | select | 9600 | GPS serial baud rate. Options: 9600, 19200, 38400 |
| outputRate | select | 10Hz | Compass output data rate. Options: 10Hz, 50Hz, 100Hz, 200Hz |
| range | select | 8G | Magnetic field range. Options: 2G (higher sensitivity), 8G (wider range) |
| oversampling | select | 512 | Oversampling ratio. Options: 64, 128, 256, 512. Higher = smoother but slower |
| declinationAngle | number | 0 | Magnetic declination angle in degrees for true north correction |
Output
{
"latitude": 51.5074,
"longitude": -0.1278,
"altitude": 11.2,
"heading": 247.5,
"pitch": 2.3,
"roll": -1.1,
"magneticField": {
"x": 0.182,
"y": -0.054,
"z": 0.423
},
"declination": -0.8,
"timestamp": 1640000000000
} Wiring (I2C + UART)
Connection
VCC → 3.3V or 5V
GND → GND
SDA → GPIO 2 (Pin 3) - Compass I2C
SCL → GPIO 3 (Pin 5) - Compass I2C
TX → GPIO 15 (Pin 10) - GPS UART
RX → GPIO 14 (Pin 8) - GPS UART
ASCII Wiring Diagram
BN-880 Raspberry Pi
------ ------------
VCC ──────────── 3.3V (Pin 1)
GND ──────────── GND (Pin 6)
SDA ──────────── SDA (Pin 3 / GPIO 2)
SCL ──────────── SCL (Pin 5 / GPIO 3)
TX ──────────── RXD (Pin 10 / GPIO 15)
RX ──────────── TXD (Pin 8 / GPIO 14)
Note: SDA/SCL = compass (I2C)
TX/RX = GPS (UART) Example: Drone Heading and Navigation
Combine GPS position with magnetic heading for drone autopilot navigation and waypoint tracking.
// Function node: Navigate to waypoint
var lat = msg.latitude;
var lon = msg.longitude;
var heading = msg.heading;
// Target waypoint
var targetLat = 51.5080;
var targetLon = -0.1260;
// Calculate bearing to target
var dLon = (targetLon - lon) * Math.PI / 180;
var lat1 = lat * Math.PI / 180;
var lat2 = targetLat * Math.PI / 180;
var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1) * Math.sin(lat2) -
Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
var bearing = (Math.atan2(y, x) * 180 / Math.PI + 360) % 360;
// Calculate turn needed
var turn = bearing - heading;
if (turn > 180) turn -= 360;
if (turn < -180) turn += 360;
// Distance to waypoint
var R = 6371000;
var dLat = (targetLat - lat) * Math.PI / 180;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1) * Math.cos(lat2) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var distance = R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
msg.payload = {
position: { lat: lat, lon: lon },
heading: heading,
bearingToTarget: bearing.toFixed(1),
turnAngle: turn.toFixed(1),
distanceToTarget: distance.toFixed(1),
arrived: distance < 5
};
return msg; Example: Compass Calibration Check
Monitor magnetic field consistency to detect when the compass needs recalibration due to magnetic interference.
// Function node: Calibration quality monitor
var mag = msg.magneticField;
var fieldStrength = Math.sqrt(
mag.x * mag.x + mag.y * mag.y + mag.z * mag.z
);
var readings = flow.get('magReadings') || [];
readings.push(fieldStrength);
if (readings.length > 100) readings.shift();
flow.set('magReadings', readings);
// Calculate variance
var sum = readings.reduce(function(a, b) { return a + b; }, 0);
var mean = sum / readings.length;
var variance = readings.reduce(function(acc, val) {
return acc + Math.pow(val - mean, 2);
}, 0) / readings.length;
var quality = "good";
if (variance > 0.05) quality = "needs_calibration";
else if (variance > 0.02) quality = "moderate";
msg.payload = {
heading: msg.heading,
fieldStrength: fieldStrength.toFixed(4),
variance: variance.toFixed(6),
quality: quality,
samples: readings.length
};
return msg; Common Use Cases
Drone Autopilot
Combined GPS waypoint navigation with magnetic heading for UAV flight control
Robot Navigation
Heading-aware outdoor navigation for autonomous ground vehicles and rovers
Weather Vane
Digital compass heading for wind direction measurement in weather stations
Antenna Pointing
Satellite dish or antenna alignment using combined position and heading data