Search
Filters
Close

HiTechnic NXT Compass Sensor

Expand your NXT experiences with the new NXT Compass Sensor and add accurate navigation to your Mindstorms® NXT projects. The NXT Compass Sensor is a digital compass that measures the earth's magnetic field and outputs a value representing the current heading. The magnetic heading is calculated to the nearest 1° and returned as a number from 0 to 359. The NXT Magnetic Compass Sensor updates the heading 100 times per second. The Compass Sensor operates in two modes, Read mode and Calibrate mode. In Read mode, the current heading is calculated and returned each time to the NXT program executes a read command. In Calibrate mode the compass can be calibrated to compensate for externally generated magnetic field anomalies such as those that surround motors and batteries, thereby maintaining maximum accuracy.

SKU: NMC1034
$54.95

HiTechnic NXT Compass Sensor for LEGO Mindstorms NXT

Introduction

The NXT Compass Sensor contains a digital magnetic compass that measures the earth’s magnetic field and calculates a heading angle. The Compass Sensor connects to an NXT sensor port using a standard NXT wire and uses the digital I2C communications protocol.  The current heading is calculated to the nearest 1° and refreshed 100 times per second. 

The Compass Sensor is housed in a standard Mindstorms sensor housing to match the other Mindstorms elements.

To test your new sensor, plug it into port 2 of your NXT and select View > Ultrasonic cm > Port 2. As you swing the sensor around, you’ll notice that the readings will change from 1 – 179. (0 will display as ?????? while in View mode.)

Programming

Mindstorms NXT-G

The compass can be programmed using LEGO Mindstorms NXT Software Compass Block*.  If the Compass Block is not available you may also use the standard Ultrasonic Block.

*Note:  The NXT Compass Block can be downloaded by going to the Downloads page.

Ultrasonic Block

If using the Ultrasonic Block to program the compass, configure the block to centimeter mode as shown.

 

The Ultrasonic Block can only return values from 0 to 250 so in order to return the full range of headings, 0 to 360, the heading value returned when using the Ultrasonic Block will be the current heading divided by 2.  For example, if the current heading is 220°, the value returned will be 110.  North will return a value of 0, East, a value of 45, South, a value of 90 and West, a value of 135.  To get the actual magnetic heading, simply take the number returned and multiply by 2.

Compass Sensor Block

The Compass Block is designed to support the HiTechnic Compass Sensor and supports all compass features.

 

 

1.  This plug wires the number for which of your NXT’s ports are connected to the compass sensor.
2.  This plug wires the number of the Action to be performed.
3.  This plug wires the Target heading, see section on Relative Heading further down this page.
4.  This plug wires the lower limit number for the Inside/Outside compare function.
5.  This plug wires the upper limit number for the Inside/Outside compare function.
6.  This plug outputs the current Absolute Heading number.
7.  This plug outputs the current Relative Heading number, see section on Relative Heading further down this page.
8.  This plug outputs the Inside/Outside logical value.

 

 

Compass Front Panel

Port allows you to select the NXT port the compass is plugged into.

Action

Action has three options.  These are;

Absolute Reading:  Allows you to read the Absolute Heading, a value from 0 to 359, corresponding to the current magnetic heading in degrees.  (Plug 6 on the data hub)

Relative Reading: Allows you to set a Target and read the Relative Heading (Plug 3 and 7 on the data hub). 
See Using Relative Reading below for more information.

Calibrate: Set the compass sensor into Calibrate mode allowing you to go through the calibrate sequence to minimize the influence of metal and other other sources of magnetic interference such as motors or batteries.
See Calibrating the Compass Sensor below for more information.

Compare

Compares the Absolute Heading to the range set and sets the logic value to show if the value is inside or outside the range.
See Using Range below for more information.

 

Using Relative Reading

Relative Reading makes it easy to stay on a selected heading.  To use this feature select the Relative Reading action.  Then enter a Target that is the heading you wish to maintain. 

If you wanted to navigate South, you would  enter a Target of 180 (South is 180 degrees).  The Compass Sensor block would then calculate the difference between the Absolute Heading and your Target and return the difference as the Relative Heading. (plug 7).

