I need help with getting my gps and bmp085 sensor working with arduino

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
DatBoyEvV
 
Posts: 4
Joined: Wed Apr 25, 2012 9:34 am

I need help with getting my gps and bmp085 sensor working with arduino

Post by DatBoyEvV »

I have been working with this for a couple of days and i can not get this program working. It keeps saying i have and error compiling the program.

Here is the program:

Code: Select all

#include <NewSoftSerial.h>
 #include <Wire.h>  
 #include <SD.h>  
 #include <Adafruit_BMP085.h>  
 #include <avr/sleep.h>  
 #include "GPSconfig.h"
 //#include <SoftwareSerial.h> 
 


 #define SLEEPDELAY 0  
 #define TURNOFFGPS 0  
 #define LOG_RMC_FIXONLY 0  


 #define GPSRATE 4800  

 #define powerPin 4  
 #define led1Pin 5  
 #define led2Pin 6  
 #define chipSelect 10  
 #define BUFFSIZE 90  
NewSoftSerial gpsSerial(2, 3);

 char buffer[BUFFSIZE];  
 uint8_t bufferidx = 0;  
 uint8_t fix = 0;
 uint8_t i,j,k;  
 char *parseptr;  
 float Temperature;  
 int32_t Pressure;  
 float lat,lon,temp;  
 char date[7];  
 char utc_time[10];  
 char alt[10];  
 File logfile;  

 Adafruit_BMP085 bmp;  
 
 uint8_t parseHex(char c) {  
  if (c < '0')  
   return 0;  
  if (c <= '9')  
   return c - '0';  
  if (c < 'A')  
   return 0;  
  if (c <= 'F')  
   return (c - 'A')+10;  
 }  

 void error(uint8_t errno) {  
  while(1) {  
   for (i=0; i<errno; i++) {  
    digitalWrite(led1Pin, HIGH);  
    digitalWrite(led2Pin, HIGH);  
    delay(100);  
    digitalWrite(led1Pin, LOW);  
    digitalWrite(led2Pin, LOW);  
    delay(100);  
   }  
   for (; i<10; i++) {  
    delay(200);  
   }  
  }  
 }  

 void readline(void) {  
  char c;  
  bufferidx = 0; 
  gpsSerial.read();
  while (1) {  
   c=gpsSerial.read();  
   if (c == -1)  
    continue;  
   if (c == '\n')  
    continue;  
   if ((bufferidx == BUFFSIZE-1) || (c == '\r')) {  
    buffer[bufferidx] = 0;  
    return;  
   }  
   buffer[bufferidx++]= c;  
  }  
 }  
 void setup() {  
  WDTCSR |= (1 << WDCE) | (1 << WDE);  
  WDTCSR = 0;  
  Serial.begin(9600);  
  Serial.println("\r\nGPS and BMP085 logger");  
  pinMode(led1Pin, OUTPUT);  
  pinMode(led2Pin, OUTPUT);  
  pinMode(powerPin, OUTPUT);  
  digitalWrite(powerPin, LOW);  

  pinMode(10, OUTPUT);  

  if (!SD.begin(chipSelect)) {  
   Serial.println("Card init. failed!");  
   error(1);  
  }  
  strcpy(buffer, "AQDLS.TXT");  
  for (i = 0; i < 100; i++) {  
   buffer[6] = '0' + i/10;  
   buffer[7] = '0' + i%10;  

   if (! SD.exists(buffer)) {  
    break;  
   }  
  }  
  logfile = SD.open(buffer, FILE_WRITE);  
  if( ! logfile ) {  
   Serial.print("Couldnt create ");   
   Serial.println(buffer);  
   error(3);  
  }  
  Serial.print("Writing to ");   
  Serial.println(buffer);  
  logfile.println("# A GPS track data file");  
  logfile.println("# UTC time  lat  lon  gps_alt  pressure temperature");  
  logfile.println("# hhmmss.sss deg  deg  m     hPa    C");  
  logfile.println("#");  
  
  gpsSerial.begin(GPSRATE);  
  Serial.println("Ready!");  
  gpsSerial.print(SERIAL_SET);  
  delay(250);  
  gpsSerial.print(GGA_ON);  
  delay(250);  
  
  gpsSerial.print(RMC_OFF);  
  delay(250);  

  gpsSerial.print(WAAS_ON);  
  bmp.begin();   
 }  
 void loop() {  
  char c;  
  uint8_t sum;  
  char *p;  

  readline();  
  Serial.print("raw line: ");  
  Serial.println(buffer);  

  sum = parseHex(buffer[bufferidx-2]) * 16;  
  sum += parseHex(buffer[bufferidx-1]);  
  Serial.print("Checksum:");  
  Serial.println(sum);  

  for (i=1; i < (bufferidx-3); i++) {  
   sum ^= buffer[i];  
  }  
  if (sum != 0) {  

   Serial.print('~');  
   bufferidx = 0;  
   return;  
  }  
  p = buffer;  
 
  p = strchr(p, ',')+1;  
  for (k=0;k<9;k++)  
   utc_time[k]=p[k];  
  Serial.print(" UTC time:");  
  Serial.println(utc_time);  

  p = strchr(p, ',')+1;  

  lat = (p[0]-'0')*10.0 + (p[1]-'0') + ((p[2]-'0')*10.0 + (p[3]-'0') + (p[5]-'0')/10.0 + (p[6]-'0')/100.0 + (p[7]-'0')/1000.0 + (p[8]-'0')/10000.0)/60.0;  

  p = strchr(p, ',')+1;  
  if (p[0]=='S')  
   lat *= -1.0;  
  Serial.print(" latitude:");  
  Serial.println(lat,7);  

  p = strchr(p, ',')+1;  
 
  lon = (p[0]-'0')*100.0 + (p[1]-'0')*10.0 + (p[2]-'0') + ((p[3]-'0')*10.0 + (p[4]-'0') + (p[6]-'0')/10.0 + (p[7]-'0')/100.0 + (p[8]-'0')/1000.0 + (p[9]-'0')/10000.0)/60.0;  
 
  p = strchr(p, ',')+1;  
  if (p[0]=='W')  
   lon *= -1.0;  
  Serial.print(" longitude:");  
  Serial.println(lon,7);  

  p = strchr(p, ',')+1;    
  if (p[0]=='0') {  
   fix = 0;   
   digitalWrite(led1Pin, LOW);  
  }  
  else {  
   fix = 1;  
   digitalWrite(led1Pin, HIGH);  
  }  

  p = strchr(p, ',')+1;  
  p = strchr(p, ',')+1;  
  p = strchr(p, ',')+1;  
  j=0;  
  while (p[j] != ',') {  
   alt[j] = p[j];   
   j++;  
  }  
  Serial.print(" alt:");  
  Serial.println(alt);  
  bufferidx = 0;  
 
  digitalWrite(led2Pin, HIGH); 
 
  logfile.print(date);  
  logfile.print(" ");  

  logfile.print(utc_time);  
  logfile.print(" ");  

  logfile.print(lat,7);  
  logfile.print(" ");  
 
  logfile.print(lon,7);  
  logfile.print(" ");  
 
  logfile.print(alt);  
  logfile.print(" ");  
  
  Temperature = bmp.readTemperature();  
  Serial.print("Temperature = ");  
  Serial.print(Temperature);  
  Serial.println(" C");  
  Pressure = bmp.readPressure();    
  Serial.print("Pressure = ");  
  Serial.print(Pressure);  
  Serial.println(" Pa");   

  logfile.print(" ");  
  logfile.print(Pressure);  
  logfile.print(" ");  

  logfile.println(Temperature);     
  logfile.flush();   
  digitalWrite(led2Pin, LOW);  

  if (TURNOFFGPS) {  
   digitalWrite(powerPin, HIGH);  
  }  
  delay(SLEEPDELAY * 1000);  
  digitalWrite(powerPin, LOW);  
  return;  
 }
