Compass Heading

Find which direction on a compass the Calliope mini is facing.

The Calliope mini measures the compass heading from 0 to 360 degrees with its magnetometer chip. Different numbers mean north, east, south, and west.

input.compassHeading();

Returns

Example

This program finds the compass heading and stores it in the degrees variable.

let degrees = input.compassHeading()

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.

Example: compass

This program finds the compass heading and then shows a letter that means whether the Calliope mini is facing north (N), south (S), east (E), or west (W).

basic.forever(() => {
    let degrees = input.compassHeading()
    if (degrees < 45)
        basic.showString("N")
    else if (degrees < 135)
        basic.showString("E")
    else if (degrees < 225)
        basic.showString("S")
    else basic.showString("W")
})

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 to calibrate (adjust itself). It will ask you to draw a circle by tilting the Calliope mini.

If you are calibrating or using the compass near metal, it might confuse the Calliope mini.

See also

acceleration

Edit this page on GitHub