Greenhouse monitoring system project

Hello!

I am working on a monitoring system that displays the temperature and humidity of 10 different houses using a mega. For some reason, after some random time (sometimes 2 hours sometimes 1 day), it freezes. In each greenhouse, there is a sensor (Adafruit HTU21D-F Temperature & Humidity Sensor ) and an OLED display (similar to this in amazon: Diymall 0.96" Inch Blue and Yellow I2c IIC Serial Oled LCD LED Module 12864 128X64 for Arduino Display Raspberry PI 51 Msp420 Stim32 SCR). Both the oled and sensor are attached to a differential i2c breakout board. From there, they are connected to another differential i2c breakout board, and then a SparkFun Qwiic Mux Breakout - 8 Channel (TCA9548A). I have attached pictures of the hardware, connections, and code. Any ideas? Thanks!

41vSEw5FNuL.jpg

racs24:
Any ideas? Thanks!

Guesses, sure.

With the greenhouses at 2 miles apart the wiring is bound to be dodgy.

racs24:
Hello!
I have attached ..... code.

This may be an important part.

Did you consider transmitting the data wireless?

dave-in-nj:
This may be an important part.

#include <Wire.h>
#include "Wire.h"
#include "Adafruit_HTU21DF.h"
#include <SPI.h>
#include <SoftwareSerial.h>
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}
#include "Adafruit_FONA.h"
int textingsignal = 1; 
#define FONA_RX 2
#define FONA_TX 10
#define FONA_RST 4



#include <OLED_I2C.h>
#include <SD.h>
#include <DS1302.h>
DS1302 rtc(32, 33, 34);
Time t;
OLED  myOLED(SDA, SCL, 8);
const int chipSelect = 53;
File myFile;
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];     
extern uint8_t BigNumbers[];

// this is a large buffer for replies
char replybuffer[255]; 

// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines 
// and uncomment the HardwareSerial line
//#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

// Hardware serial is also possible!
//  HardwareSerial *fonaSerial = &Serial1;

// Use this for FONA 800 and 808s
//Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// Use this one for FONA 3G
Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

uint8_t type;
#define TCAADDR 0x70 // mux 1 #define TCAADDR 0x70 // mux 1 
#define TCAADDR2 0x71 // mux 2 #define TCAADDR 0x71 // mux 2 
#define TCAADDR3 0x72 // mux 3 #define TCAADDR 0x72 // mux 3
#define TCAADDR4 0x73 // mux 4 #define TCAADDR 0x73 // mux 4
// Connect Vin to 3-5VDC
// Connect GND to ground
// Connect SCL to I2C clock pin (A5 on UNO)
// Connect SDA to I2C data pin (A4 on UNO)

Adafruit_HTU21DF htu = Adafruit_HTU21DF();
// array of temperature designated by [ ] when calling call from 0-9 for an array of size 10
float temperature[10]= {-1, -1, -1, -1, -1,-1,-1,-1,-1,-1};
float humidity[10]= {-1, -1, -1, -1, -1,-1,-1,-1,-1,-1};
float humiditymax[10]={60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0};
float humiditymin[10]={24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0,  24.0, 24.0, 24.0};
//temperature max is 100F and min is 60F
float temperaturemax[10]={37.8, 37.8, 37.8, 37.8, 37.8, 37.8, 37.8, 37.8, 37.8, 37.8};
float temperaturemin[10]={15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55};
//temp below  60 above 100

int heart= 12;
const int heartwrite = 49;
int pushbtcount = -1; 
const int buttonPin = 19; //reverse button
const int buttonPin2 = 18;//forward button
int buttonStateForward = 0;  
int buttonStateReverse = 0; 
int buttonState = 0;  
int buttonState2 = 0;  
int printtofile=0;
int debounceDelay= 50;
int lastDebounceTime=0;
//if temp too high/low, send notification every 12 hrs(in millis) until resolved
const unsigned long lowTempNotification= 43200000;
const unsigned long highTempNotification= 43200000;
const unsigned long batteryBackupNotification = 43200000;
unsigned long startTimeHigh;
unsigned long currentTimeHigh;
unsigned long startTimeLow;
unsigned long currentTimeLow;
unsigned long startTimeBattery;
unsigned long currentTimeBattery;
int lastCheckHigh = 0;
int lastCheckLow = 0;
//reference voltage(5V) and pin battery is connected to (A0)
const int batteryPin=0;
const float referenceVolts = 5.0;
//power ON/OFF flag
int powerDown = 0;


