IoT Bytes

Bits and Bytes of IoT

Send DTMF Tones with Raspberry Pi

Pradeep Singh | 29th Jun 2018

touch_tone

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 –

modem_setup

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.

VTS

The VTS command can take string parameters in three formats as shown in the following table –

VTS_str_formats.png

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) –

DTMF1

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) –

AT+VTS=[697,1209,100]

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 –

dtmf_freq_tbl

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 Octocat 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 –

python pass_dtmf_tones.py

Following screenshots has the output of the Raspberry Pi terminal window-

pass_dtmf1

On successful connection, Raspberry Pi will start passing the DTMF digits –

pass_dtmf2.png


 

Related Articles:

Modem Events and DTMF Tone Detection with Raspberry Pi

USB Analog Modem with Raspberry Pi

Python Script to Reset USB Modem COM Port on Raspberry Pi

Python Script to Autodetect Modem COM Port on Raspberry Pi

Incoming Call Details Logger with Raspberry Pi

Play Audio File on Phone Line with Raspberry Pi

Record Audio from Phone Line with Raspberry Pi

References:

Wikipedia – Voice modem command set

USRobotics 56K USB Modem Voice Commands

USRobotics 56K USB Modem – Data and General Commands

Voice +V Commands – Developer’s Guide

Blog Home Page:

Let’s Decipher IoT…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: