I am currently working on a project utilizing a GY-511 compass module, and a GT-U7 GPS module, my MCU is an Arduino DUE. The problem I am encountering is that when I add the line compass.read(); my code no longer outputs any data to the serial port. Now, I have tested with a compass code, and a GPS code matching both portions of the following sketch, I only get problems from compass.read(); when it is included with the GPS code. I should also mention that I am getting no errors from the debug console.
#include <Servo.h>
#include <TinyGPS++.h>
#include <LSM303.h>
#include <Wire.h>
//Object Declaration
Servo leftMotor;
Servo rightMotor;
LSM303 compass;
TinyGPSPlus gps;
//Global Variables
float bearing;
//Timers
int lastMillis;
int updateTimer;
int printTimer;
//GPS Data
double latitude;
double longitude;
double Altitude;
double speedKnots;
double speedMPS;
double Course;
int satelliteCount;
//GPS Positions
int homeTrigger;
double homeLatitude;
double homeLongitude;
//GPS Waypoint variables;
double waypoints[] = {};
void setup() {
Serial.begin(115200);
Serial.println("Serial communications established");
Serial1.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();
//Compass Calibration
compass.m_min = (LSM303::vector<int16_t>) {-381, +744, -1146};
compass.m_max = (LSM303::vector<int16_t>) {-372, +752, -1140};
}
void loop() {
while (Serial1.available() > 0){
gps.encode(Serial1.read());
}
if (gps.location.isUpdated()){
updateTimer = millis();
latitude = gps.location.lat();
longitude = gps.location.lng();
Altitude = gps.altitude.meters();
speedKnots = gps.speed.knots();
satelliteCount = gps.satellites.value();
}
updateCompass();
Serial.println(latitude, 8);
}
void updateCompass() {
compass.read();
}
I have tested with and without the compass module electrically connected and the results are the same.
My electrical connections are as follows:
TX1 --> GPS RX
RX1 --> GPS TX
3.3v --> GPS VCC
GND --> GPS GND
3.3v --> Compass 3.3v
GND --> Compass GND
SDA --> Compass SDA
SCL --> Compass SCL
Water_Rover.ino (1.32 KB)
