Hi,
I am new to using teensy, and have been using arduino before for simpler projects.
I'm working on a project where I need to create square wave signal with a sweeping frequency ranging from 20 to 20000 Hz. I need the frequency to bounce back to the startfrequency with a period of 30 seconds. I want the signal to repeat for 30 minutes before it stops.
I want to output the signal through the DAC.
I looked at the avaliable examples related to this, and am trying to reuse the code in Arduino IDE examples/audio/hardwaretesting/tonesweep
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
AudioSynthToneSweep myEffect;
AudioOutputI2S audioOutput; // audio shield: headphones & line-out
// The tone sweep goes to left and right channels
AudioConnection c1(myEffect, 0, audioOutput, 0);
AudioConnection c2(myEffect, 0, audioOutput, 1);
AudioControlSGTL5000 audioShield;
float t_ampx = 0.8;
int t_lox = 10;
int t_hix = 22000;
// Length of time for the sweep in seconds
float t_timex = 10;
// <<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
void setup(void)
{
Serial.begin(9600);
while (!Serial) ;
delay(3000);
AudioMemory(2);
audioShield.enable();
audioShield.volume(0.5);
Serial.println("setup done");
if(!myEffect.play(t_ampx,t_lox,t_hix,t_timex)) {
Serial.println("AudioSynthToneSweep - begin failed");
while(1);
}
// wait for the sweep to end
while(myEffect.isPlaying());
// and now reverse the sweep
if(!myEffect.play(t_ampx,t_hix,t_lox,t_timex)) {
Serial.println("AudioSynthToneSweep - begin failed");
while(1);
}
// wait for the sweep to end
while(myEffect.isPlaying());
Serial.println("Done");
}
void loop(void)
{
}
I'm changing the following
- im not using audioshield,
- im not outputting via i2s, but DAC
- new freq range and period
- waveform1 for square wave signal.
- moving code to loop to repeat infinitely (until I fix an overall time limit)
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
AudioSynthToneSweep waveform1;
AudioOutputAnalogStereo dacs; //xy=423,362
AudioConnection c1(waveform1, 0, dacs, 0);
AudioConnection c2(waveform1, 0, dacs, 1);
//AudioControlSGTL5000 audioShield;
float t_ampx = 0.8;
int t_lox = 20;
int t_hix = 20000;
// Length of time for the sweep in seconds
float t_timex = 300;
// <<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
void setup(void)
{
Serial.begin(9600);
while (!Serial) ;
delay(3000);
AudioMemory(2);
Serial.println("setup done");
if(!waveform1.play(t_ampx,t_lox,t_hix,t_timex)) {
Serial.println("AudioSynthToneSweep - begin failed");
while(1);
}
// wait for the sweep to end
while(waveform1.isPlaying());
// and now reverse the sweep
if(!waveform1.play(t_ampx,t_hix,t_lox,t_timex)) {
Serial.println("AudioSynthToneSweep - begin failed");
while(1);
}
// wait for the sweep to end
while(waveform1.isPlaying());
Serial.println("Done");
}
void loop(void)
{
}
I compile and upload it, but it does not work.
------------------------------ HARDWARE ----------------------------------------------
I have the following hardware setup 
------------------------------ TESTING ----------------------------------------------
I do not get sound when connecting a speaker to the amplifier
I dont get a nice signal when I only have teensy connected to the USB port and probing GND and DAC with an oscilloscope.
I have verified with a multimeter that teensy and the amplifer get 5.1V from the battery powerboost circuit.
I have checked that the speaker works.
Any obvious problems here? Grateful for some support!
Best regards,
Marcus