void heartbeat(){
  digitalWrite(heart,HIGH);
  delay(15);
  digitalWrite(heart,LOW);
  delay(15);
}
void heartwriter(){
  digitalWrite(heartwrite,HIGH);
  delay(15);
  digitalWrite(heartwrite,LOW);
  delay(15);
}

void checkConditions(float humidity[], float temperature[], float humiditymax[], float humiditymin[],
float temperaturemax[], float temperaturemin[]);

dave-in-nj:
This may be an important part.

void setup() {
            Wire.begin(); // Initiate the Wire library
            Serial.begin(9600);
            tcaselect(7);
            tcaselect2(7);
            tcaselect3(7);
            tcaselect4(7);
            myOLED.begin();
            htu.begin();

          Serial.print("Initializing SD card...");
          // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
          // Note that even if it's not used as the CS pin, the hardware SS pin 
          // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
          // or the SD library functions will not work. 
           pinMode(SS, OUTPUT);
           
          if (!SD.begin(chipSelect)) {
            Serial.println("initialization failed!");
            return;
          }
          Serial.println("initialization done.");
  
          rtc.halt(false);
          rtc.writeProtect(false);

          // The following lines can be commented out to use the values already stored in the DS1302
          //  rtc.setDOW(MONDAY);        // Set Day-of-Week to FRIDAY
          //  rtc.setTime(1, 03, 0);     // Set the time to 12:00:00 (24hr format)
            //rtc.setDate(5, 2, 2018);   // Set the date to August 6th, 2010 day/month/year
            
           Serial.println(F("FONA basic test"));
           Serial.println(F("Initializing....(May take 3 seconds)"));
          
          fonaSerial->begin(4800);
          if (! fona.begin(*fonaSerial)) {
            Serial.println(F("Couldn't find FONA"));
            while (1);
          }
          type = fona.type();
          Serial.println(F("FONA is OK"));
          Serial.print(F("Found "));
          switch (type) {
                case FONA800L:
                  Serial.println(F("FONA 800L")); break;
                case FONA800H:
                  Serial.println(F("FONA 800H")); break;
                case FONA808_V1:
                  Serial.println(F("FONA 808 (v1)")); break;
                case FONA808_V2:
                  Serial.println(F("FONA 808 (v2)")); break;
                case FONA3G_A:
                  Serial.println(F("FONA 3G (American)")); break;
                case FONA3G_E:
                  Serial.println(F("FONA 3G (European)")); break;
                default: 
                  Serial.println(F("???")); break;
           }
  
          // Print module IMEI number.
          char imei[16] = {0}; // MUST use a 16 character buffer for IMEI!
          uint8_t imeiLen = fona.getIMEI(imei);
          if (imeiLen > 0) {
            Serial.print("Module IMEI: "); Serial.println(imei);
          }

                    // Optionally configure a GPRS APN, username, and password.
                    // You might need to do this to access your network's GPRS/data
                    // network.  Contact your provider for the exact APN, username,
                    // and password values.  Username and password are optional and
                    // can be removed, but APN is required.
                    fona.setGPRSNetworkSettings(F("hologram"), F("your username"), F("your password"));
                  
                    // Optionally configure HTTP gets to follow redirects over SSL.
                    // Default is not to follow SSL redirects, however if you uncomment
                    // the following line then redirects over SSL will be followed.
                    //fona.setHTTPSRedirect(true);
                  
                   
                 
                  pinMode(heart,OUTPUT);
                  pinMode(heartwrite,OUTPUT);
                  Wire.begin();
                 
                    delay(10);
                  // Serial.println("\ndone");   
                   startTimeHigh = millis();
                   startTimeLow = millis();
}

dave-in-nj:
This may be an important part.