Last edited by DatBoyEvV on Wed Apr 25, 2012 12:01 pm, edited 1 time in total.

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: I need help with getting my gps and bmp085 sensor working with arduino

Post by Franklin97355 »

With such long code it would make it more readable if you were to enclose it within "CODE" tags. You can go back and edit your existing post.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: I need help with getting my gps and bmp085 sensor working with arduino

Post by adafruit_support_bill »

It keeps saying i have and error compiling the program
It would help if you posted the text of the error too.

DatBoyEvV
 
Posts: 4
Joined: Wed Apr 25, 2012 9:34 am

Re: I need help with getting my gps and bmp085 sensor working with arduino

Post by DatBoyEvV »

Sorry about that

here is the error:

Code: Select all

 
Error compiling 
In file included from sketch_apr24a.cpp:1:
C:\Users\EVV\Desktop\arduino-1.0\libraries\NewSoftSerial/NewSoftSerial.h:71: error: conflicting return type specified for 'virtual void NewSoftSerial::write(uint8_t)'
C:\Users\EVV\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'


User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: I need help with getting my gps and bmp085 sensor working with arduino

Post by adafruit_support_bill »

Looks like you are using the Arduino 1.0 IDE. Starting with 1.0, the functionality of NewSoftSerial has been integrated as "SoftwareSerial". You should replace your "#include <NewSoftSerial.h>" with "#include <SoftwareSerial.h>". You should also remove the NewSoftSerial folder from your libraries folder to avoid conflicts.