For example, with your target set to 180, if the Absolute Heading were 175, then the Relative Heading would be 5 (Target – Absolute Heading or 180 – 175 = 5).  This indicates a turn to the right or clockwise of 5 degrees is required to get back to the Target. 

If the Absolute Heading were 185, then the Relative Heading would be -5 (Target – Absolute Heading or 180 – 185 = -5).  This indicates a turn to the left or clockwise of 5 degrees is required to get back to the Target.  

Calibrating the Compass Sensor

The HiTechnic compass sensor will be influenced by local magnetic interference in the same way as any other magnetic compass.  Objects such as metal items, motors, batteries and wires can cause magnetic interference.  Local magnetic interference may cause the compass to output a heading several degrees different than the actual magnetic heading.  This is called compass deviation.  To correct for deviation, the HiTechnic compass sensor has a built in calibration function that calculates correction offsets and stores them in the compass.  

Calibration is optional and usually not required for normal operation. To minimize the need for calibration make sure you mount the compass at least 4 – 6 inches (10 – 15 cm) away from the NXT and NXT motors.

 

To calibrate the compass under program control, select calibration mode (value 2 wired to the Action plug input) and then program your robot to rotate (turn in a tight circle) between 1 ½ and 2 times (more than 360 degrees) so it completes a full turn in about 20 seconds.  Once the turns have been completed, set the Action to a Read function (Absolute or Relative) and the compass will be calibrated.  The compass will retain the calibration settings until another calibration is performed, even if it is unplugged.

Using Range

The Compare lets you set a range and easily determine if you are inside or outside the range.

The Components for using the Range function are;

Inside Range / Outside Range:  Select if you want to test for an Absolute Heading inside the range or outside the range.

A: The lower limit of the range (0 – 359)

B: The upper limit of the range (0 – 359)

To use the Range function, set the lower and upper limit of your range and whether you want to test for inside or outside the range. 

Examples showing the logical result.

A
B
Range
Absolute Heading
Logical Value
85
95
Inside Range
90
85
95
Inside Range
100
85
95
Outside Range
90
85
95
Outside Range
100
 

 

Sensor Register Layout

Address
Type
Contents
00 – 07H
chars
Sensor version number
08 – 0FH
chars
Manufacturer
10 – 17H
chars
Sensor type
18 – 3DH
bytes
Not used
3E, 3FH
chars
Reserved
40H
byte
Not used
41H
byte
Mode control
42H
byte
Heading }  two degree heading
43H
byte
Heading }  one degree adder
44, 45H
word
Heading (low byte, high byte)
46 – 7FH
bytes
Not used

The Sensor version number field will report a revision number in the format “²Vn.m” where n is the major version number and m is the revision level. Revision numbers will typically reflect the firmware level. The version number will be used to indicate the hardware level.

The Manufacturer field will contain “HiTechnc”.

The Sensor type field will contain “Compass”.

The Mode control field may be set to 0x00 or 0x43 to define measurement mode or hard-iron calibrate mode.

The Heading fields will return the currently measured heading during measurement mode operation. During hard-iron calibrate mode operation, this field will jam.

The heading is obtained by reading location 0x42 to obtain the two degree heading and 0x43 to obtain the one degree adder. The heading can then be computed as

Heading = (two degree heading *2) + one degree adder.

If the sign is a problem, then the conventional 16 bit value can be obtained from 0x44 (low byte) and 0x45 (high byte).

Locn 0x41 is the mode control. Defaults to 0, which is measurement mode. Change to  0x43 to set calibration mode. Must be changed back to 0 when calibration is completed. (If cal. fails, locn. 0x41 will be set to 2 after the host has set it to 0 at the end of the failed calibrate attempt.)

Other Programming Environments

RobotC

All features of the HiTechnic Compass can be accessed using RobotC.  For more information go to http://www-education.rec.ri.cmu.edu/robotc/.  

NBC

