SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By jacobarber
#46884
I am involved in a class project in which we are using an Arduino Diecimila to communicate to Adobe Director via bluetooth. Right now, we have the BlueSMiRF RP-SMA Bluetooth Modem connected to the Diecimila through the digital TX & RX connections, 3.3v, & ground. Bluetooth connection works, so that's not a problem.

We also have a pedometer connected to the Diecimila that is sending "step" signals to our program. That's working just fine as well.

Our issue has come up now that we're trying to connect a digital compass to the Diecimila. The unit we're using is the Honeywell HMC1052L. The connections on the eval board are VCC, Ground, Out1, Out2, and Set. Our programming so far has been done in Processing, which communicates with Flash, and Flash communicates with Director.

My questions:

1) Is there any other hardware besides the Diecimila and the HMC1052L that is needed to get usable data from the compass?

2) Does the Diecimila have an ADC? If so, is it high enough resolution to give an accurate reading from the HMC1052L? If not, then what hardware do we need to make that happen?

3) Can Processing grab data from the HMC1052L and use it like it takes data from other devices?

Give me answers as though I have no prior experience, cause that's about where I'm at. Thanks for help.
By emf
#46905
The arduino has an ADC built in, so you can connect them up directly. The question is how much accuracy do you need?

There was just another thread on this subject a week or so ago. Your ADC has 10 bits of resolution, so it will give you a reading from 0 to 1023. The way the breakout board is configured, the earth's magnetic field will cause the magnetometer's outputs to vary from about 2.25V to 2.75V, so your readings will all be in the 460 - 560 range. That's not going to give you terrific accuracy, but if you just need a rough idea of where you're headed, it should do fine. If you want better accuracy, you can run the outputs through an amplifier or try to coax more bits of resolution out of your ADC.

Also keep in mind you'll only get good results if the compass is level, or nearly so. If you need compass readings at significant angles, you'll need an accelerometer to figure out which way is up, and (I think) a third compass axis.
By jacobarber
#46935
So here is a simple example that can help us out:

- The compass's Out1 & Out2 are connected to Digital inputs, ground, and either 5v or 3.3v on the Diecimila. Is the 'Set' connection needed anywhere?
- The arduino software is started up and the appropriate COM port is being monitored.
- The compass is level

With the 10-bit ADC provided by the Diecimila, we should be receiving numbers between 0 and 1023, or between 460 and 560? And what do those readings mean in terms of directional degrees (0-360 ... north, south, easy, west)?
By emf
#46939
The magnetometer's outputs are analog, so connect them to an analog input. You'll need to connect the 'set' to a digital output. To take a reading, you set the 'set' pin high, then set it low, then do an A/D conversion on each of the magnetometer outputs.

The two outputs give you the strength of the magnetic field in the X or Y direction. They can range from 0-1023 if you bring a magnet near the sensor, but the earth's magnetic field is fairly weak so you'll see a much smaller range when using it as a compass. Actually the 100-point range is a bit optimistic, unless you live on the magnetic equator. Where I live, only about 40% of the magnetic field is in the horizontal direction, so I'd only see a range of ~490 - 530.

Ideally, at ~512 they'd be indicating zero magnetic field, above 512 for positive, below 512 for negative. To get a compass heading, you'll basically subtract 512 from each reading and then feed them to atan2() to get the angle. In the real world, you'll probably have to calibrate their zero points and possibly scale one of the sensors.

With this module, you'll need to become familiar with the datasheet and read some of the app notes to figure out how to get the most of it. It's not particularly hard, but it takes some work to get it to do what you want. If you want easy, one of the prepackaged compass modules would probably save you a lot of headache.
By jacobarber
#47098
We have all the connections in place, and have the formula in place to print out degree headings. We're subtracting 512 from each ouput's reading, and feeding them into the atan2() function. The problem is that the numbers being spit out don't make any sense. Most of the time they stay the same no matter what direction the board is facing, they may be negative, and they are outside the range of what we're looking for. Basically, it feels like we're doing something wrong.

When you say "then do an A/D conversion on each of the magnetometer outputs", is this something that needs to be done in the Processing code? If so, how is it done?

Also, do we need to calibrate the zero points on the compass and scale the sensor in order to get a usable reading? If so, how?

Last: the prepackaged compass modules you mentioned ... is the HMC6352 something you'd recommend instead to avoid the headaches we're getting from the HMC1052L, or is there something else that'd give us simple readings? Thanks very much.
By emf
#47108
jacobarber wrote:The problem is that the numbers being spit out don't make any sense.
Before you worry about the data your equations are spitting out, make sure the data going in looks ok. You could be getting bad data from not doing any calibration, or from bad connections or bad code. Looking at the raw data, for each axis you should see values somewhere near 512. When you rotate the module in a circle, they should both change. If you rotated it at a constant rate and graphed them, one would generate a sine wave, the other a cosine wave. If you aren't getting results that look like this, try bringing a magnet near the sensor and see if you notice a change in the readings.
When you say "then do an A/D conversion on each of the magnetometer outputs", is this something that needs to be done in the Processing code? If so, how is it done?
I just meant "read the analog input". I don't know Processing, but I'm sure it has a simple function to do this.
Also, do we need to calibrate the zero points on the compass and scale the sensor in order to get a usable reading? If so, how?
Yes. Check out Honeywell's app note AN214 - Low Cost Compass.

I've never tried any of the compass modules, so I can't recommend any. I've only used the raw sensors because I'm cheap and I wanted the raw data anyway.