Compass 4 Click - Working Code

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
Bill Legge
Posts: 235
Joined: 28 Oct 2007 03:16
Location: West Australia

Compass 4 Click - Working Code

#1 Post by Bill Legge » 20 Aug 2022 01:44

Working code that gives reasonable results - if yours fails it may be due to not collecting sufficient max and min values in the calibration loop?
The set up is:
1. EasyPICFusionv7 with TFT and PIC32MX795F512L.
2. Compass 4 Click in left BUS 1 socket.
3. RS232 Click in right BUS 2 socket - or use the USB/UARTB for RF12/RF13.
The Compass 4 Click has a few catches. You really need to read the manual for the AK09915 chip:
1. The write address is 0x18. The click board jumpers are not set as shown on the circuit diagram (The Mikro chip carrier ties the address pins CAD0=0 and CAD1=0)
2. 100ns minimum delay after any MODE change.
3. Must read register STATUS2 after reading the fields Mx My My in CONTINUOUS MODE at 10Hz, 20Hz etc
4. The field strengths need normalising, scaling and adjusting before using arctan2 to work out a heading (0 to 360 degrees):
  • Read the max and min values whilst rotating the board.
  • Normalise, for example Mx_normalised = (Mx - Mxmin)/(Mxmax - Mxmin) so the range is 0 to +1
  • Then scale and shift, for example Mx_scale_shift = (Mx_normalised * 2) - 1 so the range = -1 to +1
Input RG12 is used to break out of the calibration loop - set the board switches SW10 and PORTG/H as described in my code.
If you I2C comms fail it may be due to handling the area of mikroBUS1 and upsetting the voltages on the pins - keep your fingers on the board edges only.

Regards Bill Legge in Australia
Resources_Tahoma_26X29.zip
(3.84 KiB) Downloaded 37 times
Header.zip
(2.29 KiB) Downloaded 53 times
Template_Compass_4_Click.zip
(5.52 KiB) Downloaded 40 times
Last edited by Bill Legge on 08 Sep 2022 01:05, edited 4 times in total.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Compass 4 Click - Working Code

#2 Post by filip » 05 Sep 2022 10:46

Hi,

Thanks for your help, it is appreciated!

Regards,
Filip.

Post Reply

Return to “User Projects”