Thanks again for the assistance and I apologize for the delay in my response.
Below is the link to the synth.h library. I will post my complete sketch at the end of this message.
As a reminder my first project was with the Mega2560 and the SIM800. Tones, such as dial tones and touch tones were generated by IC's:
With the demise of the SIM800 as a result of the termination of 2G in the US. I invested in the SIM7600. I also rebuilt my PCB, eliminating the IC's and used the UNO to generate the tones. I switched to the UNO after determining the library for tones did not work with the Mega2560.
Today the only consideration for using the MEGA2560 would be the advantage of multiple serial ports. The extra ports would be used purely for diagnostic purposes of the current show stopper which is:
The SIM7600 is not sending, "MO CONNECTED" responses that were previously used with the SIM800 to determine a call was successful. If a call was successful, a flag was set to fire a relay to keep the money deposited for a call.
Over the last day, I have used software serial to create a second serial port on the UNO. I was able to monitor the software serial with Putty. I added several check points in the sketch where data was sent to putty (via) the software serial connection. I received positive results to all of these check points. I did not receive any of the expected messages from the SIM7600. Most importantly the "MO CONNECTED". Note, that the command AT+MORING=1 is/was what enabled notifications with the SIM800
It is interesting to note, If I use the Windows utility to make phone calls with the SIM7600, the GUI gives the message "VOICE CALL; BEGIN (time)" when the opposite end picks up the phone. I do not see this message when monitoring the serial traffic (Specifically the content of receivedChars) with putty.
Conclusion: unless I can find a method to determine a call has successfully connected with the SIM7600, I can not determine if a refund of money is due. It makes no difference if I am using the MEGA2560 or the UNO, as the response is expected from the SIM7600.
Thanks again for your help!
#include <Time.h>
#include <synth.h>
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
const byte rxPin = 2;
const byte txPin = 12;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {6, 7, 8, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3, 4, 5}; //connect to the column pinouts of the keypad
//Create an object of keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
synth tones; //-Make a synth
int keypressDelay = 200; // delay in mS to hold down a touch tone key
int keyReleaseDelay = 500; // delay in mS to remain silent after a key has been released
//Global variables-----------------------------------------------------------------------------------------
boolean wasHigh = false;
String phonenumber = "";
String response = "";
String toneNumber = "";
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
int countdigit = 0; // counts the number of digits that have been input
int trigger = 0; // determined if long distant and to wait for 10 digits if 1 is dialed first.
int telhook = 0; // current state of the button
int coin = 0; // counting money
int ln = 0; //determines if enought digits to dial
int initCall = 0;
int callGood = 0; // controls refund relays 3 & 4
int lc = 0; // lost carrier
const int GSM = 2; //turn on GSM
const int KeyPadC1 = 3; // KeyPad 1 4 7 *
const int KeyPadC2 = 4; // KeyPad 2 5 8 0
const int KeyPadC3 = 5; // KeyPad 3 6 9 #
const int KeyPadR1 = 6; // KeyPad 1 2 3
const int KeyPadR2 = 7; // KeyPad 4 5 6
const int KeyPadR3 = 8; // KeyPad 7 8 9
const int KeyPadR4 = 9; // KeyPad * 0 #
const int Audio = 10; //Control ear peice source
const int telhookpin = 14; // To detect phone offhook
const int R1 = 15; //Keep Money Relay
const int R2 = 16; //Refund Money Relay
const int five = 17; //Nickle detection pin
const int ten = 18; //Dime Detection pin
const int twentyfive = 19; //Quarter Detection pin
void setup() {
// put your setup code here, to run once:
tones.begin(); //-Start it up
tones.setupVoice(0, TRIANGLE, 60, ENVELOPE1, 127, 64); //-Set up voice 0
tones.setupVoice(1, TRIANGLE, 60, ENVELOPE1, 127, 64); //-Set up voice 1
tones.setupVoice(2, TRIANGLE, 60, ENVELOPE1, 127, 64); //-Set up voice 2
tones.setupVoice(3, TRIANGLE, 60, ENVELOPE1, 127, 64); //-Set up voice 3
//Setup the INPUT pins on the Arduino
pinMode(telhookpin, INPUT);
pinMode(KeyPadC1, INPUT);
pinMode(KeyPadC2, INPUT);
pinMode(KeyPadC3, INPUT);
pinMode(KeyPadR1, INPUT);
pinMode(KeyPadR2, INPUT);
pinMode(KeyPadR3, INPUT);
pinMode(KeyPadR4, INPUT);
pinMode(five, INPUT);
pinMode(ten, INPUT);
pinMode(twentyfive, INPUT);
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
pinMode(GSM,OUTPUT);
pinMode(Audio, OUTPUT);
digitalWrite(R1, HIGH); //Set Money Keep/Return relays
digitalWrite(R2, HIGH);
digitalWrite(Audio, HIGH); // Set audio for Arduino tones
// start serial port
//digitalWrite(2, LOW);
delay (1000);
//digitalWrite(2, HIGH); Enable GSM
Serial.begin(9600);
delay(10000); //Wait for GSM to come on line
Serial.println("AT+MORING=1"); //old command suppost to trigger connection reports not working
}
void clearCount() {
countdigit = 0;
coin = 0;
trigger = 0;
phonenumber = "";
toneNumber = "";
}
void loop() {
while (digitalRead(telhookpin)==HIGH) { // Monitor HookFlash
dialTone(0); //enable dialtone
delay(500);
while (coin<25) { //check if 25 Cents entered to proceed
if (digitalRead(five)==HIGH){
coin=coin+5;
delay(500);
}
if (digitalRead(ten)==HIGH){
coin=coin+10;
delay(500);
}
if (digitalRead(twentyfive)==HIGH){
coin=coin+25;
delay(500);
}
if (digitalRead(telhookpin)==LOW){ //Set Coin to 9999 to exit if phone hungup
coin=9999;
dialTone(1); //Disable dialtone
delay(500);
}
}
while (coin>24 and coin<9998){ //Collect Dial Digits
char key = keypad.getKey();// Read the key
if (digitalRead(telhookpin)==LOW){ //Set Coin to 9999 to exit if phone hungup
coin=9999;
dialTone(1); //Disable dialtone
delay(500);
}
if (key){
toneNumber=key;
phonenumber=phonenumber+key;
countdigit=countdigit+1;
if (countdigit>0) { //Shut off dialtone when first digit is entered
dialTone(1);
}
if (toneNumber=="1"){
oneTone(100);
}
if (toneNumber=="2"){
twoTone(100);
}
if (toneNumber=="3"){
threeTone(100);
}
if (toneNumber=="4"){
fourTone(100);
}
if (toneNumber=="5"){
fiveTone(100);
}
if (toneNumber=="6"){
sixTone(100);
}
if (toneNumber=="7"){
sevenTone(100);
}
if (toneNumber=="8"){
eightTone(100);
}
if (toneNumber=="9"){
nineTone(100);
}
if (toneNumber=="0"){
zeroTone(100);
}
if (toneNumber=="*"){
starTone(100);
}
if (toneNumber=="#"){
poundTone(100);
}
if (countdigit==1 and toneNumber==1 and trigger==0){ //Determine how many digits to expect before dial
trigger=11;
} else if (trigger==0) {
trigger=10;
}
ln=phonenumber.length(); //Check to see if phone number length has been met
if (ln==trigger and trigger>0){
coin=24;
}
}
while (coin==24){ //Prepare to dial number
digitalWrite(Audio, LOW); //Change to GSM Audio
if (initCall==0) {
phonenumber=phonenumber+";";
phonenumber="ATD"+phonenumber;
initCall=1;
Serial.println(phonenumber); //Send number to GSM
}
delay(1000);
while (initCall==1){
static byte ndx = 0; //Look for successfull connection
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
if (newData == true) {
if (strcmp(receivedChars,"NO CARRIER\r") == 0) {
lc=1;
}
if (strcmp(receivedChars,"VOICE CALL: BEGIN\r") == 0) {
callGood=1;
}
if (strcmp(receivedChars,"MO CONNECTED\r") == 0) {
callGood=1;
}
newData = false;
}
if (digitalRead(telhookpin)==LOW or lc==1){ //Watch for phone on hook or no carrier
delay (1000);
Serial.println("AT+CHUP"); //Send hangup to GSM
initCall=2;
coin=9999;
}
}
}
}
if (coin==9999){
Serial.println("AT+CHUP"); //Issue Hangup to SIM7600
countdigit = 0;
coin=0;
initCall=0;
ln=0;
trigger=0;
phonenumber="";
digitalWrite(Audio, HIGH); //Change to Arduino pin 11 audio
if (callGood==1){ //keKeep Money
digitalWrite (R2,LOW);
delay(2000);
digitalWrite (R2,HIGH);
}
if (callGood==0){ //Refund Money
digitalWrite (R1,LOW);
delay(2000);
digitalWrite (R1,HIGH);
}
callGood=0;
}
}
}
// if onTime=0 the sound continuously plays until another sound is commanded elsewhere
// if onTime>0 the sound plays for the duration in mS
// dial tone 350Hz + 440Hz
void dialTone(int onTime) {
tones.setFrequency(0, 440.0);
tones.setFrequency(1, 350.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void oneTone(int onTime) {
tones.setFrequency(0, 1209.0);
tones.setFrequency(1, 697.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void twoTone(int onTime) {
tones.setFrequency(0, 1336.0);
tones.setFrequency(1, 697.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void threeTone(int onTime) {
tones.setFrequency(0, 1477.0);
tones.setFrequency(1, 697.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void fourTone(int onTime) {
tones.setFrequency(0, 1209.0);
tones.setFrequency(1, 770.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void fiveTone(int onTime) {
tones.setFrequency(0, 1336.0);
tones.setFrequency(1, 770.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void sixTone(int onTime) {
tones.setFrequency(0, 1477.0);
tones.setFrequency(1, 770.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void sevenTone(int onTime) {
tones.setFrequency(0, 1209.0);
tones.setFrequency(1, 852.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void eightTone(int onTime) {
tones.setFrequency(0, 1336.0);
tones.setFrequency(1, 852.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void nineTone(int onTime) {
tones.setFrequency(0, 1477.0);
tones.setFrequency(1, 852.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void zeroTone(int onTime) {
tones.setFrequency(0, 1336.0);
tones.setFrequency(1, 941.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void starTone(int onTime) {
tones.setFrequency(0, 1209.0);
tones.setFrequency(1, 941.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}
void poundTone(int onTime) {
tones.setFrequency(0, 1477.0);
tones.setFrequency(1, 941.0);
tones.trigger(0);
tones.trigger(1);
if (onTime > 0) {
delay(onTime);
tones.setFrequency(0, 0);
tones.setFrequency(1, 0);
}
}