Thanks for the Advice given so far, but the solution was far simpler than anticpated as I was (we was) look to far outside the box.
The key was to remove the delays i.e. delay(1500); and use the implement the blink without delay method for the LCD updates.
Giving LCD updates every 1000millis, and still processing everything else.
Thanks again for your effort, below is the revised code.
/*
Process incoming serial data without blocking by Nick Gammon
http://gammon.com.au/serial
The rest of the sketch is by me
AT+CMGF=1 for txt mode
AT+CNMI=2,1,0,0,1 message indication
AT^SMGO=1 SMS full indication
AT&W store to memory
To check what you have entered
AT&V display current configuration
*/
#include <SoftwareSerial.h>
SoftwareSerial gsmSerial(9,10); //Creates a software serial port. (rx,tx) using the software serial header file
//-------- TC35i GSM ---------------
int SMS_location_number;
const unsigned int MAX_INPUT = 165; // 160 characters for SMS plus a few extra
static unsigned int input_pos = 0;
float TempSens; // temperature array for the 2 readings
int TempAver; // average temp of 2 internal sensors
float Voltage;
int TempDisplay;
int Setting;
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)
//------ Inital setup ----------
void setup()
{
//Set I/O status
pinMode(13, OUTPUT); //Test output
pinMode(12, OUTPUT); //Drive to relay
Serial.begin(9600); //Start default serial for LCD screen and debug
gsmSerial.begin(9600); //Starts addtional serial port for GSM
delay(10); //10ms delay
brightness(); //Set brightness by runing brightness function
clearLCD(); //Clear LCD from setup data by using clearLCD function
WelcomeMessage(); //Step 01 :- Welcome splash screen (defined in WelcomeMessage function)
GSM_Startup(); //Step 02 :- Run the GSM start function
System_Healthy(); //Step 03 :- Setup no complete
}
//------ End setup -------
//------ Main loop -------
void loop()
{
readTC35i(); //Step 04 :- Run through TC35i for incomming message
TempSetting(); //Step 05 :- Run temperature function to get temperatures
TempFunction(); //Step 06 :- Run temperature function to get temperatures
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
selectLineOne();
Serial.write("Temp = ");
Serial.print(TempDisplay);
Serial.write("c ");
selectLineTwo();
Serial.write("Setting = ");
Serial.print(Setting);
Serial.write("c ");
}
}
//------ End loop --------
//---------------------------- Read TC35i ------------------------------------//
// Read data from the TC35i, When a linefeed is read the data is processed
void readTC35i()
{
static char input_line [MAX_INPUT]; //static unsigned int input_pos = 0;
if (gsmSerial.available () > 0) //
{
while (gsmSerial.available () > 0)
{
char inByte = gsmSerial.read ();
switch (inByte)
{
case '\n': // end of text
input_line [input_pos] = 0; // terminating null byte
// terminator reached! process input_line here ...
process_data (input_line);
// reset buffer for next time
input_pos = 0;
break;
case '\r': // discard carriage return
break;
default:
// keep adding if not full ... allow for terminating null byte
if (input_pos < (MAX_INPUT - 1))
input_line [input_pos++] = inByte;
break;
} // end of switch
} // end of while incoming data
} // end of if incoming data
} // end of readTC35i
//---------------------------- process_data --------------------------------
void process_data (char * data)
{
//Serial.println (data); // display the data
if(strstr(data, "+CMGR:") && strstr(data, "+44XXXXXXXXXX"))
{
// Reads the +CMGR line to check if SMS is from a known Phone number
// This if statement could cover the whole of the process_data function
// then only known a phone number could control the Arduoino
}
if(strstr(data, "smsdelete"))
{
delete_All_SMS();
}
if(strstr(data, "^SMGO: 2"))
{ // SIM card FULL
delete_All_SMS(); // delete all SMS
}
if(strstr(data, "+CMTI:"))
{ // An SMS has arrived
char* copy = data + 12; // Read from position 12 until a non ASCII number to get the SMS location
SMS_location_number = (byte) atoi(copy); // Convert the ASCII number to an int
gsmSerial.print("AT+CMGR=");
gsmSerial.println(SMS_location_number); // Print the SMS in Serial Monitor
} // this SMS data will go through this process_data function again
// any true if statements will execute
if(strstr(data, "Heating on")) // If data contains Heating on
{
digitalWrite(13, HIGH); // REPLACE THIS WITH RELAY CONNECTION
selectLineTwo();
Serial.write("Heating is on");
delay(100);
gsmSerial.print("AT+CMGS=+44XXXXXXXXXX\r"); //AT command to send SMS
delay(100);
gsmSerial.print("Heating is now switched on"); //Print the message
delay(10);
gsmSerial.print("\x1A"); //Send it ascii SUB
delay(10);
delete_one_SMS(); //Calls delete message function
}
if(strstr(data, "Heating off"))
{
digitalWrite(13, LOW); // REPLACE THIS WITH RELAY CONNECTION
selectLineTwo();
Serial.write("Heating is off");
delay(100);
gsmSerial.print("AT+CMGS=+44XXXXXXXXXX\r"); //AT command to send SMS
delay(100);
gsmSerial.print("Heating is now switched off"); //Print the message
delay(10);
gsmSerial.print("\x1A"); //Send it ascii SUB
delay(10);
delete_one_SMS(); //Calls delete message function
}
} //--------------------------- end of process_data ---------------------------
void delete_one_SMS()
{
clearLCD();
selectLineTwo();
Serial.write("deleting SMS ");
Serial.print("1");
gsmSerial.print("AT+CMGD=");
gsmSerial.println("1");
delay(1000);
}
void delete_All_SMS()
{
for(int i = 1; i <= 10; i++) {
gsmSerial.print("AT+CMGD=");
gsmSerial.println(i);
selectLineTwo();
Serial.write("deleting SMS ");
Serial.print(i);
delay(500);
}
}
void clearLCD()
{ //clears the LCD display
Serial.write(0xFE); //command flag
Serial.write(0x01); //clear command.
delay(50);
}
void brightness()
{ //clears the LCD display
Serial.write(0x7C); //command flag
Serial.write(148); //brightness level.
delay(50);
}
void WelcomeMessage()
{
selectLineOne();
Serial.write("A greener home");
selectLineTwo();
Serial.write("Loading...");
delay(1500);
clearLCD(); // Clear LCD funtion
selectLineOne();
Serial.write("TC35i Start up");
selectLineTwo();
Serial.write("Configuring...");
delay(1500);
}
void GSM_Startup()
{
gsmSerial.print("AT+CMGF=1\r");
delay(100);
gsmSerial.print("AT+CNMI=2,1,0,0,1\r");
delay(100);
delete_All_SMS();
}
void System_Healthy()
{
clearLCD(); // Clear LCD funtion
selectLineOne();
Serial.write("System healthy");
delay(1000);
clearLCD();
}
void selectLineOne()
{ //puts the cursor at line 0 char 0.
Serial.write(0xFE); //command flag
Serial.write(128); //position
}
void selectLineTwo()
{ //puts the cursor at line 1 char 0.
Serial.write(0xFE); //command flag
Serial.write(192); //position
}
void TempFunction()
{
int count = 0; // counter set to 0
while (count <= 9){ // while loop to log each temperature reading
float reading = analogRead(1); //getting the voltage reading from the temperature sensor
Voltage = ((reading * 5)/1024); // converting that reading to voltage
float temperatureC = (Voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset to degrees ((voltage - 500mV) times 100)
TempAver = (TempAver + temperatureC); // log the temperature in the array
count++;
}
TempAver = (TempAver / 10); // calculates the average of the 2 sensors
TempDisplay = TempAver;
}
void TempSetting()
{
// read the input on analog pin 0:
float sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Setting = (15 + (voltage/0.5));
}