//begin recording information
void loop() {
delay(5000);

            currentTimeHigh = millis();
            currentTimeLow = millis();
            ///////////////send data from sensors to the lath house , main room, green house 1 and 2 ////////////
            // Ex. tcaselect(1) is option 1 temperature/humidity reading, tcaselect(2) is option 2  temperature/humidity reading..etc
            //total 10 options/readings, mux1 reads from sensors 0-3, mux2 reads from sensors 4-7, mux3 reads from sensors 8 & 9
            //mux1
            tcaselect2(1);
            temperature[0] = htu.readTemperature();
            humidity[0] = htu.readHumidity();
            
            tcaselect2(2);
            temperature[1] = htu.readTemperature();
            humidity[1] = htu.readHumidity();
            
            tcaselect(3);
            temperature[2] = htu.readTemperature();
            humidity[2] = htu.readHumidity();
            
            tcaselect(4);
            temperature[3] = htu.readTemperature();
            humidity[3] = htu.readHumidity();
            
            //// mux 2
            tcaselect2(1);
            temperature[4] = htu.readTemperature();
            humidity[4] = htu.readHumidity();
            
            tcaselect2(2);
            temperature[5] = htu.readTemperature();
            humidity[5] = htu.readHumidity();
            
            tcaselect2(3);
            temperature[6] = htu.readTemperature();
            humidity[6] = htu.readHumidity();
            
            tcaselect2(4);
            temperature[7] = htu.readTemperature();
            humidity[7] = htu.readHumidity();
            
            //// mux 3
            tcaselect3(1);
            temperature[8] = htu.readTemperature();
            humidity[8] = htu.readHumidity();
            
            tcaselect3(2);
            temperature[9] = htu.readTemperature();
            humidity[9] = htu.readHumidity();
// Display humidity and temperature number, Ex. "Humidity # 1"//////////////////////
for(int i=0;i< 2; i++){
  Serial.print("Humidity #");
  Serial.print (i); 

  Serial.print(humidity[0]);
   Serial.print (",");
  Serial.print(humidity[1]);
   }

Serial.println("");

for(int j=0;j< 10; j++){
  //Serial.print("Temperature #");
  //Serial.print (j); 
  Serial.print(temperature[j]); 
  Serial.print (",");

}

checkConditions(humidity, temperature, humiditymax, humiditymin, temperaturemax, temperaturemin);
voltageMonitor();


//display in each OLED
//mux1
tcaselect(1);
            myOLED.begin();
            myOLED.setFont(SmallFont); //font size
            myOLED.print("F1", LEFT, 0); 
            myOLED.print("Temperature1: ", LEFT, 24);//labels displayed on screen, Ex. "Temperature1: " 
            myOLED.print("Humidity1: ", LEFT, 48); // Ex. "Humidity1: "
            myOLED.update();
            
            myOLED.setFont(BigNumbers);
            myOLED.printNumF(humidity[0],2,RIGHT,40); //display data next to labels, temperature & humidity
            myOLED.update(); 
            myOLED.setFont(BigNumbers);
            //fahrenheit conversion, for celsius just delete conversion
            myOLED.printNumF((temperature[0]* 9.0)/ 5.0 + 32.0,2,RIGHT,0);
            myOLED.update(); 
    
tcaselect(2);
          myOLED.begin();
            myOLED.clrScr();
            myOLED.setFont(SmallFont);
            myOLED.print("F2", LEFT, 0);
            myOLED.print("Temperature2 ", LEFT, 24);
            myOLED.print("Humidity2 ", LEFT, 48);
            myOLED.update();
           
            myOLED.setFont(BigNumbers);
            myOLED.printNumF(humidity[1],2,RIGHT,40);
            myOLED.update(); 
            myOLED.setFont(BigNumbers);
            myOLED.printNumF((temperature[1]* 9.0)/ 5.0 + 32.0,2,RIGHT,0);
            myOLED.update(); 


tcaselect(3);
            myOLED.begin();
            myOLED.clrScr();
            myOLED.setFont(SmallFont);
            myOLED.print("F3", LEFT, 0);
            myOLED.print("Temperature3 ", LEFT, 24);
            myOLED.print("Humidity3 ", LEFT, 48);
            myOLED.update();
       
            myOLED.setFont(BigNumbers);
            myOLED.printNumF(humidity[2],2,RIGHT,40);
            myOLED.update(); 
            myOLED.setFont(BigNumbers);
            myOLED.printNumF((temperature[2]* 9.0)/ 5.0 + 32.0,2,RIGHT,0);
            myOLED.update(); 
        

tcaselect(4);
            myOLED.begin();
            myOLED.clrScr();
            myOLED.setFont(SmallFont);
            myOLED.print("F4", LEFT, 0);
            myOLED.print("Temperature4 ", LEFT, 24);
            myOLED.print("Humidity4 ", LEFT, 48);
            myOLED.update();
           
            myOLED.setFont(BigNumbers);
            myOLED.printNumF(humidity[3],2,RIGHT,40);
            myOLED.update(); 
            myOLED.setFont(BigNumbers);
            myOLED.printNumF((temperature[3]* 9.0)/ 5.0 + 32.0,2,RIGHT,0);
            myOLED.update(); 

//// mux 2
tcaselect2(1);
            myOLED.begin();
            myOLED.clrScr();
            myOLED.setFont(SmallFont);
            myOLED.print("F5", LEFT, 0);
            myOLED.print("Temperature5 ", LEFT, 24);
            myOLED.print("Humidity5 ", LEFT, 48);
            myOLED.update();
       
            myOLED.setFont(BigNumbers);
            myOLED.printNumF(humidity[4],2,RIGHT,40);
            myOLED.update(); 
            myOLED.setFont(BigNumbers);
            myOLED.printNumF((temperature[4]* 9.0)/ 5.0 + 32.0,2,RIGHT,0);
            myOLED.update(); 
tcaselect2(2);
            myOLED.begin();
            myOLED.clrScr();
            myOLED.setFont(SmallFont);
            myOLED.print("F6", LEFT, 0);
            myOLED.print("Temperature6 ", LEFT, 24);
            myOLED.print("Humidity6 ", LEFT, 48);
            myOLED.update();
       
            myOLED.setFont(BigNumbers);
            myOLED.printNumF(humidity[5],2,RIGHT,40);
            myOLED.update(); 
            myOLED.setFont(BigNumbers);
            myOLED.printNumF((temperature[5]* 9.0)/ 5.0 + 32.0,2,RIGHT,0);
            myOLED.update(); 

tcaselect2(3);
            myOLED.begin();
            myOLED.clrScr();
            myOLED.setFont(SmallFont);
            myOLED.print("F7", LEFT, 0);
            myOLED.print("Temperature7 ", LEFT, 24);
            myOLED.print("Humidity7 ", LEFT, 48);
            myOLED.update();
            
            myOLED.setFont(BigNumbers);
            myOLED.printNumF(humidity[6],2,RIGHT,40);
            myOLED.update(); 
            myOLED.setFont(BigNumbers);
            myOLED.printNumF((temperature[6]* 9.0)/ 5.0 + 32.0,2,RIGHT,0);
            myOLED.update(); 
tcaselect2(4);
            myOLED.begin();
            myOLED.clrScr();
            myOLED.setFont(SmallFont);
            myOLED.print("F8", LEFT, 0);
            myOLED.print("Temperature8 ", LEFT, 24);
            myOLED.print("Humidity8 ", LEFT, 48);
            myOLED.update();
          
            myOLED.setFont(BigNumbers);
            myOLED.printNumF(humidity[7],2,RIGHT,40);
            myOLED.update(); 
            myOLED.setFont(BigNumbers);
            myOLED.printNumF((temperature[7]* 9.0)/ 5.0 + 32.0,2,RIGHT,0);
            myOLED.update();

dave-in-nj:
This may be an important part.

// time till printing on sd card, (recording data every 1 second for each sensor(0-9))
printtofile++;
if(printtofile == 1000){
  for(int t ; t>=9; t++){
      sensorwritesd(t);
  }
    printtofile=0;
}
  printtofile++;

} // end of loop 