Next Byte Code (NBC) is a simple programming language that can access all compass features.  For more information go to http://bricxcc.sourceforge.net/nbc/.

 Notes:

  • The HiTechnic compass sensor will only operate correctly in a horizontal plane so you must keep the compass level for it to read correctly. This is very important so remember this when you build it into your robot.
  • NXT Firmware version 1.03 must be loaded in the NXT for the compass to operate correctly.  You can check the firmware version by  displaying the NXT Window in the Mindstorms software.
  • It is highly desirable to mount the compass at least 6 inches (15 cm) away from the motors and 4 inches (10cm) away from the NXT brick itself.
  • Try to make sure it is firmly mounted, if it bounces around, the readings may bounce around too.

HiTechnic NXT Compass Sensor for LEGO Mindstorms NXT

Introduction

The NXT Compass Sensor contains a digital magnetic compass that measures the earth’s magnetic field and calculates a heading angle. The Compass Sensor connects to an NXT sensor port using a standard NXT wire and uses the digital I2C communications protocol.  The current heading is calculated to the nearest 1° and refreshed 100 times per second. 

The Compass Sensor is housed in a standard Mindstorms sensor housing to match the other Mindstorms elements.

To test your new sensor, plug it into port 2 of your NXT and select View > Ultrasonic cm > Port 2. As you swing the sensor around, you’ll notice that the readings will change from 1 – 179. (0 will display as ?????? while in View mode.)

Programming

Mindstorms NXT-G

The compass can be programmed using LEGO Mindstorms NXT Software Compass Block*.  If the Compass Block is not available you may also use the standard Ultrasonic Block.

*Note:  The NXT Compass Block can be downloaded by going to the Downloads page.

Ultrasonic Block

If using the Ultrasonic Block to program the compass, configure the block to centimeter mode as shown.

 

The Ultrasonic Block can only return values from 0 to 250 so in order to return the full range of headings, 0 to 360, the heading value returned when using the Ultrasonic Block will be the current heading divided by 2.  For example, if the current heading is 220°, the value returned will be 110.  North will return a value of 0, East, a value of 45, South, a value of 90 and West, a value of 135.  To get the actual magnetic heading, simply take the number returned and multiply by 2.

Compass Sensor Block

The Compass Block is designed to support the HiTechnic Compass Sensor and supports all compass features.

 

 

1.  This plug wires the number for which of your NXT’s ports are connected to the compass sensor.
2.  This plug wires the number of the Action to be performed.
3.  This plug wires the Target heading, see section on Relative Heading further down this page.
4.  This plug wires the lower limit number for the Inside/Outside compare function.
5.  This plug wires the upper limit number for the Inside/Outside compare function.
6.  This plug outputs the current Absolute Heading number.
7.  This plug outputs the current Relative Heading number, see section on Relative Heading further down this page.
8.  This plug outputs the Inside/Outside logical value.

 

 

Compass Front Panel

Port allows you to select the NXT port the compass is plugged into.

Action

Action has three options.  These are;

Absolute Reading:  Allows you to read the Absolute Heading, a value from 0 to 359, corresponding to the current magnetic heading in degrees.  (Plug 6 on the data hub)

Relative Reading: Allows you to set a Target and read the Relative Heading (Plug 3 and 7 on the data hub). 
See Using Relative Reading below for more information.

Calibrate: Set the compass sensor into Calibrate mode allowing you to go through the calibrate sequence to minimize the influence of metal and other other sources of magnetic interference such as motors or batteries.
See Calibrating the Compass Sensor below for more information.

Compare

Compares the Absolute Heading to the range set and sets the logic value to show if the value is inside or outside the range.
See Using Range below for more information.

 

Using Relative Reading

Relative Reading makes it easy to stay on a selected heading.  To use this feature select the Relative Reading action.  Then enter a Target that is the heading you wish to maintain. 

If you wanted to navigate South, you would  enter a Target of 180 (South is 180 degrees).  The Compass Sensor block would then calculate the difference between the Absolute Heading and your Target and return the difference as the Relative Heading. (plug 7).

