Arduino Due Tone example not working

cmaglie:
Wifi and Tone are not yet ported for the Due. Wifi Library is the next in my todo list for the coming week.

Sorry guys there are a lot of libraries out there... :frowning:

Two months have passed, that is Tone () works now?
I tried a very simple program, the compiler tells me: "error: 'tone' was Not Declared in this scope"

How to operate Tone () on the Due? Int is in 4 bytes on said date. Is that I can exceed 64,000 hertz?

Your help is appreciated :slight_smile:

I am new to the DUE, but I did get the sound to work OK for my purposes. (Make some sound on the speaker on my shield to let me know something is happening...)

//==============================================================================
//    SoundNoTimer - Quick and dirty tone function to try to output a frequency
//            to a speaker for some simple sounds.
//==============================================================================
void SoundNoTimer(uint8_t _pin, unsigned long duration,  unsigned int frequency)
{
  // Try to get something working on DUE...
  long toggle_count = 0;
  long lusDelayPerHalfCycle;
  boolean fHigh = false;
  // Set the pinMode as OUTPUT
  pinMode(_pin, OUTPUT);
  digitalWrite(_pin, LOW);
  toggle_count = 2 * frequency * duration / 1000;
  lusDelayPerHalfCycle = 1000000L/(frequency * 2);

  // if we are using an 8 bit timer, scan through prescalars to find the best fit
  while (toggle_count--) {
    // toggle the pin
    fHigh  = !fHigh;
    digitalWrite(_pin, fHigh? LOW : HIGH);
    // delay a half cycle
    delayMicroseconds(lusDelayPerHalfCycle);
  }    
  digitalWrite(_pin, LOW);
}

Note on other platforms, this code uses Port Masks and the like to set/clear the values as quickly as possible...

Not saying this is great, but may get you limping along.
Kurt

Kurt thank you, your solution will allow me to test until they find something better. When you go up in frequency with your trick, it becomes unclear.

I was hoping to convert the Arduino Duo frequency generator. :slight_smile: And I need to do a full scan between certain frequencies. I hoped, with integers coded on 4 bytes, have a Tone (), which amounts to 1 Ghz ... :slight_smile: This is not Christmas every day :).
Tone function () she will walk one day?

Hi,
That keeps you code pretty busy, you could try interrupts instead, here is a simple example of generating a sinewave, it would be easy to add other waveforms, see the second example for a simple synth based on the same code -

DDS Sinewave on Due

Quick and dirty synth on Due

Duane B

rcarduino.blogspot.com

Yep - you are correct that it sits and hangs in the code. But before I was using the Tone command and found myself doing things like:

tone(pin, 2000, 250);
delay(250);

So it did not buy me anything to use up the timer. Also my code that uses this, often passes in multiple notes to play, which is easy to do when you are doing it in a hard loop.

Also a lot of the code I do is for robots. Sometimes using the servo library, or my own version of it (ServoEx), which does timed moves... The Servo library relies heavily on the timer interrupts timing and having other interrupts often leads to servos that jitter.

But for other uses I would definitely look into using timers and interrupts.

Good luck
Kurt

thanks
I tried tone (pin, frequency) and I thought tone (pin, frequency, delay) work better, but no: (

tone(5, 2000, 250);
delay(250);

test_frequence_001.ino: In function 'void loop()':
test_frequence_001:13: error: 'tone' was not declared in this scope

tone () works with you on Aduino due?

Check this thread too:
http://forum.arduino.cc/index.php?topic=136500.0

Well, you can use the NewToneLib if you need to use tone() on unsupported arduino devices.
NewToneLib Github: GitHub - thr33bricks/NewToneLib: New Tone library for arduino devices which do not support the built-in one.

try this example:

https://forum.arduino.cc/index.php?topic=402784.0