problems after including the software serial

Hello everybody,

I have a project that uses the gsm shield to send sms if heart rate is irregular and or the temperature high or low.

The sms sent says: HELP!

I tried to add the gps code to the original project so that in the sms message the location will be included as well.

But everytime I get the error exit status 1 and I have no idea what I am doing wrong.

Attached each code separately, and each of them are working fine.

I need help to combine them both

Best

at_high_or_low_body_temp_and_irregular_pulse_send_sms_at_a_fixe.ino (1.9 KB)

working_gps_fast.ino (2.71 KB)

But everytime I get the error exit status 1 and I have no idea what I am doing wrong.

Post the combined code that produces the error and the complete text of the error

If both sketches use SoftwareSerial then you will have a problem combining them. The SoftwareSerial library can only listen to one device at a time.

UKHeliBob:
Post the combined code that produces the error and the complete text of the error

This is the combined code:

#include <GSM.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

#define PINNUMBER ""

SoftwareSerial mySerial(10, 11);
TinyGPS gps;

void gpsdump(TinyGPS &gps);
void printFloat(double f, int digits = 2);

// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

char remoteNumber[20] = "0536393352";

// char array of the message
char txtMsg[200] = "HELP";

void setup()
{
mlx.begin();

// initialize serial communications
Serial.begin(9600);

Serial.println("SMS Messages Sender");

mySerial.begin(9600);
delay(1000);

// connection state
boolean notConnected = true;

// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
sendSMS();
}

int Signal; // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550; // Determine which Signal to "count as a beat", and which to ingore.

int PulseSensorPurplePin = 0;
double temp;

void loop() {
bool newdata = false;
unsigned long start = millis();
// Every 5 seconds we print an update
while (millis() - start < 5000)
{
if (mySerial.available())

{
char c = mySerial.read();
//Serial.print(c); // uncomment to see raw GPS data
if (gps.encode(c))
{
newdata = true;
break; // uncomment to print new data immediately!
}
}
}

temp = mlx.readObjectTempC();
Signal = analogRead(PulseSensorPurplePin); // Read the PulseSensor's value.
// Assign this value to the "Signal" variable.
Serial.println(Signal); // Send the Signal value to Serial Plotter.

if (temp > 40 || temp < 15 || Signal == 0) {

sendSMS();
Serial.print("temp is ");
Serial.print(temp);
}

/*else if (Signal == 0){
sendSMS();

}*/
delay(2500);
}

void sendSMS() {

Serial.print("Message to mobile number: ");
Serial.println(remoteNumber);

// sms text
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);

// send the message
sms.beginSMS(remoteNumber);

float flat, flon;
unsigned long age;
char str_flat[16], str_flon[16];
gps.f_get_position(&flat, &flon, &age);
dtostrf(flat, 5, 2, str_flat);
dtostrf(flon, 5, 2, str_flon);
sprintf(txtMsg, "Help, my location is %s %s", str_flat, str_flon);

sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
}

void gpsdump(TinyGPS &gps)
{
long lat, lon;
float flat, flon;
unsigned long age, date, time, chars;
int year;
byte month, day, hour, minute, second, hundredths;
unsigned short sentences, failed;

// On Arduino, GPS characters may be lost during lengthy Serial.print()
// On Teensy, Serial prints to USB, which has large output buffering and
// runs very fast, so it's not necessary to worry about missing 4800
// baud GPS characters.

gps.f_get_position(&flat, &flon, &age);
Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);
}

void printFloat(double number, int digits)
{
// Handle negative numbers
if (number < 0.0)
{
Serial.print('-');
number = -number;
}

// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i = 0; i < digits; ++i)
rounding /= 10.0;

number += rounding;

// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
Serial.print(int_part);

// Print the decimal point, but only if there are digits beyond
if (digits > 0)
Serial.print(".");

// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
Serial.print(toPrint);
remainder -= toPrint;
}
}

You could have done us all a favour and used code tag when you posted your code

Please post the full error message that you get when you compile the program

You should read How to use this forum. It describes posting your code, errors, and what information you should provide in your question, like WHAT ARDUINO ARE YOU USING?

You could have done us all a favour and indented the code. Press control-T in the IDE editor. :stuck_out_tongue:

You cannot use SoftwareSerial with that GSM library. To connect the GPS device, you can use

  • AltSoftSerial on pins 8 & 9 (for an UNO), or

  • Serial on pins 0 & 1. You must disconnect pin 0 from the GPS to upload new sketches via USB.

Here is a NeoGPS version of your sketch:

#include <GSM.h>
#include <Wire.h>
#include <NMEAGPS.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx;

#define PINNUMBER ""

//-------------
//  Uncomment one of these sections:

//     This:
//#include <AltSoftSerial.h>
//AltSoftSerial gpsPort; // RX on pin 8 (to GPS TX), TX on pin 9 (to GPS RX)

//   ... or this:
//#define gpsPort Serial  // GPS TX to RX pin 0 (disconnect to upload), GPS RX to TX pin 1
//-------------

NMEAGPS gps;      // NMEA parser object
gps_fix fix;      // structure that contains all parsed GPS fields
uint8_t fixCount; // how many fixes have been received (this is also a seconds count)

// initialize the GSM library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

char remoteNumber[20] = "0536393352";

void setup()
{
  mlx.begin();

  // initialize serial communications
  Serial.begin(9600);
  Serial.println( F("SMS Messages Sender") );

  gpsPort.begin(9600);
  delay(1000);

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (gsmAccess.begin(PINNUMBER) != GSM_READY)
  {
    Serial.println( F("Not connected") );
    delay(1000);
  }

  Serial.println( F("GSM initialized") );

  sendSMS();
}

int Signal; // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550; // Determine which Signal to "count as a beat", and which to ingore.

int PulseSensorPurplePin = 0;
double temp;

void loop()
{
  // Check for available GPS characters and parse them
  if (gps.available( gpsPort )) {

    //  Once per second, a complete GPS fix is ready.
    fix = gps.read(); // get all the GPS field values in one structure
    fixCount++;       // increment the seconds counter

    if (fixCount >= 10) {
      // once every 10 seconds, send an SMS

      temp = mlx.readObjectTempC();
      Signal = analogRead(PulseSensorPurplePin); // Read the PulseSensor's value.

      //Serial.print( F("Signal is ") );
      Serial.println(Signal); // Send the Signal value to Serial Plotter.

      if (temp > 40 || temp < 15 || Signal == 0) {

        sendSMS();

        Serial.print( F("temp is ") );
        Serial.println(temp);
      }

      fixCount = 0;  // reset seconds timer
    }
  }
}

void sendSMS() {

  Serial.print( F("Message to mobile number: ") );
  Serial.println(remoteNumber);

  // show the text we are going to send
  Serial.println( F("SENDING") );
  Serial.println();
  Serial.println( F("Message:") );
  printMessageTo( Serial );

  // send the SMS
  sms.beginSMS(remoteNumber);

  printMessageTo( sms );

  sms.endSMS();

  Serial.println( F("\nCOMPLETE!\n") );
}

void printMessageTo( Stream & output )
{
  output.print( F("Help") );

  if (fix.valid.location) {
    output.print( F(", my location is ") );
    output.print( fix.latitude(), 6 );
    output.print( ' ' );
    output.print( fix.longitude(), 6 );
  }
}

Notice how it is much more readable with spacing, and it takes fewer lines of code. By using the F macro in Serial prints, it also saves RAM.

NeoGPS is faster, smaller, more reliable and more accurate than all other GPS libraries. NeoGPS and AltSoftSerial are available from the Ardino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.