Pages: [1]   Go Down
Author Topic: Problems using multiple libraries .... Arduino Crash!  (Read 839 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to build a small project to take Record GPS and Temperature data onto an SD Card.

The GPS works by itself.
The Temperature Sensor works by itself.
The SD Card works by itself. 
All together it crashes the Arduino with random characters going across the screen or general lock-up.

Here are the libraries I'm using.  Also I show where I can comment out the temperature sensor and write only GPS data to the SD card.

#include <SD.h>  // FOR SD Card
#include <SoftwareSerial.h> // For GPS
#include <TinyGPS.h>           // For GPS
#include <OneWire.h>   // Commenting this and all assoc code stops lockup.
#include <DallasTemperature.h>  // Commenting this and all assoc code stops lockup.

Any ideas why stuff crashes with that combination of libraries and how to fix it?
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Out of memory? Search the site for the freemem code.
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i would also out of mem; i ran int othe same thing with a huge int array and the TVout library on a uno
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

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

I am a programming novice and not sure how to clear out the unused memory. I don't really care about optimal performance just that it can work for a couple of hours without crashing.   Below is my loop function which I assembled looking at the examples on my sensors.  Any advice on how to use that library to make my program work?   


void loop()
{
  bool newdata = false;
  unsigned long start = millis();
 
  // Every second we print an update
  while (millis() - start < 1000)
  {
    if (feedgps())
      newdata = true;
  }
 
  // Get Temperature data
  sensors.requestTemperatures(); 
  float temp1c = sensors.getTempCByIndex(0); 
  float temp1f=temp1c*1.8+32;

  // GET PRESSURE Data
  int raw = 0;
  for (int i=0; i<16; i++){
    raw += analogRead(A0);
  }
  raw /=16;
  float cooked = cook(raw);

  // Define - get GPS data
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  gps.f_get_position(&flat, &flon, &age);

  // print Serial Data in CSV format for screen
  print_date(gps);
  Serial.print(", ");
  Serial.print(temp1c);
  Serial.print(", ");
  Serial.print(temp1f); 
  Serial.print(", ");
  //Serial.print("PSI");  // Temp PSI placeholder
  Serial.print(cooked, 2); 
  Serial.print(",   ");
  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 2);
  Serial.print(",    ");
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5);
  Serial.print(", ");
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 9, 4);
  Serial.print(", ");
  print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2);
  Serial.print(", ");
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  Serial.print(", ");
  print_float(gps.f_speed_mph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
  Serial.print(", ");
  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
  Serial.println();


  // Write same data to file in CSV format
  // Ignore print_ functions for complexity
  myFile = SD.open("HEROCKET.CSV", FILE_WRITE);
  if (myFile) {
    fprint_date(myFile, gps);
    myFile.print(", ");
    myFile.print(temp1c); 
    myFile.print(", ");
    myFile.print(temp1f); 
    myFile.print(", ");
    //myFile.print("PSI");  // Temp PSI placeholder
    myFile.print(cooked, 2); 
    myFile.print(",   ");
    //print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 2);
    myFile.print(gps.satellites());
    myFile.print(",    ");
    //print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5);
    myFile.print(flat);
    myFile.print(", ");
    //print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 9, 4);
    myFile.print(flon);
    myFile.print(", ");
    //print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2);
    myFile.print(gps.f_altitude());
    myFile.print(", ");
    //print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
    myFile.print(gps.f_course());
    myFile.print(", ");
    //print_float(gps.f_speed_mph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
    myFile.print(gps.f_speed_mph());
    myFile.print(", ");
    //print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
    myFile.print(TinyGPS::cardinal(gps.f_course()));
    myFile.println();
  }
  myFile.close();

}
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

a good way is to get rid of any excessive integers and or replace then with a byte if possible. but you dont really have any...
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It may not be the actual sketch, which you should post all of, by the way. The SD library takes a lot of SRAM on its own. The conbination of libraries you are using might just not fit.
Logged

Pages: [1]   Go Up
Jump to: