Ok good news. Seems the inside testing was the problem. I have finally got a fix. I didn't realize that the antenna is so weak.
Anyway: Here's the code I use:
#include <SoftwareSerial.h>
SoftwareSerial GPS(3, 5);
byte gps_set_sucess = 0 ;
char gpssentence[66];
void setup()
{
GPS.begin(9600);
// START OUR SERIAL DEBUG PORT
Serial.begin(9600);
Serial.println("GPS Level Convertor Board Test Script");
Serial.println("03/06/2012 2E0UPU");
Serial.println("Initialising....");
//
// THE FOLLOWING COMMAND SWITCHES MODULE TO 4800 BAUD
// THEN SWITCHES THE SOFTWARE SERIAL TO 4,800 BAUD
//
GPS.print("$PUBX,41,1,0007,0003,4800,0*13\r\n");
GPS.begin(4800);
GPS.flush();
// THIS COMMAND SETS FLIGHT MODE AND CONFIRMS IT
Serial.println("Setting uBlox nav mode: ");
uint8_t setNav[] = {
0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00,
0x05, 0x00, 0xFA, 0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC };
while(!gps_set_sucess)
{
sendUBX(setNav, sizeof(setNav)/sizeof(uint8_t));
gps_set_sucess=getUBX_ACK(setNav);
}
gps_set_sucess=0;
//ADDED THIS//////////////////////////////////////////////////////////////////////////////////////
GPS.println("$PUBX,40,GLL,0,0,0,0*5C");
GPS.println("$PUBX,40,GGA,0,0,0,0*5A");
GPS.println("$PUBX,40,GSA,0,0,0,0*4E");
GPS.println("$PUBX,40,RMC,0,0,0,0*47");
GPS.println("$PUBX,40,GSV,0,0,0,0*59");
GPS.println("$PUBX,40,VTG,0,0,0,0*5E");
////////////////////////////////////////////////////////////////////////////////////////////////////
}
void loop()
{
//ADDED THIS////////////////////////////////////////////////////////////////////////////////////
GPS.println(F("$PUBX,00*33"));
unsigned long previousMillis = millis();
unsigned long currentMillis = millis();
while (currentMillis - previousMillis <= 3000) {
// wait for GPS sentence to arrive
currentMillis = millis();
}
while (GPS.available())
{
for (int i=0; i <66 ; i++)
{
gpssentence[i] = GPS.read();
}
}
}
// Send a byte array of UBX protocol to the GPS
void sendUBX(uint8_t *MSG, uint8_t len) {
for(int i=0; i<len; i++) {
GPS.write(MSG[i]);
Serial.print(MSG[i], HEX);
}
GPS.println();
}
// Calculate expected UBX ACK packet and parse UBX response from GPS
boolean getUBX_ACK(uint8_t *MSG) {
uint8_t b;
uint8_t ackByteID = 0;
uint8_t ackPacket[10];
unsigned long startTime = millis();
Serial.print(" * Reading ACK response: ");
// Construct the expected ACK packet
ackPacket[0] = 0xB5; // header
ackPacket[1] = 0x62; // header
ackPacket[2] = 0x05; // class
ackPacket[3] = 0x01; // id
ackPacket[4] = 0x02; // length
ackPacket[5] = 0x00;
ackPacket[6] = MSG[2]; // ACK class
ackPacket[7] = MSG[3]; // ACK id
ackPacket[8] = 0; // CK_A
ackPacket[9] = 0; // CK_B
// Calculate the checksums
for (uint8_t i=2; i<8; i++) {
ackPacket[8] = ackPacket[8] + ackPacket[i];
ackPacket[9] = ackPacket[9] + ackPacket[8];
}
while (1) {
// Test for success
if (ackByteID > 9) {
// All packets in order!
Serial.println(" (SUCCESS!)");
return true;
}
// Timeout if no valid response in 3 seconds
if (millis() - startTime > 3000) {
Serial.println(" (FAILED!)");
return false;
}
// Make sure data is available to read
if (GPS.available()) {
b = GPS.read();
// Check that bytes arrive in sequence as per expected ACK packet
if (b == ackPacket[ackByteID]) {
ackByteID++;
Serial.print(b, HEX);
}
else {
ackByteID = 0; // Reset and look again, invalid order
}
}
}
}
I have 2 questions:
-
Have I set the GPS to altitude mode correctly (->Will this work if i stick it in a HAB balloon?)
-
When I print the "gpssentence[]" Buffer I always get some corrupted characters. It usually looks something like this:
$PUBX,00,154106.00,4732.65609,N,00733.55878,E,364.181,G3,12,19,���,
So normally this wouldn't irritate me in the least as no actual data is ever corrupted. However I want to use this sentence in a CSV file, meaning that every gps sentence should have the same number of commas in it. However, often they do not. So what could I do to solve this problem? I do not want to parse any of the sentence. I want it raw, and also I don't whant to use any libraries (seeing as I've already got memory problems in my project)