///////////////////////////////////////////////////////////////////////////////////////////////////////////
//choose which mux to transmit data from, Ex. mux1, mux2, mux3 or mux4////////////////////////////////////////////
void tcaselect(uint8_t i) {   
      // set the mux we want to the correct loacation// reading from mux1, disable other muxes
      if (i > 7) return;
          Wire.beginTransmission(TCAADDR);
          Wire.write(1 << i);
          Wire.endTransmission(); 
             //disable all other muxes
             Wire.beginTransmission(TCAADDR2);
             Wire.write(0); // no channel selected
             Wire.endTransmission();
             Wire.beginTransmission(TCAADDR3);
             Wire.write(0); // no channel selected
             Wire.endTransmission();
             Wire.beginTransmission(TCAADDR4);
             Wire.write(0); // no channel selected
             Wire.endTransmission();
}

//reading from mux2, disable other muxes//////////////////////////////////////////////////////////////////////
void tcaselect2(uint8_t j) {   
      if (j > 7) return;
          Wire.beginTransmission(TCAADDR2);
          Wire.write(1 << j);
          Wire.endTransmission();  
            //end other muxes
            Wire.beginTransmission(TCAADDR);
            Wire.write(0); // no channel selected
            Wire.endTransmission();
            Wire.beginTransmission(TCAADDR3);
            Wire.write(0); // no channel selected
            Wire.endTransmission();
            Wire.beginTransmission(TCAADDR4);
            Wire.write(0); // no channel selected
            Wire.endTransmission();
}

