HMC6352 compass and servo motors both on a BOE shield a bad combo?

Hi all,

I have question, i have a BOE shield with a HMC6362 compass sensor and two servo motors. I have written a simple program that gets the heading form the compass and then turns left, the goal is to 90 degrees left.

On the BOE shield is a switch where i can turn on the shield, breadbord (on the BOE shield) and also power on the attached servo's.

When i turn on the breadbord (the compass gets power and is activated) i get clean readings say 25 degrees. But when i flip the switch to also actevate the servos then i get a lot of false reading. Even if i stop the motors (so the device doesn't shake anymore) wait one second and then read out the sensor i still get a lot of false readings.

Does anyone have a idea why this is happening?

Below are some print out of the readings (the actual heading of the device didn't change):
Witouth the servos:

FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 25

With the servos:

ND OBJECTSTATE: Currentheading: 73
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 25
FIND OBJECTSTATE: Currentheading: 11
FIND OBJECTSTATE: Currentheading: 21
FIND OBJECTSTATE: Currentheading: 74
FIND OBJECTSTATE: Currentheading: 73
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 73
FIND OBJECTSTATE: Currentheading: 17
FIND OBJECTSTATE: Currentheading: 78
FIND OBJECTSTATE: Currentheading: 21
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 75
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 64
FIND OBJECTSTATE: Currentheading: 17
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 82
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 69
FIND OBJECTSTATE: Currentheading: 14
FIND OBJECTSTATE: Currentheading: 39
FIND OBJECTSTATE: Currentheading: 20
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 60
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 24
FIND OBJECTSTATE: Currentheading: 24

How are the servos powered ?
Direct from the Arduino or separately with a common GND to the Arduino ?

Thanks for your respose! I have found the problem, the batterypack (5 AA) where low on power, when i change out the battery i got the right values. I think that the problem lays the greater power demand (servos, compass and other sensors).

The electric motor or servo on your robot is going to create a magnetic field when it is running, which is going to disrupt the geomagnetic field sensor. That is a magnetic field disturbance in addition to any electrical noise you may have. You should mount the geomagnetic field sensor as far as possible from motors, servos, or anything else creating a magnetic field.