AnalogWave source code?

I have an R4 WiFi board and I'm trying to use the DAC output. I'm following the directions at https://docs.arduino.cc/tutorials/uno-r4-wifi/dac/

I am getting lockups if I create a sine wave, stop it, re-create it, and then stop it again. I suspect that there is a bug in the analogwave.h library but I have been unable to find the source code. I can only find the header file in the arduino IDE (2).

How can I find the source code for the AnalogWave library implementation?

Thanks,
James

Welcome to the forum.

You might want to look at this How to get the best out of this forum before you proceed any further.
We only know what you tell us, and without knowing what you have, we don't stand a chance.

Why are you doing this?
Also how are you doing this?
Please post your code using the information in the link above.

You can see the source code for the AnalogWave on the following GitHub page:-
AnalogWave source code

It is a bit of a rubbish library anyway because it is limited in speed because it tries to play all the samples into one wave.

Much better to address the registers themselves like in my video here.

Also look for other videos, from me, showing sound from a R4 WIFI board.

Or, there is a problem with your code, which you forgot to post.

Hi @voltron6000.

If you are looking for the location where the source code is hosted online, just go to the link provided by @Grumpy_Mike and navigate up a couple of folder levels until you see the analogWave.cpp file.

If you were instead looking for the copy of the library files on your hard drive, which are used when compiling a sketch in Arduino IDE, then you can find it by the following procedure:

  1. Open any sketch that uses the library in Arduino IDE.
  2. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  3. Check the box next to "Show verbose output during: ☐ compile" in the "Preferences" dialog.
  4. Click the "OK" button.
    The "Preferences" dialog will close.
  5. Select Sketch > Verify/Compile from the Arduino IDE menus.
  6. Wait for the compilation to finish.

Now examine the contents of the black "Output" panel at the bottom of the Arduino IDE window. There you will see a line that looks something like this:

Using library AnalogWave in folder: C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\libraries\AnalogWave (legacy)

You will find the source files under that folder.


:exclamation: The path might be under a folder that is hidden by your operating system by default (as Windows does with the AppData folder in the example snippet I provided above). If you don't see a folder while looking for that path, in your file manager, find and follow the instructions for configuring the operating system to not hide folders from you.

If you want help with that, just tell us which operating system you are using and we'll provide instructions.


Thank you very much for the links! This is exactly what I was looking for.

Web IDE issues

My experience with this library first started with my using the Arduino Web IDE on a Chromebook to run the example programs listed in the DAC documentation. Specifically the first example on that page.

I just copied the code and placed it into the Web IDE, complied, and installed on the board. The board just locks up and does not display anything on the serial port (the serial port LEDs on the board do not flash either). No local code modifications. We've been able to get other non-DAC code to run just fine on the board.

I switched to the desktop IDE (v2), updated the firmware, and the code started working as expected. I just went back to the Chromebook Web IDE and the code still does not run, even with the updated firmware.

Desktop IDE issues

Then I started working with my daughter on a desktop (IDE v2) on a fun Morse code project. Here's a testcase that does not work:

#include "analogWave.h" // Include the library for analog waveform generation

int freq = 282;
int unit = 250;
analogWave wave(DAC);   // Create an instance of the analogWave class, using the DAC pin

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}

void dit() {
  digitalWrite(LED_BUILTIN, HIGH);
  wave.sine(freq);
  delay(unit);
  digitalWrite(LED_BUILTIN, LOW);
  wave.stop();
  delay(unit);
}

void dah() {
  digitalWrite(LED_BUILTIN, HIGH);
  wave.sine(freq);
  delay(3 * unit);
  digitalWrite(LED_BUILTIN, LOW);
  wave.stop();
  delay(unit);
}

void loop() {
  // N : Dah Dit
  Serial.println("Starting N");
  dah();
  dit();
  delay(2 * unit);

  // E: dit
  Serial.println("Starting E");
  dit();
  delay(2 * unit);

  // V: dit dit dit dah
  Serial.println("Starting V");
  dit();
  dit();
  dit();
  dah();
  delay(2 * unit);
}

The Arduino (R4 WiFi) locks up after printing "Starting E". It works fine if I comment out all the calls to the 'wave' object.

We worked around this by using wave.amplitude() to turn the tone on/off instead.

Thanks again for the links. This really feels like a library issue and I'll try to send a pull request if I find a solution.