DTMF decoder library

This is a basic speech recognition software: GitHub - arjo129/uSpeech: Speech recognition toolkit for the arduino. It worked great.
This gave a response, but because it can only detect one tone at once, it didn't work: GitHub - jacobrosenthal/Goertzel: Arduino Library implementation of the Goertzel algorithm

Hello,

Works very well for me to display the code on the computer.

For cons, I can not seem to use a DTMF to turn an LED on output.

How to make the LED lights up when you press the button 5.

thank you

Post your code (using code tags).

Pete

Thank you for the reply,

I took your code and have just added this:

if(thischar == 5) {
digitalWrite(led, HIGH);
}

I know (thischar == 5) is not fair. But I do not know what to put.

with this code

if(thischar) {
digitalWrite(led, HIGH);
}

The LED lights up, but with all the DTMF.

Code complet:

//DTMF Remote 
//Led pin 13
//Audio IN A0


#include <DTMF.h>

int sensorPin = A0;
int led = 13;
float n=128.0;

// sampling rate in Hz
float sampling_rate=8926.0;

// Instantiate the dtmf library with the number of samples to be taken
// and the sampling rate.
DTMF dtmf = DTMF(n,sampling_rate);

void setup(){
  pinMode(led, OUTPUT);     
  Serial.begin(115200);

}

int nochar_count = 0;
float d_mags[8];



void loop()
{
  char thischar;
  

  /* while(1) */

  dtmf.sample(sensorPin);
  dtmf.detect(d_mags,506);
  thischar = dtmf.button(d_mags,1800.);

// Led ON receive DTMF "5"
//??? no (thischar) fonction
  if(thischar == 5) {
digitalWrite(led, HIGH);
}

  if(thischar) {
    Serial.print(thischar);
    nochar_count = 0;
    // Print the magnitudes for debugging
//#define DEBUG_PRINT
#ifdef DEBUG_PRINT
    for(int i = 0;i < 8;i++) {
      Serial.print("  ");
      Serial.print(d_mags[i]);
    }
    Serial.println("");
#endif
  } else {
    // print a newline 
    if(++nochar_count == 50)Serial.println("");
    // don't let it wrap around
    if(nochar_count > 30000)nochar_count = 51;
  }
}

I started, but you've probably noticed ...

thank you very much

The code returns the detected button as a character so you need to use:

if(thischar == '5') {
  digitalWrite(led, HIGH);
}

This allows it to also return the symbols such as '*', '#' and, if you have the full 16 button pad, 'A', 'B' etc.

Pete

The simplest things are the most obvious.

Thank you, now it works fine.

FYI, perfect decoding at a speed of 50ms, but only with the wiring you suggested.

thank you very much for the help and the job.

HB3YWU / Mike

DTMF.cpp gets compile errors for me. I use the current version of the 'arduino' package from the Fedora 'updates' repository on Fedora 20. Perhaps something has changed in the avr-gcc compiler. I get error message:
unable to find a register to spill in class 'POINTER_REGS'
The line causing the error is:
dtmf_mag = sqrt(Q1Q1 + Q2Q2 - coeffQ1_Q2);
I fixed the problem by splitting up this expression into 3 lines:
float tmp;

tmp = Q1*Q1 + Q2Q2;
tmp = tmp - coeff*Q1Q2;

dtmf_mag = sqrt(tmp);
Griff_

Pete, it is possible that your library can decode CTCSS tone? this guy make something that : Private Site
but this radio can't read DTMF tone or i made a mistake ?

The library is specifically designed to decode the 8 DTMF tones. Decoding CTCSS tones is much more difficult because in some cases they are less than 3Hz apart whereas the DTMF tones are at least 70Hz apart.
If you were aiming to decode only a few of the tones and could choose a few that were much further apart, it can be done, but trying to decode all of them is probably impossible on an Arduino without external hardware.

Pete

When I try to compile the example dtmf_test I get the following and some more error-messages:

C:\Users\Peter\Documents\Arduino\libraries\DTMF\DTMF.cpp: In member function 'void DTMF::detect(float*, int)':

C:\Users\Peter\Documents\Arduino\libraries\DTMF\DTMF.cpp:179:1: error: unable to find a register to spill in class 'POINTER_REGS'

Arduino: 1.6.1 (Windows 7), Platine: "Arduino Uno"

