Pages: [1]   Go Down
Author Topic: Programme stuck in setup  (Read 155 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've put together some code to log GPS data and readings from a BMP180 pressure/temperature sensor, but the code gets stuck in the stetup function. Any ideas? Thanks!

Code:
#include <SPI.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <Wire.h>


Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

#if ARDUINO >= 100
  SoftwareSerial mySerial(3, 2);
#else
  NewSoftSerial mySerial(3, 2);
#endif
Adafruit_GPS GPS(&mySerial);

#define GPSECHO false
const int chipSelect = 10;
boolean usingInterrupt = false;
const int dec_place  = 100;

const int groundpin = 18;             // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis (only on 3-axis models)

void setup()
{
  Serial.begin(115200);
  Serial.println("Into Setup");
  bmp.begin();
  Serial.println("BMP complete");
 
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  Serial.println("GPS complete");
  delay(1000);
 
  mySerial.println(PMTK_Q_RELEASE);
  Serial.println("Beginning SD test");
  pinMode(10, OUTPUT);
  if (!SD.begin(chipSelect)){
      Serial.println("Recognition of SD card reader failed!");
      return;
  }
  Serial.println("SD test complete");
 
  String hdrstr = "Humidity (%)\tTemp (dht,*C)\tTemp (bmp,*C)\tPressure (hPa)\tAltitude (m)\tX Accel \tY Accel \tZ Accel \tIR\tFull\tVisible\tLux\tTime\tDate\tFix\tQuality\tLat\tLon\tSpeed (kt)\tAngle\tAltitude (ft)\tSatellites";
  //Serial.println(hdrstr);
  File hdrFile = SD.open("datalog.txt", FILE_WRITE);
  if (hdrFile) {
    hdrFile.println(hdrstr);
    hdrFile.close();
    Serial.println(hdrstr);
  }else{
    Serial.println("FAILURE!");
  }
  Serial.println("SD tgest complete"); 
}
uint32_t timer = millis();
void loop()
{
   if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) UDR0 = c;
      // writing direct to UDR0 is much much faster than Serial.print
      // but only one character can be written at a time.
  }
 
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
 
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }
  if (timer > millis())  timer = millis();

  // approximately every 5 seconds or so, print out the current stats
  if (millis() - timer > 5000) {
    Serial.println("INTO TIMER LOOP");
   
    timer = millis(); // reset the timer
    File dataFile = SD.open("datalog.txt", FILE_WRITE);
    if (dataFile) {
      //Write BMP data to file
      sensors_event_t event;
      bmp.getEvent(&event);
      dataFile.print("Pressure:    ");
      dataFile.print(event.pressure);
      dataFile.println(" hPa");
      float temperature;
      bmp.getTemperature(&temperature);
      dataFile.print("Temperature: ");
      dataFile.print(temperature);
      dataFile.println(" C");
      float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
      dataFile.print("Altitude:    ");
      dataFile.print(bmp.pressureToAltitude(seaLevelPressure,
                                        event.pressure,
                                        temperature));
      dataFile.println(" m");
      dataFile.println("");
      dataFile.print("\t");
      //Write GPS data to file
      dataFile.print(GPS.hour);
      dataFile.print(":");
      dataFile.print(GPS.minute);
      dataFile.print(":");
      dataFile.print(GPS.seconds);
      dataFile.print(".");
      dataFile.print(GPS.milliseconds);
      dataFile.print("\t");
      dataFile.print(GPS.day);
      dataFile.print("/");
      dataFile.print(GPS.month);
      dataFile.print("/20");
      dataFile.print(GPS.year);
      dataFile.print("\t");
      dataFile.print((int)GPS.fix);
      dataFile.print("\t");
      if (GPS.fix) {
        Serial.println("Fix Achieved!");
        dataFile.print((int)GPS.fixquality);
        dataFile.print("\t");
        dataFile.print(GPS.latitude);
        dataFile.print("\t");
        dataFile.print(GPS.lat);
        dataFile.print("\t");
        dataFile.print(GPS.longitude);
        dataFile.print("\t");
        dataFile.print(GPS.lon);
        dataFile.print("\t");
        dataFile.print(GPS.speed);
        dataFile.print("\t");
        dataFile.print(GPS.angle);
        dataFile.print("\t");
        dataFile.print(GPS.altitude);
        dataFile.print("\t");
        dataFile.println(GPS.satellites);
      }else {
        dataFile.println(GPS.fixquality);
      }
      dataFile.close();
      Serial.println("Wrote to file");
    }
  }
}
Logged

Cincinnati, OH
Offline Offline
God Member
*****
Karma: 49
Posts: 877
I'm not bossy...I just know what you should be doing.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know squat about the GPS library, but these two lines make me wonder...

Code:
  Serial.begin(115200);              // Serial com rate
  Serial.println("Into Setup");
  bmp.begin();
  Serial.println("BMP complete");
 
  GPS.begin(9600);                   // Same com rate???
Logged

Offline Offline
Edison Member
*
Karma: 49
Posts: 1670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does your debugging output tell you? It also might be worth telling us what it prints.

Pete
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the quick replies guys!

When I open up the serial monitor I get something like this:

Into Setup
Into Setup
Into Setup
BMP complete
IntïR‹½Setup
Into Setup
BMP complete
IntïR‹½Setup
Into Setup
BMP complete
IntïR‹½Setup
Into Setup
BMP complete
IntïR‹½Setup
Into Setup
BMP complete
IntïR‹½Setup
Into Setup
BMP complete
IntïR‹½Setup

and it is repeated like that. I've tried matching the com rates but I get the same results. Should I try something else to debug it?
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4339
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My best guess would be that you are running out of memory which will not be helped by the extensive use of String objects as opposed to C style strings.  As a first test reduce the length of hdrstr to a single character.  Do you get any different results ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Edison Member
*
Karma: 49
Posts: 1670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There's only one String object in the code. Change this:
Code:
String hdrstr =
to this:
Code:
char * hdrstr =

Pete
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah okay, interesting. I've changed it to "char * hdrstr =" and I do get somewhat different results, but I think I'm still low on memory. I'm getting this:

Into Setup
BMP complete
GPS complete
BeginnInto Setup
BMP complete
GPS complete
Beginning SD teInto Setup
BMP complete
GPS complete
Beginning SD teInto Setup
BMP complete
GPS complete
BeginnInto Setup

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also I'm using an Uno R3. Do I need a more powerful unit?
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4339
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Define what you mean by more powerful

More memory ?
Faster processor ?
More pins ?
More than one hardware serial port ?
etc, etc
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3741
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can save yourself some RAM by pushing constant serial printed strings into progmem. Change stuff like this:
Code:
  Serial.println("BMP complete");
to
Code:
  Serial.println(F("BMP complete"));
Logged

Pages: [1]   Go Up
Jump to: