Invalid R4 SineWave.ino Example

arduino IDE 1.x, 2.x
Board Manager : Arduino UNO R4 Boards 1.0.2

File -> example -> UNO R4 xxx example -> AnalogWave -> SineWave

#include "analogWave.h"

analogWave wave(DAC);

int freq = 10;  // in hertz, change accordingly

void setup() {
  Serial.begin(115200);
  pinMode(A0, INPUT);
  wave.sine(freq);
}

void loop() {
  freq = map(analogRead(A0), 0, 1024, 0, 10000);
  Serial.println("Frequency is now " + String(freq) + " hz");
  wave.freq(freq);
  delay(1000);
}

This example code outputs the signal received with A0 to DAC.
But A0 is a DAC pin.

Web page examples use A5 instead of A0.

the same example
https://docs.arduino.cc/tutorials/uno-r4-minima/dac

The example seems to be invalid.

Thanks for bringing this to our attention @nyk_yeon. A fix for the example is now in progress:

2 Likes

Just change A0 to A5 and it will work! It appears twice in the code, you need to change both instances.

I came up with this simple fix and it worked.

/*
 * Generate a sin wave with frequency
 * determined with a pot on A1
 * Wave output on A0
 */
#include "analogWave.h"

analogWave wave(DAC);

int freq = 1000;  // in hertz, change accordingly

void setup() {
  Serial.begin(115200);
  pinMode(A1, INPUT);
  wave.sine(freq);
}

void loop() {
  freq = map(analogRead(A1), 0, 1024, 0, 10000);
  Serial.println("Frequency is now " + String(freq) + " hz");
  wave.freq(freq);
  delay(1000);
}

Hello everybody !
to generate a frequency i use this code from 5Hz to 10kHz

*
 * Generate a sin wave with frequency

 * Wave output on A0
 */
#include "analogWave.h"

analogWave wave(DAC);

int freq = 2000;  // in hertz, change accordingly


void setup() {
  Serial.begin(115200);
  wave.sine(freq);
}

void loop() {
  Serial.println("Frequency is now " + String(freq) + " hz");
  wave.freq(freq);
  delay(1000);
}