-
Linking to the cellphone module
10/19/2020 at 16:41 • 0 commentsIntro
The A6 SIM module that I bought is this one. In this page I explain how I connected the phone and the Arduino to the GSM shield and what code I use for receviving and making a call.
Arduino to A6 connections
Connections between the Arduino and the A6 module are quite straight forward. I did have two issues that I didn't direclty debug:
Power: Connecting the Arduino to the laptop I use for code development and routing the 5V out of the Arduino to the A6 module does not allow for enough current draw for the module to fully function. Full functionality is acheived by powering the A6 module seperately. Later using the AC/DC module as described in the previous page, enough power is provided for full functionality.
Communication: In hindsight it sounds very stupid, but make sure you connect the Rx port ofthe Arduino to te Tx of the A6 and vice versa. We want to receive what one module is sending out by the other module.
A6 to phone connections
The only thing needed to connect to the A6 module is the horn of the phone, which contains to wires for the microphone and two for the speaker. Since the first plan was to connect the horn to the phone and the A6 module has a Jack input I bought a solderable converter. Using the Jack plug and connecting it to the A6 only gave me the functionality of the microphone, not the speaker of the horn. After that I connected the horn directly to the pins on the A6 module and everything was fine.
Incoming call detection
A lot of examples out there, but I wanted a way to detect it with a simple command, which is why I went with te option below:
{` //Rigistering the "RING" being transmitted by the SIM module == incoming call if (ringer.indexOf("RING") > 0) { Call_receive(); } `}
where ringer is a String variable containing the most recent information available as received from the A6 module.
The SIM-card
Only one thing to say here, don't go to cheap on the SIM. I was happy like a child when I had and the A6 module and my SIM card, the latter bought after searching the web for the operator that give the the best rates without a monthly subscription. I went to bed crying that day. couldn't get it to receive cell connection, while most of the other communication was fine, could read the sim card number etc. I later tried with a SIM from a more prominent provider and everything worked instantly...
Still haven't figured out why the other SIM didn't work.The Code
The code used for the entire project can be found below. Feel free to reach out should anything be unclear.
{` // Global variable definition /// Varialbes mainly for receiving a call int ringstate = 0; // state of the bell int hornstate = 0; // is the telephone horn lifted or not int hornstate_prev = 1; // previous state of the hrn String ringer = ""; // detecting an incomming call char letter; /// Variables mainly for making a call float pulscount = 0; // measured state of the 'digitalPin_cnt' signal float pulscount_prev = 0; // previous state of the 'digitalPin_cnt' signal float reset = 0; // measured state of the 'digitalPin_reset' signal float reset_prev = 0; // previous state of the 'digitalPin_reset' signal int count = 0; // variable counting the amount of pulses received when dialing a number String PHnumber = ""; // string capturing the full phone number dialed unsigned long timer; // Arduino PIN selection int digitalPin_cnt = 6; // Pin 6 is input connected to the number pulses of rotary dial int digitalPin_reset = 7; // Pin 7 is input connected to the single pulse showing rotary dial usage int digitalPin_ringer_out = 8; // Pin 8 is output to the relay swithing the ringer on and off int digitalPin_horn = 9; // Pin 9 is input connected to the horn sensor detecting a picked up horn void setup() { pinMode(digitalPin_cnt, INPUT); pinMode(digitalPin_reset, INPUT); pinMode(digitalPin_ringer_out, OUTPUT); pinMode(digitalPin_horn, INPUT); //Begin serial communication with Arduino and Arduino IDE (Serial Monitor) Serial.begin(19200); //Begin serial communication with Arduino and A6 Serial1.begin(19200); // Initializing the A6 module Serial.println("Initializing..."); delay(1000); Serial1.println("AT+IPR?"); //checking the baud rate of the A6 module updateSerial(); Serial1.println("AT+IPR=19200"); // setting the baud rate of the A6 module updateSerial(); Serial1.println("AT"); //Once the handshake test is successful, it will back to OK updateSerial(); Serial1.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best updateSerial(); Serial1.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged updateSerial(); Serial1.println("AT+CREG?"); //Check whether it has registered in the network updateSerial(); Serial1.println("AT"); //Once the handshake test is successful, it will back to OK updateSerial(); Serial.println("Done!"); } void loop() { delay(10); hornstate_prev = hornstate; hornstate = digitalRead(digitalPin_horn); //Detecting a picked up horn if (hornstate_prev == 1 && hornstate == 1) { Dialing(); } //Rigistering the "RING" being transmitted by the SIM module == incoming call if (ringer.indexOf("RING") > 0) { Call_receive(); } updateSerial(); } // update the signals sent/received from/to the SIM module. // don't write everything to the Serial.Println, causes problems and delays. void updateSerial() { ringer = ""; delay(250); while (Serial.available()) { Serial1.write(Serial.read());//Forward what Serial received to Software Serial Port } while (Serial1.available()) { letter = Serial1.read(); ringer += letter; } } void Call_receive() // How to handle an incoming call { boolean finishedcall = false; unsigned long timer; timer = micros(); ringer = ""; ringstate = 1; digitalWrite(digitalPin_ringer_out, ringstate); // while no 'ERROR' or '+..' is received indicating a stopped or cancelled call while (ringer.indexOf("O") < 0 && ringer.indexOf("+") < 0 && finishedcall == false) { hornstate_prev = hornstate; hornstate = digitalRead(digitalPin_horn); // Turn on the horn of the phone with 1000 ms intervals if (micros() - timer > 1000000) { timer = micros(); ringstate = (ringstate + 1) % 2; digitalWrite(digitalPin_ringer_out, ringstate); } // Detecting a picked up horn after incoming call if (hornstate == 1 && hornstate_prev == 0) { digitalWrite(digitalPin_ringer_out, 0); // accept the call once the horn has been picked up Serial1.println("ATA"); hornstate_prev = hornstate; while ((hornstate == 1 || hornstate_prev == 1)&& ringer.indexOf("+") < 0 && ringer.indexOf("O") < 0) { // hornstate_prev = hornstate; hornstate = digitalRead(digitalPin_horn); delay(10); finishedcall = true; } Serial1.println("ATH"); finishedcall = true; updateSerial(); delay(10); } updateSerial(); delay(10); } digitalWrite(digitalPin_ringer_out, 0); Serial1.println("AT"); finishedcall = 1; } void Dialing() // Handling dialing and calling { while (hornstate_prev == 1 && hornstate == 1) { delay(10); pulscount = digitalRead(digitalPin_cnt); reset = digitalRead(digitalPin_reset); hornstate_prev == hornstate; hornstate = digitalRead(digitalPin_horn); if ( pulscount == 0 && pulscount_prev == 1 && reset == 1) { count = count + 1; timer = micros(); } if ( reset == 0 && reset_prev == 1) { PHnumber.concat(String(count % 10)); count = 0; Serial.println(PHnumber); timer = micros(); } if (micros() - timer >= 3000000 && PHnumber != "") { //Serial.println(PHnumber); // the dialed number. Serial1.println("ATD"+PHnumber); //call the dialed number PHnumber = ""; timer = micros(); } pulscount_prev = pulscount; reset_prev = reset; } Serial1.println("ATH"); } `}
-
Ringing the Bell
10/19/2020 at 16:39 • 0 commentsIntro
The ringer of the phone is actuated by a hammer and an electromagnet. Alternating current through a solenoid, continuously polarises the magnet two different ways. This makes the hammer swing both ways, hitting the bells.
During the days of the actual phone this was done with around 100 Volts at a frequency of 20 Hz, but I am hoping that 12 V and 50 Hz will do the trick.
AC/DC
I want the phone to be working continously and not have to hassle with batteries. Since I anyway need the AC circuit for the bell, I plan to use the power from an outlet, convert it to 12 V DC for the electronics and tap from the incomming AC supply for the bell. The ACDC converter I ended up buying is very similar to this one.
A simple 5V relay shall be used to actuate the solenoid intermittently with 1s intervals. The figure below shows the electromagnetical actuator in this phone: -
Reading the Rotary dial
10/19/2020 at 16:37 • 0 commentsThe phone
Intro
I recently bought an old RTT 72 phone and I wanted to give it a second life.
The first idea was to only reuse the horn of the phone such that I would be able to connect my cellphone through the jack connection. This soon became too little of a challange so I wanted to make the phone a full stand alone unit that can be used to make and receive calls.
For this I shall request the help on an Arduino.The rotary dial
No rotary encoder was needed to read in the signal, as the original mechanism could be used. Two digital inputs are needed to cature the numbers.
One changes state the entire time the dial is turning and the other one gives a certain amount of pulses, equal to the number dialed.
So, two digital inputs are reserved on the Arduino. The figure below shows the two parts of the mechanism registering the dialed numbers.Two resistors and a connection to the ground are needed to correctly measure the signals. At first I tried hardware interrupts to register the pulses, but the result whas not as expected. More detailed investigation with the 'Serial Plotter' of the Arduino IDE at a high CAN rate showed that the signals sometimes switched states when not expected, So I moved to using normal digital inpus and compared two values measured consecutively with a 10 ms delay.
Below an extract of the Arduino code I used for this part:
{` int digitalPin_cnt = 6; // Pin 6 is input connected to the number pulses of rotary dial int digitalPin_reset = 7; // Pin 7 is input connected to the single pulse showing rotary dial usage float pulscount = 0; // measured state of the 'digitalPin_cnt' signal float pulscount_prev = 0; // previous state of the 'digitalPin_cnt' signal float reset = 0; // measured state of the 'digitalPin_reset' signal float reset_prev = 0; // previous state of the 'digitalPin_reset' signal int count = 0; // variable counting the amount of pulses received when dialing a number String PHnumber = ""; // string capturing the full phone number dialed unsigned long timer; void setup() { // start serial communication Serial.begin(9600); // set pin modes pinMode(digitalPin_cnt, INPUT); pinMode(digitalPin_reset, INPUT); // initiate the timer timer = micros(); } void loop() { delay(10); // to filter out erractic signals pulscount = digitalRead(digitalPin_cnt); reset = digitalRead(digitalPin_reset); // detect the pulses of the number dialed if the rotary dial is in motion if (pulscount == 0 && pulscount_prev == 1 && reset == 1) { count = count + 1; timer = micros(); } // If the rotary dial is no longer in motion the number dialed is captured if ( reset == 0 && reset_prev == 1) { PHnumber.concat(String(count % 10)); // a modulo operator because the '0' is 11 pulses count = 0; Serial.println(PHnumber); timer = micros(); } //If 'PHnumber' is not empty and nothing happens within 3s you capture the fully dialed number if (micros() - timer >= 3000000 && PHnumber != ""){ Serial.println(PHnumber); PHnumber = ""; timer = micros(); } pulscount_prev = pulscount; reset_prev = reset; } `}