Shawn Hymel's Magnetometer article on Maker.IO

Hello,

The article ‘How to Calibrate a Magnetometer’,
[How to Use a Calibrated Magnetometer as a Compass]

contains a Digital Compass Example.
@(Copy the following program to your Arduino IDE:).

The code does not compile. The section of code >
// Apply soft-iron scaling
for (uint8_t i = 0; i < 3; i ) {
mag_data[i] = (soft_iron[i][0] * hi_cal[0])
(soft_iron[i][1] * hi_cal[1])
(soft_iron[i][2] * hi_cal[2]);
}
Compass_Demo:107:47: error: expression cannot be used as a function
(soft_iron[i][1] * hi_cal[1])
^
Has this been updated, or is there a fix?
I know this is quite a while ago!
Thank you.

Hi,

for (uint8_t i = 0; i < 3; i ) {…

the ‘i’ won’t ever reach 3, change to

for (uint8_t i = 0; i < 3; i++ ) {

Then,
having a calculation
mag_data[i] = ()()();
Won’t make sense. Missing operators. Probably additions are the wanted ones.
mag_data[i] = (soft_iron[i][0] * hi_cal[0]) +
(soft_iron[i][1] * hi_cal[1]) +
(soft_iron[i][2] * hi_cal[2]);

Cheers,
heke

2 Likes

Thanks for your reply.
The missing are commas; as soon as I saw your ()()() I realised they should be (), (), (); then it compiles!
The i only needs to be 0, 1, 2 and not 3 as well. X, Y, Z are the three planes.
It is never easy debugging code you believed to be functional!
Thanks again
Vaughn

3 Likes