Compass 2 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 2 Click - Working Code

#1 Post by Bill Legge » 31 Aug 2022 10:37

The code here works OK and gives reasonable results.
The set up is:

1. EasyPICFusionv7 with TFT and PIC32MX795F512L.
2. Compass 2 Click in left BUS 1 socket.
3. RS232 Click in right BUS 2 socket - or use the USB/UARTB for RF12/RF13.
4. Input RG12 is used to break out of the calibration loop - set the board switches SW10 and PORTG/H as described in my code.
Most of my difficulty was working out how to manipulate the magnetic field readings Mx My and Mz:
1. Read the max and min values whilst rotating the board.
2. Normalise, for example Mx_normalised = (Mx - Mxmin)/(Mxmax - Mxmin) so the range is 0 to +1
3. Then scale and shift, for example Mx_scale_shift = (Mx_normalised * 2) - 1 so the range = -1 to +1

Whilst rotating the board to read Mmax and Mmin the I2C loop 'locks-up' This is caused by touching the back of the board
in the area of mikroBUS1 and upsetting the voltages on the pins - keep your fingers on the board edges only.

The code is 'clunky' and reads/displays many of the register values that are not essential to getting a heading in degrees.
But, it gives a good insight into I2C comms and the compass 2 Click board.

Regards Bill Legge in Australia
Main.zip
(6.42 KiB) Downloaded 48 times
Header.zip
(2.63 KiB) Downloaded 42 times
Resources_Tahoma_26X29.zip
(3.84 KiB) Downloaded 38 times

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

Re: Compass 2 Click - Working Code

#2 Post by filip » 07 Sep 2022 09:12

Hi,

Thank you very much for this code! :)

Regards,
Filip.

Post Reply

Return to “User Projects”