//reading from mux3, disable other muxes/////////////////////////////////////////////////////////////////////
void tcaselect3(uint8_t k) {   
      // mux we are using
      if (k > 7) return;
          Wire.beginTransmission(TCAADDR3);
          Wire.write(1 << k);
          Wire.endTransmission();  
            // end other muxes 
            Wire.beginTransmission(TCAADDR);
            Wire.write(0); // no channel selected
            Wire.endTransmission();
            Wire.beginTransmission(TCAADDR2);
            Wire.write(0); // no channel selected
            Wire.endTransmission();
            Wire.beginTransmission(TCAADDR4);
            Wire.write(0); // no channel selected
            Wire.endTransmission();
}

//reading from mux4, disable other muxes/////////////////////////////////////////////////////////////////////
void tcaselect4(uint8_t w) {   
      // mux we are using
      if (w > 7) return;
          Wire.beginTransmission(TCAADDR4);
          Wire.write(1 << w);
          Wire.endTransmission();  
              Wire.beginTransmission(TCAADDR);
              Wire.write(0); // no channel selected
              Wire.endTransmission();
              Wire.beginTransmission(TCAADDR2);
              Wire.write(0); // no channel selected
              Wire.endTransmission();
              Wire.beginTransmission(TCAADDR3);
              Wire.write(0); // no channel selected
              Wire.endTransmission();
}



// sensors //////////////////////////////////////////////////////////////////////////////////////////////////
//record data on test.txt file

void sensorwritesd(int i){
        //
      myFile = SD.open("test.txt", FILE_WRITE);
  
      // if the file opened okay, write to it:
      if (myFile) {
              Serial.println("Writing to test.txt...");
              myFile.println(" ");
              myFile.print("sensor #:");
              myFile.print(i);
              myFile.print(" ");
              myFile.println("_______________________________start____________________________________");
  
              // sensor data for humidity
              myFile.print("1_humidity:");
              myFile.print(humidity[i]);
              myFile.print(" ");
              // Send Day-of-Week//////////////////
              myFile.print(rtc.getDOWStr());
              myFile.print(" ");
              // Send date/////////////////////////
              myFile.print(rtc.getDateStr());
              myFile.print(" -- ");
  
              // Send time/////////////////////////
              myFile.print("  time:");
              myFile.println(rtc.getTimeStr());

              //sensor data for temperature
              myFile.print("1_temperature:");
              myFile.print(temperature[i]); 
              
              // Send Day-of-Week
              myFile.print(rtc.getDOWStr());
              myFile.print(" ");
              
              // Send date
              myFile.print(rtc.getDateStr());
              myFile.print(" -- ");
              // Send time
              myFile.println(rtc.getTimeStr());
              delay(20);
              myFile.println("_______________________________end____________________________________ ");
              myFile.println(" ");
    
        // close the file:
          myFile.close();
            }
            else {
              // if the file didn't open, print an error:
              Serial.println("error opening test.txt");
                  }
}

dave-in-nj:
This may be an important part.

