Silicon ChipEl cheapo modules, part 20: two tiny compass modules - November 2018 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Are electronic medical records privacy concerns overblown?
  4. Feature: Which tiny country is about to launch a lunar lander? by Dr David Maddison
  5. Project: Oh Christmas tree, oh Christmas tree... by Tim Blythman
  6. Project: USB digital and SPI interface board by Tim Blythman
  7. Feature: Australians develop a "supercomputer" by Geoff Graham
  8. Serviceman's Log: It's torture having a broken phone by Dave Thompson
  9. Project: Insomnia and Tinnitus killer by John Clarke
  10. Feature: El cheapo modules, part 20: two tiny compass modules by Jim Rowe
  11. Project: GPS-synched, lab-quality frequency reference (Part 2) by Tim Blythman and Nicholas Vinen
  12. Product Showcase
  13. Subscriptions
  14. Vintage Radio: The 1939 HMV 904 5-inch TV set and 3-band radio receiver by Dr Hugo Holden
  15. PartShop
  16. Market Centre
  17. Advertising Index
  18. Notes & Errata: Super Digital Sound Effects Module, August-September 2018
  19. Outer Back Cover: Trio Test & Measurement - Siglent test equipment

This is only a preview of the November 2018 issue of Silicon Chip.

You can view 41 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Oh Christmas tree, oh Christmas tree...":
  • Software for Amazing Light Patterns for the LED Christmas Tree (Free)
  • Stackable LED Christmas Tree PCB [16107181] (AUD $5.00)
  • Kit for the Stackable LED Christmas Tree (Component, AUD $10.00)
  • Kit for the Digital Interface Module (Component, AUD $15.00)
  • Arduino sketch (.ino) files and sample Python software for the LED Christmas Tree (Free)
  • LED Christmas Tree PCB pattern (PDF download) [16107181] (Free)
Articles in this series:
  • Oh Christmas tree, oh Christmas tree... (November 2018)
  • Oh Christmas tree, oh Christmas tree... (November 2018)
  • Amazing light display from our LED Christmas tree... (December 2018)
  • Amazing light display from our LED Christmas tree... (December 2018)
Items relevant to "USB digital and SPI interface board":
  • USB Digital and SPI Interface PCB [16107182] (AUD $2.50)
  • PIC16F1455-I/P programmed for the USB Digital and SPI Interface Module [1610718A.HEX] (Programmed Microcontroller, AUD $10.00)
  • Kit for the Digital Interface Module (Component, AUD $15.00)
  • Firmware (HEX and C) files for the USB Digital and SPI Interface Module (Software, Free)
  • USB Digital and SPI Interface PCB pattern (PDF download) [16107182] (Free)
Items relevant to "Insomnia and Tinnitus killer":
  • Tinnitus/Insomnia Killer PCB (Jaycar version) [01110181] (AUD $5.00)
  • Tinnitus/Insomnia Killer PCB (Altronics version) [01110182] (AUD $5.00)
  • Tinnitus/Insomnia Killer PCB (Jaycar version, manufacturing fault) [01110181] (AUD $2.50)
  • PIC12F617-I/P programmed for the White Noise Generator [0910618A.HEX] (Programmed Microcontroller, AUD $10.00)
  • Hard-to-get parts for the Tinnitus/Insomnia Killer (Component, AUD $12.50)
  • Firmware (ASM and HEX) files for the White Noise Source and Steam Train Whistle/Diesel Horn [0910618A/M.HEX] (Software, Free)
  • Tinnitus/Insomnia Killer PCB patterns (PDF download) [01110181/2] (Free)
  • Tinnitus and Insomnia Killer panel label artwork and drilling templates (PDF download) (Panel Artwork, Free)
Items relevant to "El cheapo modules, part 20: two tiny compass modules":
  • Sample BASIC source code for interfacing a Micromite with an eCompass module (Software, Free)
