2

I'm developing a project where I can control a RC boat with GPS and a magnetometer. How ever, I was developing everything connected to my computer and worked pretty well. When I was going to make some test with a battery and a couple of Xbee's (PC and "Arduino"), the magnetometer signal was not updating. So, I read the first value and continued to transmit the same value (thing that never happened on computer). Has someone had the same issue before? How can I solve this? Oh, one thing. The GPS and magnetometer comes in the same module, and I'm having no problems with GPS coordinates. And even if I power de MCU with my computer and transmitting with the Xbee's it doesn't work either. Seems like a communication problem.

Hardware used:

GPS Module + Compass

ATmega1284P

UPDATE:

I want to share also the code I'm using for the I2C reading.

#include <Wire.h> //I2C Arduino Library
#define address 0x1E //0011110b, I2C 7bit address of HMC5883
void setup(){
 //Initialize Serial and I2C communications
 Serial.begin(9600);
 Wire.begin();
 //Put the HMC5883 IC into the correct operating mode
 Wire.beginTransmission(address); //open communication with HMC5883
 Wire.send(0x02); //select mode register
 Wire.send(0x00); //continuous measurement mode
 Wire.endTransmission();
}
 void loop(){
 int x,y,z; //triple axis data
 //Tell the HMC5883L where to begin reading data
 Wire.beginTransmission(address);
 Wire.send(0x03); //select register 3, X MSB register
 Wire.endTransmission();
 //Read data from each axis, 2 registers per axis
 Wire.requestFrom(address, 6);
 if(6<=Wire.available()){
 x = Wire.receive()<<8; //X msb
 x |= Wire.receive(); //X lsb
 z = Wire.receive()<<8; //Z msb
 z |= Wire.receive(); //Z lsb
 y = Wire.receive()<<8; //Y msb
 y |= Wire.receive(); //Y lsb
 }
 //Print out values of each axis
 Serial.print("x: ");
 Serial.print(x);
 Serial.print(" y: ");
 Serial.print(y);
 Serial.print(" z: ");
 Serial.println(z);
}
asked Nov 8, 2016 at 3:40
8
  • Maybe the battery is too weak. Or you are using voltage regulators with too high voltage drop. It can be anything. Commented Nov 8, 2016 at 7:57
  • Try and solve one problem at a time. Make a simple circuit that reads the magnetomerter and check it works on the computer. If it does try it on the battery. Then try and solve the Xbee problem. Commented Nov 8, 2016 at 9:55
  • @KIIV I'm using a powerbank, so the battery is not a problem. Even if I supply my MCU from the computer and make the communication wireslessly, it doesn't work. Commented Nov 8, 2016 at 13:49
  • @Matt I have already done that, with every possibilities of connections and power supplies. Seems to be a communication problem when I'm using the Xbee's. Commented Nov 8, 2016 at 13:50
  • This sounds less like a battery problem and more like a Xbee problem. I would, as @Matt said, test 1 thing at a time. That is, test your Xbee with something simple like a fixed message that has nothing to do with your sensor. Then, if it is a Xbee problem, change your question and question's title ... as you are attracting the wrong type of answer. Commented Nov 8, 2016 at 13:53

2 Answers 2

1

I have solved the problem by adding a delay just before I select the continuous measurement mode.

void setup(){
 //Initialize Serial and I2C communications
 Serial.begin(9600);
 Wire.begin();
 //Put the HMC5883 IC into the correct operating mode
 Wire.beginTransmission(address); //open communication with HMC5883
 Wire.send(0x02); //select mode register
 Wire.send(0x00); //continuous measurement mode
 delay(100);
 Wire.endTransmission();
} 
answered Nov 15, 2016 at 15:21
1
  • try delay(1). Acording to shared experiences, that delay is needed by it can be shorter. Commented Nov 12, 2017 at 8:55
0

There are 2 possible problems:

Lack of power or libraries not supporting each other.

1 - Try powering the circuit with some USB 5V. Make sure that your other modules can support 5V. Also check your clock speed. High clock speeds with low voltages might cause your ATmega to function incorrectly.

2 - Some libraries for certain module / breakout uses software I2C which pretty much emulate I2C. They might not be compatible with another module that needs the wire library to function proprely. To debug it, test out 1 module at the time with the battery.

answered Nov 8, 2016 at 12:53
3
  • Hey, I'm using wire.h library and reading the sensor directly from its registers. The batteries I use for the supply is a cellphone powerbank, so pretty much is the same if I connected the MCU with my PC. Commented Nov 8, 2016 at 13:47
  • 1
    Any other libraries? Commented Nov 8, 2016 at 15:11
  • 1
    No, just wire.h, I updated the question, so you can have an idea of my issue. Thanks for commenting. Commented Nov 8, 2016 at 15:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.