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

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

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

Postby DatBoyEvV » Wed Apr 25, 2012 8:39 am

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 11:01 am, edited 1 time in total.
DatBoyEvV
 
Posts: 4
Joined: Wed Apr 25, 2012 8:34 am

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

Postby franklin97355 » Wed Apr 25, 2012 10:17 am

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
franklin97355
 
Posts: 1705
Joined: Mon Apr 21, 2008 1:33 pm

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

Postby adafruit_support_bill » Wed Apr 25, 2012 11:28 am

It keeps saying i have and error compiling the program

It would help if you posted the text of the error too.
User avatar
adafruit_support_bill
 
Posts: 15898
Joined: Sat Feb 07, 2009 9:11 am

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

Postby DatBoyEvV » Wed Apr 25, 2012 11:44 am

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)'

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

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

Postby adafruit_support_bill » Wed Apr 25, 2012 12:17 pm

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 ".
User avatar
adafruit_support_bill
 
Posts: 15898
Joined: Sat Feb 07, 2009 9:11 am

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

Postby DatBoyEvV » Wed Apr 25, 2012 1:11 pm

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

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


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

Postby DatBoyEvV » Wed Apr 25, 2012 1:44 pm

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; 

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

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

Postby adafruit_support_bill » Wed Apr 25, 2012 1:51 pm

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);
User avatar
adafruit_support_bill
 
Posts: 15898
Joined: Sat Feb 07, 2009 9:11 am


Return to General Project help

Who is online

Users browsing this forum: mibignistinly and 10 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [105]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]