Articles in this series:
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • A Gesture Recognition Module (March 2022)
  • A Gesture Recognition Module (March 2022)
  • Air Quality Sensors (May 2022)
  • Air Quality Sensors (May 2022)
  • MOS Air Quality Sensors (June 2022)
  • MOS Air Quality Sensors (June 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Heart Rate Sensor Module (February 2023)
  • Heart Rate Sensor Module (February 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • VL6180X Rangefinding Module (July 2023)
  • VL6180X Rangefinding Module (July 2023)
  • pH Meter Module (September 2023)
  • pH Meter Module (September 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 1-24V USB Power Supply (October 2024)
  • 1-24V USB Power Supply (October 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
Items relevant to "GPS-synched, lab-quality frequency reference (Part 2)":
  • GPS-synched Frequency Reference PCB [04107181] (AUD $7.50)
  • PIC32MX170F256B-50I/SP programmed for the GPS-Synched Frequency Reference [0410718A.hex] (Programmed Microcontroller, AUD $15.00)
  • VK2828U7G5LF TTL GPS/GLONASS/GALILEO module with antenna and cable (Component, AUD $25.00)
  • Micromite LCD BackPack V2 complete kit (Component, AUD $70.00)
  • SMD parts for the GPS-Synched Frequency Reference (Component, AUD $80.00)
  • Firmware (HEX) files and BASIC/C source code for the GPS-Synched Frequency Reference [0410718A.hex] (Software, Free)
  • GPS-Synched Frequency Reference PCB pattern (PDF download) [04107181] (Free)
  • GPS-synched Frequency Reference drilling and cutting diagrams (PDF download) (Panel Artwork, Free)
Articles in this series:
  • GPS-synched Frequency Reference Pt.1 (October 2018)
  • GPS-synched Frequency Reference Pt.1 (October 2018)
  • GPS-synched, lab-quality frequency reference (Part 2) (November 2018)
  • GPS-synched, lab-quality frequency reference (Part 2) (November 2018)

Purchase a printed copy of this issue for $10.00.

Using Cheap Asian Electronic Modules Part 20: by Jim Rowe Two tiny Electronic C mpass modules The Elecrow GY-271 and the GY-511 are two low-cost electronic compass modules. Both readily available modules incorporate a 3-axis magnetometer, with the GY-511 also including an accelerometer. You can use them with an Arduino, Micromite or any other microcontroller which supports I2C communication. T he GY-271 is the smaller of the two modules, measuring only 14.5 x 13.3 x 3.5mm (without the 5-pin header attached). It’s based on the Honeywell HMC5883L 3-axis digital compass (magnetometer) IC, which is no longer being manufactured but is nevertheless still available in significant quantities. The GY-511 is nearly double the size, measuring 21 x 14.5 x 3.5mm (without the 8-pin header attached). This module is based on the STMicroelectronics LSM303DLHC 3D accelerometer/3D magnetometer IC, which is somewhat more complex than the HMC5883L. A functionally identical clone of the GY-271 is available from Altronics (Cat Z6391) and Jaycar (Cat XC4496). This has a six-pin header rather than five, with the extra pin being a 3.3V output from the on-board regulator which you can use to power external circuitry. Since that connection is purely for convenience, the description of the GY-271 here applies to those modules too. The GY-511 is also available from Altronics, Cat Z6391A. Interestingly, while the GY-511 is a bit more expensive overseas, Altronics charge exactly the same for it as they do the GY-271 clone. Given the extra functionality, that seems like the one to get. 72 Silicon Chip The HMC5883L The HMC5883L IC used in the GY271 module comes in a tiny 3 x 3 x 0.9mm 16-pin LCC (leadless chip carrier) surface-mount package. A simplified version of its internal block diagram is shown in Fig.1. There are actually two chips inside the HMC5883L: the sensing block on the far left (pink shading) which does the actual magnetic field sensing and the measurement and control circuitry which forms the rest of the device. Presumably, this is necessary because they use different manufacturing processes. The sensing block chip has three magneto-resistive sensor bridges, orientated at right angles to each other. They are labelled X, Y and Z. This allows it to sense both the direction and magnitude of very low-intensity magnetic fields, like the one generated by the Earth. The sensor bridge outputs are connected to the inputs of an analog multiplexer (MUX) on the measurement chip, which allows the control circuitry to select them in turn. The selected bridge output is then passed via a charge amplifier to the input of a 12-bit ADC (analog-to-digital converter), which delivers its corresponding digital value to the control logic section. When all three measurements have been made in this way, the control logic makes them available to an external Fig.1: block diagram for the Honeywell HMC5883L eCompass IC, showing the magnetic sensing bridges at upper left, which are connected to the charge amplifier by a multiplexer. Australia’s electronics magazine siliconchip.com.au Fig.2: circuit diagram of the GY-271, which is based around the HMC5883L IC. It has few other components; primarily, voltage regulator REG1, level shifting Mosfets Q1 & Q2 and some bypass/filtering capacitors and pull-up resistors. MCU via the standard I2C interface at far right. The other two circuit blocks labelled “Offset Strap Driver” and “Set/Reset Strap Driver” are used by the chip’s control logic to perform degaussing, testing and offset compensation for the magneto-resistive sensor bridges. As a result, the device can offer magnetic field resolution down to 200nT (nanoTesla) or 2mG (milliGauss). This makes it very suitable for measurements of the Earth’s magnetic field, which tends to vary between about 22µT and 64µT (microTesla) over the planet’s surface. And it can make these measurements at a rate of up to 160Hz. The supply current of the HMC5883L is very low, varying from around 2µA in idle mode up to about 100µA when it’s making measurements. This makes it suitable for portable and hand-held applications like smartphones and tablets. The circuit diagram of the complete GY-271 eCompass module is shown in Fig.2 with the HMC5883L forming the heart of this module. The only other active devices are REG1, a 3.3V LDO (low-dropout) regulator and N-channel Mosfets Q1 and Q2 which perform level translation on the SCL and SDA lines of the module’s I2C interface. This means that the HMC5883L can operate from a 3.3V supply rail but still siliconchip.com.au exchange data with an external micro running from a 5V supply. In fact, the I2C pull-up resistors (2.2kW) for CON1 connect to the incoming 5V supply. The 220nF capacitor between pins 8 and 12 of IC1 determines its Set/Reset timing, while the 4.7µF capacitor from pin 10 to ground acts as a reservoir for the charge amplifier ahead of the ADC. Pin 15 provides a data ready signal at the end of each measurement cycle. This is brought out to pin 5 of Australia’s electronics magazine CON1, for optional use by the MCU to which it’s connected. We’ll describe how to use this module a bit later. First, let’s take a look at the IC used in its larger sibling, the LCM303DLHC. The LSM303DLHC IC Fig.3 shows a simplified block diagram of the LSM303DLHC eCompass IC, and as you can see it is a little more complex than the HMC5883L (Fig.1). November 2018  73 Fig.3: the STMicro LSM303DLHC IC is similar to the HMC5883L shown in Fig.1 but also incorporates a three-axis MEMS accelerometer along with an additional multiplexer and amplifier. This allows the compass’ orientation to be determined, for more accurate results. Most of the additional complexity is because this device incorporates a 3-axis linear accelerometer as well as the 3-axis magnetometer. The magnetometer’s sensing system is similar to that in the HMC5883L, with three magneto-resistive sensor bridges orientated at right angles to each other. The linear accelerometer sensors are made from very thin micromachined strips, again orientated in mutually orthogonal directions, which cause capacitance changes when they deflect in response to any acceleration forces. They can also be used to sense gravitational fields, which allows the Earth’s gravitational field to be used for calibrating the magnetometer. Both sensor arrays are shown in the pink shaded area of Fig.3 and they each have their own multiplexer and charge amplifier feeding the in-built ADC. The only other real differences from the HMC5883L are the additional blocks shown at the bottom of Fig.3. Either of the two sensing arrays can be enabled or disabled by the control logic, in response to commands sent from the host MCU via the I2C interface. Since the accelerometer array is not really needed when you want to use the device as a simple eCompass, it can therefore be disabled. So when used as an eCompass, the LSM303DLHC is quite similar to the HMC5883L. The LSM303DLHC draws about 110µA in normal measurement mode and around 1µA in idle/sleep mode. It has seven magnetic measurement ranges varying from ±1.3 gauss to ±8.1 gauss (1G = 100µT), a maximum magnetic resolution of 2mG (0.2µT or 200nT) and the ability to make measurements at eight selectable rates, from 0.75Hz to 220Hz. So once again, the LSM303DLHC IC forms the heart of the GY-511 eCompass module, as shown in Fig.4. If you compare this with Fig.2, you’ll see that they’re almost identical. The only differences are the chip for IC1 and an 8-pin header for CON1 instead of a 5-pin header. When using the GY-511 module as an eCompass, the additional pins can be ignored. Fig.4: the circuit for the GY-511 eCompass module, which is virtually identical to the GY-271 shown in Fig.2, except that a different IC is used and it has two extra interrupt signal connections which are wired to header CON1This has more pins (eight, compared to five), along with a 3.3V output from REG1. 74 Silicon Chip Australia’s electronics magazine siliconchip.com.au The GY-511 module shown enlarged above and to its right is the example serial output from the Compass.ino sketch (James Sleeman's Arduino library) using the GY-271. Connecting to a micro As both modules use an I2C serial interface to exchange data with an MCU, connecting them to an Arduino or a Micromite is straightforward. Fig.5 shows how a GY-271 is connected to an Arduino, while Fig.6 shows how it’s connected to a Micromite. Similarly, Fig.7 shows how a GY-511 module is connected to an Arduino, while Fig.8 shows how it’s connected to a Micromite. Things are not quite so straightforward when it comes to the software. You would expect that there are already Arduino libraries suitable for interfacing with these modules, and indeed they are available. But when I tried them out, I found most of them to be too complicated, poorly written and/or buggy. The only library I found that was both easy to use and worked well was one called HMC5883L_Simple, written by James Sleeman in New Zealand. This library can be downloaded from Mr Sleeman’s website, at: http://sparks. gogo.co.nz/HMC5883L_Simple.zip The archive file includes a simple example sketch (Compass.ino), which I can recommend. A sample grab of the Arduino IDE’s Serial Monitor output when running this sketch is shown above, with the GY-271 module’s Y axis pointing to magnetic north. The heading figures are all within the range of 0.43-2.14°N. Since the two modules are similar, we adapted this library to work with the GY-511 module without any modifications, although the magnitude of the results may be wrong (this isn't terribly important when using it as a compass). siliconchip.com.au When it comes to using either of these modules with a Micromite, I couldn’t find any existing programs or libraries. So I had to analyse the functions embedded in Arduino libraries (especially Mr Sleeman’s), and then write MMBasic programs to duplicate the same functions on the Micromite. The programs I wrote are called “GY271 eCompass.bas” and “GY511 eCompass.bas” and both are available in a zip file from the Silicon Chip website. Note that all of these programs (Arduino and Micromite) treat the Yaxis of the module as the “needle” of the eCompass. These programs do the bare mini- mum to allow the modules to be used as electronic compasses. They initialise the main IC, then make measurements twice a second, process the X and Y data readings to arrive at the magnetic heading, then convert this to a true heading by subtracting the local declination figure. Both heading figures are then displayed on the Micromite’s LCD screen, as you can see from the screenshot below. Note that the current declination is also shown at the bottom of the screen, as a reminder. The declination adjustment is necessary because the Earth’s magnetic North Pole is not at the actual North Pole; in fact, they are getting further Our example MMBasic program shows both the magnetic heading (relative to north magnetic pole) and the true heading (relative to the north celestial pole). Australia’s electronics magazine November 2018  75 Fig.5: connecting the GY-271 eCompass module to an Arduino is easy as it only requires four connections: two for 5V power and two for I2C communications (SDA [data] and SCL [clock]). The DRDY signal is not mandatory. ▼ Fig.6: connecting the GY-271 to a ► Micromite (in this case, the LCD BackPack) is just as easy; the connections are the same as in Fig.5 but the Micromite uses pins 17 and 18 for I2C communications. Fig.7: connecting the GY-511 module to an Arduino involves similar wiring compared to the GY-271. As with the DRDY signal, the two interrupt signals are not absolutely necessary and so can be left unconnected. ▼ ◄ Fig.8: as with the Arduino circuit in Fig.7, only four pins of the GY-511 need to be connected to the Micromite (two are for the power supply and two are for I2C serial communications). 76 Silicon Chip Australia’s electronics magazine siliconchip.com.au How a compass works A compass is a portable device used to work out your heading. This is the direction in which you are travelling with respect to the Earth’s axis of rotation, or the hypothetical meridian lines on the surface of the Earth between the true south and North Poles. It does this by sensing the weak magnetic field which surrounds the Earth, due to the magnetisation of the Earth’s metal core. A traditional compass senses the Earth’s field by means of a small magnetised iron needle which is able to rotate freely in the horizontal plane about its centre because it’s either floating on a small pool of liquid or mounted at its centre on a very low friction needle bearing. As a result, the needle can orientate itself to align with the horizontal component of the Earth’s field, so the needle always tends to point towards north. A dial around the circumference of the compass then allows the user to work out the direction of any desired heading. That’s the basic idea, anyway. But in practice, things are a little more complicated. That’s because while the compass needle aligns itself with the Earth’s magnetic field passing from south to north, that field passes between the Earth’s magnetic poles and these are different from the Earth’s true geographic poles (which correspond to its axis of rotation). Not only that, but the magnetic field is not uniform with smooth meridian lines passing between the South and North Magnetic Poles. In fact, the field lines weave around quite a bit, with an orientation varying significantly according to latitude and longitude and also according to time, as the field pattern changes from year to year. So wherever you happen to be, although the needle of a compass nominally points towards north, that doesn’t mean that it shows the direction of true north. To work out the direction of true north, you need to know the angle between the horizontal component of the Earth’s magnetic field at that location and a meridian line from the true South Pole to the true north pole at the same location. This angle is called the Magnetic Declination and you can find the declination at any particular point on the Earth’s surface by referring to either maps or websites like www.magnetic-declination.com The declination varies quite significantly over Australia and New Zealand. For example, in Sydney, it’s around 12.6°E while in Perth it’s around 1.8°W. The current declinations for a number of locations in Oceania are shown in Table 1. There’s another aspect of the Earth’s magnetic field that can affect compass operation. That’s the fact that the magnetic field at any particular location is not aligned parallel to the Earth’s surface (ie, in the horizontal plane) but in many places is at a significant angle. This is called the Magnetic Inclination, and broadly speaking (when facing north) it points down into the ground in the Northern Hemisphere and upwards away from the ground in the Southern Hemisphere. This doesn’t have a major effect on compass operation but it sometimes does need to be taken into account, especially with traditional compasses. Table 1 also shows the inclination of the Earth’s magnetic field for each location. All the inclinations listed are orientated upwards (because all locations are in the Southern Hemisphere) but they vary with latitude. The locations that are furthest south have a noticeably higher inclination than those nearer the Equator. apart each year so you may need to update this value occasionally to maintain accuracy. See the panel above for more detail on the differences between magnetic north and true north. Both programs are written to include the magnetic declination of Sydney (12.583°E, as shown in the previous screenshot). If you’re at a different location, you need to modify the source code to include the correct declination value for your location, near the start of the program: DIM AS FLOAT Declin! = 12.583 Like Mr Sleeman’s Arduino library and example sketch, my Micromite programs make no allowance for the local inclination (tilt) of the Earth’s magnetic field. siliconchip.com.au In this respect, they are the same as a traditional compass – both programs assume that the module’s PCB (and thus its magnetometer chip) is being held in the horizontal plane or close to it. It possible to take the magnetic inclination into account when working out the absolutely true heading of an eCompass but you need to combine the data from the magnetometer with that an accelerometer or gravity field detector like that in the LSM303DLHC chip. So you could not do this with the GY-271 module unless you also had a separate accelerometer. This also requires quite a bit of number crunching to combine the data from the two sensors. Which raises the question of whether it would be worth the effort. Ignoring the inclinaAustralia’s electronics magazine tion seems to deliver a heading accuracy that is at least as good as a traditional compass and probably better. I think that the only applications where it would be necessary to achieve the highest possible heading accuracy would be for things like aircraft or ship navigation, or missile guidance systems. But those are a bit out of my league. Handy links HMC5883L datasheet: siliconchip.com.au/link/aakz LSM303DLHC datasheet: siliconchip.com.au/link/aal0 Magnetic declination: siliconchip.com.au/link/aal1 Geomagnetic declination: siliconchip.com.au/link/aal2 SC November 2018  77