Section 6

Modem addon to give Call Display

Usefull: USR AT COMMANDS

Adapter Used: RS232

The following code, will grab the caller ID and put it in to a veriable to be used later.

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////                                                                            ////
////                                 Arduino Caller ID                          ////
////                                   Author: Jim A                            ////
////                                  Date: 2/28/2014                           ////
////                                   Version: 1.00                            ////
////                             Platform: Arduino Mega 2560                    ////
////                                                                            ////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
byte buffer[30]; //This will be filled with the information returned in caller ID. 
int counter = 0; //Used to step through the buffer
int counter2 = 0; //User to dump the buffer in to the veriable
boolean CaptureDate = 0; //Capture Date mode, used to enter the correct IF statement.
boolean CaptureTime = 0; //Capture Time mode, used to enter the correct IF statement.
boolean CaptureName = 0; //Capture Name mode, used to enter the correct IF statement.
boolean CaptureNMBR = 0; //Capture Number mode, used to enter the correct IF statement.
byte c; //Current byte returned from serial1
byte w1; //Sliding window, last possistion before the 7 character window drops the character
byte w2; //Sliding window
byte w3; //Sliding window
byte w4; //Sliding window
byte w5; //Sliding window
byte w6; //Sliding window
byte w7; //Sliding window, first slot in the window
void setup() {
  Serial1.begin(38400); //The Modem I am using is a 33.6 USR Sportster and needed 38400BAUD
  Serial.begin(38400); //This is the comunication with the local serial port, Felt no reason to have a baud miss match.
  ModemInit(); //Function that sets all the veriables for the modem. See http://jim.akesons.com for more info.
  delay(100); 
  Serial.println("Done Modem init"); //Just used for Diagnostics.
}
void loop()
{
  while(Serial1.available() > 0) //If serial data from the modem is available
   {
     c = Serial1.read(); //Read that data in to the veriable.
     w1 = w2; //Sliding window, drops what was window 1 and updates it with that is in window 2.
     w2 = w3; //sliding window
     w3 = w4; //sliding window
     w4 = w5; //sliding window
     w5 = w6; //sliding window
     w6 = w7; //sliding window
     w7 = c; //sliding window updating with the most recent information.
     if (CaptureDate == 1) { //Flag turned on meaning Date data has been detected.
       if(c==13){ //If end of line then dump to screen
         Serial.print("Date: "); //Just for diagnostics.
         counter2 = 0; 
         while (counter2 <= counter) {
           Serial.write(buffer[counter2]); //write the content of the buffer to serial, this is for diagnostics.
           counter2++;
         }
         Serial.println(" "); //Just to dump a charage return at the end of the line, again diagnostics.
         CaptureDate = 0; //Reset the veriables as this operation is completed.
         counter = 0;
       }
       else { //If not end of line
         buffer[counter] = w7;
         counter++;
       }
     }
     if (CaptureTime == 1) { //Flag turned on meaning Date data has been detected.
       if(c==13){ //If end of line then dump to screen
         Serial.print("Time: ");
         counter2 = 0;
         while (counter2 <= counter) {
           Serial.write(buffer[counter2]);
           counter2++;
         }
         Serial.println(" ");
         CaptureTime = 0;
         counter = 0;
       }
       else { //If not end of line
         buffer[counter] = w7;
         counter++;
       }
     }
     if (CaptureName == 1) { //Flag turned on meaning Date data has been detected.
       if(c==13){ //If end of line then dump to screen
         Serial.print("Name: ");
         counter2 = 0;
         while (counter2 <= counter) {
           Serial.write(buffer[counter2]);
           counter2++;
         }
         Serial.println(" ");
         CaptureName = 0;
         counter = 0;
       }
       else { //If not end of line
         buffer[counter] = w7;
         counter++;
       }
     }
     if (CaptureNMBR == 1) { //Flag turned on meaning Date data has been detected.
       if(c==13){ //If end of line then dump to screen
         Serial.print("NMBR: ");
         counter2 = 0;
         while (counter2 <= counter) {
           Serial.write(buffer[counter2]);
           counter2++;
         }
         Serial.println(" ");
         CaptureNMBR = 0;
         counter = 0;
       }
       else { //If not end of line
         buffer[counter] = w7;
         counter++;
       }
     }
     
   else if(w1==68 and w2==65 and w3==84 and w4==69 and w5==32 and w6==61 and w7==32) {CaptureDate = 1;} //If "DATE = " is detected....
   else if(w1==84 and w2==73 and w3==77 and w4==69 and w5==32 and w6==61 and w7==32) {CaptureTime = 1;} //If "TIME = " is detected....
   else if(w1==78 and w2==65 and w3==77 and w4==69 and w5==32 and w6==61 and w7==32) {CaptureName = 1;} //IF "NAME = " is detected....
   else if(w1==78 and w2==77 and w3==66 and w4==82 and w5==32 and w6==61 and w7==32) {CaptureNMBR = 1;} //IF "NMBR = " is detected....
   }
}
void ModemInit() {
  Serial1.println("AT&D0");     // Ignore DTR
  delay(500);
  Serial1.println("ATH0");      //Hangup
  delay(500);
  Serial1.println("ATZ0");      // Reset Modem
  delay(500);
  Serial1.println("AT&C0");     // Ignore Carier Detect
  delay(500);
  Serial1.println("at#cid=1");  // Enable CALLER ID
  delay(500);
}



//Sample Code just to talk back and forth to the modem, through the RS232 adapter.
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////                                                                            ////
////                                   MDM Test Code                            ////
////                              Author: Jim A & Mark M                        ////
////                                 Date: 2/28/2014                            ////
////                                  Version: 1.00                             ////
////                            Platform: Arduino Mega 2560                     ////
////                                                                            ////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
//SERIAL PASS THOUGH, FOR MODEM TESTING.
//THIS IS ALL BASED ON A USR SPORTSTER 33.6 FaxModem 0413
void setup() {
  Serial1.begin(38400);
  Serial.begin(38400);
  ModemInit();
  delay(100);
  DialModem("4037309927");
}
void loop() {
byte c;
if (Serial1.available() > 0)
  {
    while(Serial1.available() > 0) {
      c = Serial1.read();
      Serial.write(c);
    }         
  }  
if (Serial.available() > 0)
  {
    while(Serial.available() > 0) {
      c = Serial.read();
      Serial1.write(c);
    }         
  }  
}
void DialModem(String PNum) {
  Serial1.print("ATDT");
  Serial1.println(PNum);
}
void ModemInit() {
  Serial1.println("AT&D0");     // Ignore DTR
  delay(2000);
  Serial1.println("ATH0");      //Hangup
  delay(2000);
  Serial1.println("ATZ0");      // Reset Modem
  delay(2000);
  Serial1.println("AT&C0");     // Ignore Carier Detect
  delay(2000);
  Serial1.println("at#cid=1");  // Enable CALLER ID
  delay(2000);
//ATDT//2505734220  
//
//CALLER ID EXAMPLE RECIEVED FROM MODEM:
//RING
//
//DATE = 0228
//TIME = 2330
//NAME = Alberta
//NMBR = 4034639546
}

<<SECTION 5 - MAIN>>