Has anyone an idea how to fix this?

The code compiles with Arduino version 1.0.6 but it appears that there is a bug of some sort in the compiler in versions 1.6.0 and 1.6.1 - probably related to the -Os flag.
I have a workaround. Replace the entire DTMF:detect function in the DTMF.cpp library file with this:

// return the magnitudes of the 8 DTMF frequencies
void DTMF::detect(float dtmf_mag[],int adc_centre)
{
  int index;
  float d_tmp;

  /* Process the samples. */
  for (index = 0; index < N; index++)
  {
    ProcessSample(testData[index],adc_centre);
  }
  // Calculate the magnitude of each tone.
  for(int i=0;i < 8;i++) {
// El_Supremo 150318 the compilers in Arduino verisons 1.6.0 and 1.6.1
// generated "unable to find a register to spill" error in the original statement
// here. Breaking it into pieces worked around the problem.
//     dtmf_mag[i] = sqrt(Q1[i]*Q1[i] + Q2[i]*Q2[i] - coeff[i]*Q1[i]*Q2[i]);

  	// This is the equivalent of sqrt(real*real + imag*imag)
  	d_tmp = Q1[i]*Q1[i];
  	d_tmp += Q2[i]*Q2[i];
  	d_tmp -= coeff[i]*Q1[i]*Q2[i];

    dtmf_mag[i] = sqrt(d_tmp);
  }
  ResetDTMF();
}

I didn't notice/remember the report of the same problem in message #24 by griff2a until after I'd found a fix. My first attempt at splitting up the statement was similar to his but it didn't help so I had to split it even further.

Let me know if this works for you. I will update the link to the library.

Pete

The most recent version of the library is attached to the first message in this thread.

Pete

Everything works fine now. Thank You !!!

el_supremo:
I've uploaded the updated version to http://members.shaw.ca/el.supremo/DTMF.zip.

Pete

Hey Pete,

The above link seems to be pointing to the previous version... still the same detect function.

rob

Hi Rob,
Thanks for the heads up. I've uploaded the correct version this time.

Pete

I realized the wrong link by myself. Thanks to everybody. My application, the detection of given 4 alarmtones between 580 and 820 Hz, works very fine!

Hey everybody,

I'm so glad this DTMF library exists. To add to the posted code in this thread. Any ideas on how to select 2 or 4 dtmf tones sequentially to flip the LED on?

I'm looking for:

if(thischar == '55') {
digitalWrite(led, HIGH);
}

Or:

if(thischar == '55AB') {
digitalWrite(led, HIGH);
}

I'm thinking of having a counter that counts until 2 or 4. Once the count gets up to 2 or 4, 'thischar' would be reset to 0. I'm having trouble expressing that as code that works.

Thanks!

Hi Everybody,

I am trying to make a simple comminicator by landline which will use DTMF signals on both sides problem is , I am looking for detecting the Line busy, Call in process , other party didnt answer , Does any one can help me how to make this or which IC. can be used or is there any other way to make.

Best Regards

Hi Pete,

When I tried "Verify" of the "dtmf_test.ino"

I get this error message:

Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino\libraries\DTMF\DTMF.cpp: In member function 'void DTMF::detect(float*, int)':
C:\Program Files (x86)\Arduino\libraries\DTMF\DTMF.cpp:179:1: error: unable to find a register to spill in class 'POINTER_REGS'
}
^
C:\Program Files (x86)\Arduino\libraries\DTMF\DTMF.cpp:179:1: error: this is the insn:
(insn 42 40 44 6 (set (reg:SF 50 [ D.4208 ])
(mem:SF (post_inc:HI (reg:HI 63 [ ivtmp.118 ])) [2 MEM[base: _50, offset: 0B]+0 S4 A8])) C:\Program Files (x86)\Arduino\libraries\DTMF\DTMF.cpp:175 99 {*movsf}
(expr_list:REG_INC (reg:HI 63 [ ivtmp.118 ])
(nil)))
C:\Program Files (x86)\Arduino\libraries\DTMF\DTMF.cpp:179: confused by earlier errors, bailing out
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Do I need to have the arduino uno plugged in and running the program? I thought "verify" would compile without.

Thanks,
Emerson

See messages 24, 28 and 29 in this thread. Let me know if that doesn't help.

Pete