Another problem you are likely to encounter has to do with: "#include <Adafruit_BMP085.h> ". Unless you renamed it when you installed it, the name of the file is just "BMP085.h ".

DatBoyEvV
 
Posts: 4
Joined: Wed Apr 25, 2012 9:34 am

Re: I need help with getting my gps and bmp085 sensor working with arduino

Post by DatBoyEvV »

I changed the " #include <NewSoftSerial.h>" to " #include <SoftwareSerial.h>" and took the NewSoftserial library out and now im getting this error

Code: Select all


'gpsSerial' was not declared in this scope

 sketch_apr24a.cpp: In function 'void readline()':
sketch_apr24a:69: error: 'gpsSerial' was not declared in this scope
sketch_apr24a.cpp: In function 'void setup()':
sketch_apr24a:121: error: 'gpsSerial' was not declared in this scope


User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: I need help with getting my gps and bmp085 sensor working with arduino

Post by adafruit_support_bill »

Did you change the type of gpsSerial from NewSoftSerial to SoftwareSerial?

DatBoyEvV
 
Posts: 4
Joined: Wed Apr 25, 2012 9:34 am

Re: I need help with getting my gps and bmp085 sensor working with arduino

Post by DatBoyEvV »

yes i did , here is the code

Code: Select all


 #include <Wire.h>  
 #include <SD.h>  
 #include <Adafruit_BMP085.h>  
 #include <avr/sleep.h>  
 #include "GPSconfig.h"
 #include <SoftwareSerial.h> 
 


 #define SLEEPDELAY 0  
 #define TURNOFFGPS 0  
 #define LOG_RMC_FIXONLY 0  


 #define GPSRATE 4800  

 #define powerPin 4  
 #define led1Pin 5  
 #define led2Pin 6  
 #define chipSelect 10  
 #define BUFFSIZE 90  


 char buffer[BUFFSIZE];  
 uint8_t bufferidx = 0;  
 uint8_t fix = 0;
 uint8_t i,j,k;  
 char *parseptr;  
 float Temperature;  
 int32_t Pressure;  
 float lat,lon,temp;  
 char date[7];  
 char utc_time[10];  
 char alt[10];  
 File logfile;  

 Adafruit_BMP085 bmp;  
 
 uint8_t parseHex(char c) {  
  if (c < '0')  
   return 0;  
  if (c <= '9')  
   return c - '0';  
  if (c < 'A')  
   return 0;  
  if (c <= 'F')  
   return (c - 'A')+10;  
 }  

 void error(uint8_t errno) {  
  while(1) {  
   for (i=0; i<errno; i++) {  
    digitalWrite(led1Pin, HIGH);  
    digitalWrite(led2Pin, HIGH);  
    delay(100);  
    digitalWrite(led1Pin, LOW);  
    digitalWrite(led2Pin, LOW);  
    delay(100);  
   }  
   for (; i<10; i++) {  
    delay(200);  
   }  
  }  
 }  

 void readline(void) {  
  char c;  
  bufferidx = 0; 
  gpsSerial.read();
  while (1) {  
   c=gpsSerial.read();  
   if (c == -1)  
    continue;  
   if (c == '\n')  
    continue;  
   if ((bufferidx == BUFFSIZE-1) || (c == '\r')) {  
    buffer[bufferidx] = 0;  
    return;  
   }  
   buffer[bufferidx++]= c;  
  }  
 }  
 void setup() {  
  WDTCSR |= (1 << WDCE) | (1 << WDE);  
  WDTCSR = 0;  
  Serial.begin(9600);  
  Serial.println("\r\nGPS and BMP085 logger");  
  pinMode(led1Pin, OUTPUT);  
  pinMode(led2Pin, OUTPUT);  
  pinMode(powerPin, OUTPUT);  
  digitalWrite(powerPin, LOW);  

  pinMode(10, OUTPUT);  

  if (!SD.begin(chipSelect)) {  
   Serial.println("Card init. failed!");  
   error(1);  
  }  
  strcpy(buffer, "AQDLS.TXT");  
  for (i = 0; i < 100; i++) {  
   buffer[6] = '0' + i/10;  
   buffer[7] = '0' + i%10;  

   if (! SD.exists(buffer)) {  
    break;  
   }  
  }  
  logfile = SD.open(buffer, FILE_WRITE);  
  if( ! logfile ) {  
   Serial.print("Couldnt create ");   
   Serial.println(buffer);  
   error(3);  
  }  
  Serial.print("Writing to ");   
  Serial.println(buffer);  
  logfile.println("# A GPS track data file");  
  logfile.println("# UTC time  lat  lon  gps_alt  pressure temperature");  
  logfile.println("# hhmmss.sss deg  deg  m     hPa    C");  
  logfile.println("#");  
  
  gpsSerial.begin(GPSRATE);  
  Serial.println("Ready!");  
  gpsSerial.print(SERIAL_SET);  
  delay(250);  
  gpsSerial.print(GGA_ON);  
  delay(250);  
  
  gpsSerial.print(RMC_OFF);  
  delay(250);  

  gpsSerial.print(WAAS_ON);  
  bmp.begin();   
 }  
 void loop() {  
  char c;  
  uint8_t sum;  
  char *p;  

  readline();  
  Serial.print("raw line: ");  
  Serial.println(buffer);  

  sum = parseHex(buffer[bufferidx-2]) * 16;  
  sum += parseHex(buffer[bufferidx-1]);  
  Serial.print("Checksum:");  
  Serial.println(sum);  

  for (i=1; i < (bufferidx-3); i++) {  
   sum ^= buffer[i];  
  }  
  if (sum != 0) {  

   Serial.print('~');  
   bufferidx = 0;  
   return;  
  }  
  p = buffer;  
 
  p = strchr(p, ',')+1;  
  for (k=0;k<9;k++)  
   utc_time[k]=p[k];  
  Serial.print(" UTC time:");  
  Serial.println(utc_time);  

  p = strchr(p, ',')+1;  

  lat = (p[0]-'0')*10.0 + (p[1]-'0') + ((p[2]-'0')*10.0 + (p[3]-'0') + (p[5]-'0')/10.0 + (p[6]-'0')/100.0 + (p[7]-'0')/1000.0 + (p[8]-'0')/10000.0)/60.0;  

  p = strchr(p, ',')+1;  
  if (p[0]=='S')  
   lat *= -1.0;  
  Serial.print(" latitude:");  
  Serial.println(lat,7);  

  p = strchr(p, ',')+1;  
 
  lon = (p[0]-'0')*100.0 + (p[1]-'0')*10.0 + (p[2]-'0') + ((p[3]-'0')*10.0 + (p[4]-'0') + (p[6]-'0')/10.0 + (p[7]-'0')/100.0 + (p[8]-'0')/1000.0 + (p[9]-'0')/10000.0)/60.0;  
 
  p = strchr(p, ',')+1;  
  if (p[0]=='W')  
   lon *= -1.0;  
  Serial.print(" longitude:");  
  Serial.println(lon,7);  

  p = strchr(p, ',')+1;    
  if (p[0]=='0') {  
   fix = 0;   
   digitalWrite(led1Pin, LOW);  
  }  
  else {  
   fix = 1;  
   digitalWrite(led1Pin, HIGH);  
  }  

  p = strchr(p, ',')+1;  
  p = strchr(p, ',')+1;  
  p = strchr(p, ',')+1;  
  j=0;  
  while (p[j] != ',') {  
   alt[j] = p[j];   
   j++;  
  }  
  Serial.print(" alt:");  
  Serial.println(alt);  
  bufferidx = 0;  
 
  digitalWrite(led2Pin, HIGH); 
 
  logfile.print(date);  
  logfile.print(" ");  

  logfile.print(utc_time);  
  logfile.print(" ");  

  logfile.print(lat,7);  
  logfile.print(" ");  
 
  logfile.print(lon,7);  
  logfile.print(" ");  
 
  logfile.print(alt);  
  logfile.print(" ");  
  
  Temperature = bmp.readTemperature();  
  Serial.print("Temperature = ");  
  Serial.print(Temperature);  
  Serial.println(" C");  
  Pressure = bmp.readPressure();    
  Serial.print("Pressure = ");  
  Serial.print(Pressure);  
  Serial.println(" Pa");   

  logfile.print(" ");  
  logfile.print(Pressure);  
  logfile.print(" ");  

  logfile.println(Temperature);     
  logfile.flush();   
  digitalWrite(led2Pin, LOW);  

  if (TURNOFFGPS) {  
   digitalWrite(powerPin, HIGH);  
  }  
  delay(SLEEPDELAY * 1000);  
  digitalWrite(powerPin, LOW);  
  return;  
 }  

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: I need help with getting my gps and bmp085 sensor working with arduino

Post by adafruit_support_bill »

No, it looks like you deleted the declaration entirely. In your previous posted code you had it declared as:

Code: Select all

    NewSoftSerial gpsSerial(2, 3);
In the last post there is no declaration at all. You need to add it back in as:

Code: Select all

    SoftwareSerial gpsSerial(2, 3);

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”