void checkConditions(float humidity[], float temperature[], float humiditymax[], float humiditymin[],
float temperaturemax[], float temperaturemin[]){
  float T;

  //when Temp is higher than 100F
    for(int i=0;i< 10; i++){
        if(temperature[i] > temperaturemax[i]){
          if(lastCheckHigh ==0){
                   Serial.print("WARNING:Temperature HIGH for sensor: ");
                   Serial.print(i); 
                   Serial.print(", Temp= ");
                   T = (temperature[i] * 9.0)/ 5.0 + 32.0; 
                Serial.println(T);
                   lastCheckHigh++;
                   //if temp sensor 1 is high send sms
                    if(i==0){
                      Serial.println("WARNING TEMP SENSOR 1 HIGH");
//                                 // send an SMS!
//                                  char sendto[12], message[141];
//                                  //flushSerial();
//                                  Serial.print(F("Send to #"));
//                                  //readline(sendto, 20);
//                                  sendto[0]='1';
//                                  sendto[1]='3';
//                                  sendto[2]='1';
//                                  sendto[3]='0';
//                                  sendto[4]='9';
//                                  sendto[5]='9';
//                                  sendto[6]='4';
//                                  sendto[7]='7';
//                                  sendto[8]='1';
//                                  sendto[9]='6';
//                                  sendto[10]='9';
//                                  sendto[11]='\0';
//                                  Serial.println(sendto);
//                                  Serial.print(F("Type out one-line message (140 char): "));
//                                  message[0] = 'W';
//                                  message[1] = 'A';
//                                  message[2] = 'R';
//                                  message[3] = 'N';
//                                  message[4] = 'I';
//                                  message[5] = 'N';
//                                  message[6] = 'G';
//                                  message[7] = ' ';
//                                  message[8] = 'T';
//                                  message[9] = 'E';
//                                  message[10] = 'M';
//                                  message[11] = 'P';
//                                  message[12] = ' ';
//                                  message[13] = 'S';
//                                  message[14] = 'E';
//                                  message[15] = 'N';
//                                  message[16] = 'S';
//                                  message[17] = 'O';
//                                  message[18] = 'R';
//                                  message[19] = ' ';
//                                  message[20] = '1';
//                                  message[21] = ' ';
//                                  message[22] = 'H';
//                                  message[23] = 'I';
//                                  message[24] = 'G';
//                                  message[25] = 'H';
//                                  message[26] = '\0';
//                                 // readline(message, 140);
//                                  Serial.println(message);
//                                  if (fona.sendSMS(sendto, message)) {
//                                    Serial.println(F("sent"));
//                                    
//                                  } 
//                                  else {
//                                    Serial.println(F("Sent anyway!"));
//                                  }
//                                  textingsignal = 0; 
                          
                    }
                    //if temp sensor 2 is high send sms
                    if(i==1){
                      Serial.println("WARNING TEMP SENSOR 2 HIGH");
                          //       // send an SMS!
                          //        char sendto[11], message[141];
                          //        //flushSerial();
                          //        Serial.print(F("Send to #"));
                          //        //readline(sendto, 20);
//                                  sendto[0]='1';
//                                  sendto[1]='3';
//                                  sendto[2]='1';
//                                  sendto[3]='0';
//                                  sendto[4]='9';
//                                  sendto[5]='9';
//                                  sendto[6]='4';
//                                  sendto[7]='7';
//                                  sendto[8]='1';
//                                  sendto[9]='6';
//                                  sendto[10]='9';
//                                  sendto[11]='\0';
                          //        Serial.println(sendto);
                          //        Serial.print(F("Type out one-line message (140 char): "));
                          //        message[0] = 'W';
                          //        message[1] = 'A';
                          //        message[2] = 'R';
                          //        message[3] = 'N';
                          //        message[4] = 'I';
                          //        message[5] = 'N';
                          //        message[6] = 'G';
                          //        message[7] = ' ';
                          //        message[8] = 'T';
                          //        message[9] = 'E';
                          //        message[10] = 'M';
                          //        message[11] = 'P';
                          //        message[12] = ' ';
                          //        message[13] = 'S';
                          //        message[14] = 'E';
                          //        message[15] = 'N';
                          //        message[16] = 'S';
                          //        message[17] = 'O';
                          //        message[18] = 'R';
                          //        message[19] = ' ';
                          //        message[20] = '2';
                          //        message[21] = ' ';
                          //        message[22] = 'H';
                          //        message[23] = 'I';
                          //        message[24] = 'G';
                          //        message[25] = 'H';
                          //        message[26] = '\0';
                          //        //readline(message, 140);
                          //        Serial.println(message);
                          //        if (fona.sendSMS(sendto, message)) {
                          //          Serial.println(F("sent"));
                          //          
                          //        } 
                          //        else {
                          //          Serial.println(F("Sent anyway!"));
                          //        }
                          //        textingsignal = 0; 
                          //
                    }
}

Sorry! I forgot to post the code in the original post. & theres a character limit when I try to post all the code in one post.

There seems to be a lot of code so debugging will take time. I suggest you to compartmentalize your code so you can test each part alone for hours to see if it causes problems. I didn't find how long your differential I2C bus is. That's important.