For example, with your target set to 180, if the Absolute Heading were 175, then the Relative Heading would be 5 (Target – Absolute Heading or 180 – 175 = 5).  This indicates a turn to the right or clockwise of 5 degrees is required to get back to the Target. 

If the Absolute Heading were 185, then the Relative Heading would be -5 (Target – Absolute Heading or 180 – 185 = -5).  This indicates a turn to the left or clockwise of 5 degrees is required to get back to the Target.  

Calibrating the Compass Sensor

The HiTechnic compass sensor will be influenced by local magnetic interference in the same way as any other magnetic compass.  Objects such as metal items, motors, batteries and wires can cause magnetic interference.  Local magnetic interference may cause the compass to output a heading several degrees different than the actual magnetic heading.  This is called compass deviation.  To correct for deviation, the HiTechnic compass sensor has a built in calibration function that calculates correction offsets and stores them in the compass.  

Calibration is optional and usually not required for normal operation. To minimize the need for calibration make sure you mount the compass at least 4 – 6 inches (10 – 15 cm) away from the NXT and NXT motors.

 

To calibrate the compass under program control, select calibration mode (value 2 wired to the Action plug input) and then program your robot to rotate (turn in a tight circle) between 1 ½ and 2 times (more than 360 degrees) so it completes a full turn in about 20 seconds.  Once the turns have been completed, set the Action to a Read function (Absolute or Relative) and the compass will be calibrated.  The compass will retain the calibration settings until another calibration is performed, even if it is unplugged.

Using Range

The Compare lets you set a range and easily determine if you are inside or outside the range.

The Components for using the Range function are;

Inside Range / Outside Range:  Select if you want to test for an Absolute Heading inside the range or outside the range.

A: The lower limit of the range (0 – 359)

B: The upper limit of the range (0 – 359)

To use the Range function, set the lower and upper limit of your range and whether you want to test for inside or outside the range. 

Examples showing the logical result.

A
B
Range
Absolute Heading
Logical Value
85
95
Inside Range
90
85
95
Inside Range
100
85
95
Outside Range
90
85
95
Outside Range
100
 

 

Sensor Register Layout

Address
Type
Contents
00 – 07H
chars
Sensor version number
08 – 0FH
chars
Manufacturer
10 – 17H
chars
Sensor type
18 – 3DH
bytes
Not used
3E, 3FH
chars
Reserved
40H
byte
Not used
41H
byte
Mode control
42H
byte
Heading }  two degree heading
43H
byte
Heading }  one degree adder
44, 45H
word
Heading (low byte, high byte)
46 – 7FH
bytes
Not used

The Sensor version number field will report a revision number in the format “²Vn.m” where n is the major version number and m is the revision level. Revision numbers will typically reflect the firmware level. The version number will be used to indicate the hardware level.

The Manufacturer field will contain “HiTechnc”.

The Sensor type field will contain “Compass”.

The Mode control field may be set to 0x00 or 0x43 to define measurement mode or hard-iron calibrate mode.

The Heading fields will return the currently measured heading during measurement mode operation. During hard-iron calibrate mode operation, this field will jam.

The heading is obtained by reading location 0x42 to obtain the two degree heading and 0x43 to obtain the one degree adder. The heading can then be computed as

Heading = (two degree heading *2) + one degree adder.

If the sign is a problem, then the conventional 16 bit value can be obtained from 0x44 (low byte) and 0x45 (high byte).

Locn 0x41 is the mode control. Defaults to 0, which is measurement mode. Change to  0x43 to set calibration mode. Must be changed back to 0 when calibration is completed. (If cal. fails, locn. 0x41 will be set to 2 after the host has set it to 0 at the end of the failed calibrate attempt.)

Other Programming Environments

RobotC

All features of the HiTechnic Compass can be accessed using RobotC.  For more information go to http://www-education.rec.ri.cmu.edu/robotc/.  

NBC

