When you run a program that uses this function in a browser, click and drag the compass needle on the screen to change the compass heading.
compass Heading
Find which direction on a compass the Calliope mini is facing.
The Calliope mini measures the compass heading from 0 to 359
degrees with its magnetometer chip. Different numbers mean North,
East, South, and West.
input.compassHeading()
Returns
- a number from
0to359degrees, which means the compass heading. If the compass isn’t ready, it returns-1003.
Compass points
In history, a compass was a device that pointed in the direction of the magnetic North Pole. A needle or or a spot on a moving dial was magnetically attracted to the pole. Using a circular card or diagram arranged with direction indications you could align the indicator with the mark that meant “North” and see which direction the heading you wanted was in.

Magnetic compass
by Evan Amos, Public Domain
Examples
Digital compass
Display the current compass heading in degrees 0 - 359.
basic.forever(function () {
basic.showNumber(input.compassHeading())
basic.pause(1000)
})
Analog compass
Find the compass heading and then show an arrow that means whether the Calliope mini is facing north (🠉), south (🠋), east (🠊), or west (🠈).
let degrees = 0
basic.forever(() => {
degrees = input.compassHeading()
if (degrees < 45) {
basic.showIcon(IconNames.ArrowNorth)
} else if (degrees < 135) {
basic.showIcon(IconNames.ArrowEast)
} else if (degrees < 225) {
basic.showIcon(IconNames.ArrowSouth)
} else if (degrees < 315) {
basic.showIcon(IconNames.ArrowWest)
} else {
basic.showIcon(IconNames.ArrowNorth)
}
})
Calibration
Every time you start to use the compass (for example, if you have just turned the Calliope mini on), the Calliope mini will start a calibrate compass (adjust itself). The calibration step will ask you to draw a fill pattern on the screen by tilting the Calliope mini.
If you are calibrating or using the compass near metal, it might confuse the Calliope mini.