Pradeep Singh | 29th Jun 2018
In this article, you would learn how to dial a phone number and pass the DTMF digits using Raspberry Pi, USRobotics USR5637 USB Dial-up Modem, and Python script.
1. Hardware Setup:
For this article, I am going to connect the USRobotics USR5637 USB Dial-up Modem with a Raspberry Pi as shown in the following picture –
2. AT Commands for DTMF Tones:
In the voice mode, there are two main AT commands related to the DTMF tone generation – VTD and VTS.
2.1 AT+VTD – Beep Tone Duration Timer:
You can use this command to set the default duration for DTMF/tone generation in 0.01 s increments. For DTMF digits, beep tone duration is the interdigit time. For tone generation, this number is the actual tone duration. The default tone duration is 100 or 1 s.
2.2 AT+VTS- DTMF and Tone Generation in Voice Mode:
You can use this command to produce a sequence of DTMF tones (or other tones, such as dial tone, busy, silence, etc.) as specified in the string parameter. String parameters are made up of a sequence of elements separated by commas. If the string does not supply a duration for a particular tone, then the DCE uses the duration designated by the +VTD command.
The VTS command can take string parameters in three formats as shown in the following table –
However, during my testing single chars and the curly bracketed group didn’t generate any tone. Hence, I used the bracketed group to generate the tones in my python script.
3. DTMF Tone Frequencies:
As shown in the following image, each digit on the phone dial pad, corresponds to two frequencies (f1 and f2 in this image) –
Based on this image and the bracketed group syntax for the AT+VTS command to pass the digit 1 as DTMF tone for 1 second is shown in the following example (100 is the tone duration in milliseconds i.e. 1 second) –
The following table provides another view of the first (low) and the second (high) tones of the Dual-tone Multi-Frequency (DTMF) tones for each digit on the phone’s dial pad –
4. Download the Python Script:
You can download the sample script that I wrote to dial a number and pass DTMF digits from my Github Repository using the following command –
git clone https://github.com/pradeesi/pass_dtmf_digits
Following terminal output shows the git clone output on raspberry pi –
pi@raspberrypi:~ $ git clone https://github.com/pradeesi/pass_dtmf_digits Cloning into 'pass_dtmf_digits'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (5/5), done. remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (6/6), done. pi@raspberrypi:~ $
On successful code download, you should see “pass_dtmf_digits” directory under your present working directory. CD into the “pass_dtmf_digits” directory and make sure you have “pass_dtmf_tones.py” file under it, as shown in the following terminal output –
pi@raspberrypi:~ $ cd pass_dtmf_digits/ pi@raspberrypi:~/pass_dtmf_digits $ ls README.md pass_dtmf_tones.py pi@raspberrypi:~/pass_dtmf_digits $
3. Set Variables and Execute Python Script:
Open the “pass_dtmf_tones.py” file and locate the following section with variables “PHONE_NUMBER” and “DTMF_DIGITS“. Set the values for these variables and save the python file.
#================================================================= # Set these variables #================================================================= PHONE_NUMBER = "xxxxxxxxxxx" # Enter the Phone number that you want to dial DTMF_DIGITS = "xxxxxxxxxxxx" # Enter the DTMF digits that you want to pass (valid options: 0-9, * and #) #=================================================================
After setting the variables and saving the files you are ready to execute the script. On execution, the python script will dial the number stored in “PHONE_NUMBER” variable and once this phone goes off-hook, it will pass the DTMF digits stored in “DTMF_DIGITS” variable.
You can use the following command to execute the python script (make sure you are in the “pass_dtmf_digits” directory –
Following screenshots has the output of the Raspberry Pi terminal window-
On successful connection, Raspberry Pi will start passing the DTMF digits –