Computing stuff tied to the physical world

Not quite a compass, yet

In Software on Mar 25, 2010 at 00:01

This is an attempt to read out the magnetometer / compass of the Heading Board introduced yesterday.

The demo sketch has been extended, and is still deceptively trivial:

Screen shot 2010-03-23 at 17.30.23.png

The meat of the code is in the HeadingPort class implementation in the Ports.cpp source file.

Trouble is – it doesn’t work :(

Sample run #1:

Screen shot 2010-03-23 at 16.28.33.png

Sample run #2, using another sensor:

Screen shot 2010-03-23 at 16.29.04.png

The barometer readings are more or less consistent, but probably both wrong. The local weather station and my Pressure Plug in the ookRelay both report that the current air pressure is currently around 1017 hPa.

As for the temperature readings, well … the temperature sensor in the Pressure Plug reports 20.9°C, and it’s about one meter away, also on my desk.

What’s worse is that the magnetometer readings are missing, and both come out as zero.

Trying again with a different setup, I get this third sample output:

Screen shot 2010-03-23 at 17.25.11.png

The values don’t change when I rotate the sensor. I can’t make anything of this right now, best guess is that the I2C bus transactions are perhaps flakey. Not impossible – this is a pretty simplistic software-based bit-banging I2C implementation after all, which doesn’t support things like clock stretching. I could try it out on a real hardware I2C bus via the Plug Shield. Another day…

The code has been added to the Ports library, as usual.

  1. Not knowing what your Sensor object works, it simply looks like you’re passing uninitialized variables (temp, pres, xaxis, yaxis) to its methods (perhaps expecting them to get set as a side effect) and printing out their values upon return. Which would explain why they don’t change much and have seemingly non-sensical values.

    It simply looks like you should be passing these guys by reference rather than by value (i.e. &temp, &pres, &xaxis, &yaxis). But like I said, I don’t know anything about Sensor nor what its method signatures are,… but that looks highly suspicious.

    • The values are passed via “references” (a C++ mechanism) – these are basically hidden pointers, so the values will be set by the call. Uninitialized is ok.

  2. I have one of these too. I have gotten even less far with it than you have. I’ve never gotten mine to talk to me at all. I suppose I should have studied the datasheet harder before I purchased it: At the top of page 1: ” 2.4V-5.25V wide power supply operation supported” in the middle of page 1 “FEATURES Supply voltage 2.2V-3.6V” on page 3: “supply voltage min -0.5V max 4V” on page 4: “supply voltage min 2.4V max 3.6V”

    The I2C address for the magnetic sensor is not really specified in the datasheet either, although they did send me some source code that used 0x30 as you do, implying that the ‘xx’ in the datasheet on page 15 is ’00’.

    The pressure sensor’s specs look less accurate than the HP03; on the Arduino forum, Michael Margolis remarked that altitude readings with that device varied 4 – 5 meters in individual readings, but using 12 readings and averaging he got good results. Software-wise the HP03 and the pressure portion of the HDPM01 look quite similar. Like you, I am about to put mine aside. Perhaps inspiration or someone else’s success will let me pick this up again later.

    One other thing I noted tonight, the alpha labels on the board and in the datasheet agree but the pin NUMBERS on page 3 are not in any sensible order. Could the pinouts be completely different than the alphabetic labels?????

    • Hm, that’s not good news. I do seem to connect to the chip, but what worries me is that it’s not reproducible – hence the thought that maybe the I2C bus needs extra pullup resistors or something, i.e. an electrical issue. I’ll try some more things. Later.

Comments are closed.