Next Byte Code (NBC) is a simple programming language that can access all compass features.  For more information go to http://bricxcc.sourceforge.net/nbc/.

 Notes:

  • The HiTechnic compass sensor will only operate correctly in a horizontal plane so you must keep the compass level for it to read correctly. This is very important so remember this when you build it into your robot.
  • NXT Firmware version 1.03 must be loaded in the NXT for the compass to operate correctly.  You can check the firmware version by  displaying the NXT Window in the Mindstorms software.
  • It is highly desirable to mount the compass at least 6 inches (15 cm) away from the motors and 4 inches (10cm) away from the NXT brick itself.
  • Try to make sure it is firmly mounted, if it bounces around, the readings may bounce around too.

The RobotC driver suite supports HiTechnic products for RobotC 4.x and RobotC 3.x. Select the corresponding repository at the link below and download the zip file. 

https://github.com/botbench

HiTechnic Compass Sensor Block for Mindstorms NXT Software
The Compass Sensor Block adds support for all Compass Sensor features to the LEGO MINDSTORMS NXT Software. This block gives access to features enabling Compass calibration, target heading and in/out of range and others.
New with version 2.1: Fixes a bug preventing entering Calibration mode. You can now tell if calibration succeeded or failed by examining the absolute heading after calibration. This block supports for the HiTechnic Sensor Multiplexer as well as data logging with the LEGO Mindstorms 2.0 Education software.
  Description Version Release Date Size  
NXTIcon HiTechnic Compass Sensor Block for Mindstorms NXT Software 2.1 January 14th, 2011 637.96 KB Download Now
FTC Update For LabVIEW 2009
LabVIEW 2009 VIs and sample program VIs for the sensors commonly used by FTC teams. This set includes VIs for the Acceleration, Compass, Gyro, IR Seeker V2, and Magnetic Sensors as well the Touch Sensor Multiplexer. These VIs support the HiTechnic Sensor Multiplexer. See included readme.txt file on how to install into LabVIEW 2009.
  Description Version Release Date Size  
LabView FTC Update For LabVIEW 2009 1.0 October 6th, 2010 261.37 KB Download Now
Compass Sensor VIs For LabVIEW2009
Compass Sensor VIs and sample program VI for LabVIEW 2009. Supports the HiTechnic Sensor Multiplexer. See included readme.txt file on how to install into LabVIEW 2009.
  Description Version Release Date Size  
LabView Compass Sensor VIs For LabVIEW2009 1.0 October 6th, 2010 96.92 KB Download Now
Compass Sensor VI
LabVIEW VI to access the HiTechnic Compass Sensor in the NXT Toolkit.
Note: This vi is designed for LabVIEW 7.1 with NXT Toolkit.
  Description Version Release Date Size  
LabView Compass Sensor VI 1.0 April 2nd, 2009 34.51 KB Download Now
HiTechnic EV3 I2C Blocks
This is a release of the HiTechnic EV3 blocks file. Supported sensors are: Angle, Compass, Accelerometer, and IRSeekerV2.
New with v. 0.30: Compass and IRSeekerV2 blocks updated.
Split blocks into individual .ev3b files so you only need to import what you need. Worked around EV3 IIC U8 as I8 bug.
  Description Version Release Date Size  
EV3Logo HiTechnic EV3 I2C Blocks 0.30 May 19th, 2017 149 KB Download Now
Customers who bought this item also bought

HiTechnic NXT IRSeeker V2

Play robot soccer and zero in on your infrared (IR) beacons with the new and enhanced IRSeeker V2 (Version 2). You can use most TV remotes and LEGO® Power Functions remotes as beacons that the IRSeeker V2 will detect. With a specially designed curved lens and five internal detectors, the IRSeeker V2 has a 240 degree view making it perfect for playing robot soccer with the HiTechnic IRBall. The IRSeeker V2 has enhanced modes that detect modulated IR signals, including the new RoboCup Jr stepped modulated mode, and it filters out background signals giving superior performance in brightly lit rooms and sunny locations. The sensor returns the signal direction and strength making it easy to locate and gauge the relative distance to the target. A winning robot soccer combination when combined with the HiTechnic NXT Compass Sensor!
$54.95

Infrared Electronic Ball

This IR Ball can be detected by the IR Seeker and IR Locator to create a great game of robot soccer or simply use it as an IR beacon.
$79.95 $49.00