Hello,
I'm just using Teensy (4.0) for the first time and plan to use it for an audio project. I have the Teensy 4.0 and Audio Shield board. Currently I'm just trying to learn how it works so I'm following the audio tutorial here using the Arduino IDE 2 w/ Teensyduino: https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015#menu-description, but I'm stuck with an issue and am looking for some tech support.
First, I ran the "Part_1_02_Hardware_test" example in the File>Examples>Audio>Tutorials library and I can hear the beeping in my headphones which confirms the Teensy HW is set up correctly. Next I ran the "Part_1_03_Playing_Music" example which plays one of the four .wav audio clips provided for the tutorial that I uploaded to the SD card (SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, & SDTEST4.WAV). I am seeing intermittent behavior here when running this code (shown at the bottom). Sometimes it plays the audio file cleanly with no problem, but other times it makes a loud periodic static noise sound that repeats every ~0.25 seconds. I tried changing the code to play a different .WAV file and some work more than others, but the issue can happen with any of the 4 files.
After trying to run this several times I found that sometimes it doesn't play any audio at all and it is unable to read the SD card. It says "Unable to access the SD card" in the serial monitor. For that reason I'm guessing the static audio may be an issue related to reading the SD card? I ran the SD card test in Files>Examples>Audio>HardwareTesting>SdCardTest and the results seem okay:
SD Card Test
------------
SD card is connected
Card type is SDHC
File system space is 7939.82 Mbytes.
SD library is able to access the filesystem
Reading SDTEST1.WAV:
Overall speed = 1.35 Mbyte/sec
Worst block time = 0.75 ms
25.75% of audio frame time
Reading SDTEST1.WAV & SDTEST2.WAV:
Overall speed = 1.34 Mbyte/sec
Worst block time = 1.47 ms
50.84% of audio frame time
Reading SDTEST1.WAV & SDTEST2.WAV staggered:
Overall speed = 1.34 Mbyte/sec
Worst block time = 1.16 ms
39.84% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV:
Overall speed = 1.35 Mbyte/sec
Worst block time = 2.23 ms
76.83% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV staggered:
Overall speed = 1.35 Mbyte/sec
Worst block time = 1.53 ms
52.87% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV:
Overall speed = 1.35 Mbyte/sec
Worst block time = 2.99 ms
103.02% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV staggered:
Overall speed = 1.35 Mbyte/sec
Worst block time = 1.90 ms
65.38% of audio frame time
Does anybody have any ideas why I may hear a periodic static like that?
A couple extra things to note:
1) I noticed the examples in the tutorial were written for Teensy 3.x so some of the pin assignments (like for SPI and Dout) needed to be changed to match the Teensy 4.0. Could there be anything else in the tutorial that could be giving me problems since I'm using Teensy 4.0?
2) I don't have the audio shield board plugged in directly on top of the Teensy. I have the teensy plugged into a breadboard, and jumper cables (~8") running up to the audio shield board. Could the breadboard and long jumpers be giving me issues with reading from the SD?
I'm just using Teensy (4.0) for the first time and plan to use it for an audio project. I have the Teensy 4.0 and Audio Shield board. Currently I'm just trying to learn how it works so I'm following the audio tutorial here using the Arduino IDE 2 w/ Teensyduino: https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015#menu-description, but I'm stuck with an issue and am looking for some tech support.
First, I ran the "Part_1_02_Hardware_test" example in the File>Examples>Audio>Tutorials library and I can hear the beeping in my headphones which confirms the Teensy HW is set up correctly. Next I ran the "Part_1_03_Playing_Music" example which plays one of the four .wav audio clips provided for the tutorial that I uploaded to the SD card (SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, & SDTEST4.WAV). I am seeing intermittent behavior here when running this code (shown at the bottom). Sometimes it plays the audio file cleanly with no problem, but other times it makes a loud periodic static noise sound that repeats every ~0.25 seconds. I tried changing the code to play a different .WAV file and some work more than others, but the issue can happen with any of the 4 files.
After trying to run this several times I found that sometimes it doesn't play any audio at all and it is unable to read the SD card. It says "Unable to access the SD card" in the serial monitor. For that reason I'm guessing the static audio may be an issue related to reading the SD card? I ran the SD card test in Files>Examples>Audio>HardwareTesting>SdCardTest and the results seem okay:
SD Card Test
------------
SD card is connected
Card type is SDHC
File system space is 7939.82 Mbytes.
SD library is able to access the filesystem
Reading SDTEST1.WAV:
Overall speed = 1.35 Mbyte/sec
Worst block time = 0.75 ms
25.75% of audio frame time
Reading SDTEST1.WAV & SDTEST2.WAV:
Overall speed = 1.34 Mbyte/sec
Worst block time = 1.47 ms
50.84% of audio frame time
Reading SDTEST1.WAV & SDTEST2.WAV staggered:
Overall speed = 1.34 Mbyte/sec
Worst block time = 1.16 ms
39.84% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV:
Overall speed = 1.35 Mbyte/sec
Worst block time = 2.23 ms
76.83% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV staggered:
Overall speed = 1.35 Mbyte/sec
Worst block time = 1.53 ms
52.87% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV:
Overall speed = 1.35 Mbyte/sec
Worst block time = 2.99 ms
103.02% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV staggered:
Overall speed = 1.35 Mbyte/sec
Worst block time = 1.90 ms
65.38% of audio frame time
Does anybody have any ideas why I may hear a periodic static like that?
A couple extra things to note:
1) I noticed the examples in the tutorial were written for Teensy 3.x so some of the pin assignments (like for SPI and Dout) needed to be changed to match the Teensy 4.0. Could there be anything else in the tutorial that could be giving me problems since I'm using Teensy 4.0?
2) I don't have the audio shield board plugged in directly on top of the Teensy. I have the teensy plugged into a breadboard, and jumper cables (~8") running up to the audio shield board. Could the breadboard and long jumpers be giving me issues with reading from the SD?
Code:
// Advanced Microcontroller-based Audio Workshop
//
// http://www.pjrc.com/store/audio_tutorial_kit.html
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
//
// Part 1-3: First "Hello World" program, play a music file
//
// WAV files for this and other Tutorials are here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playSdWav1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 11
#define SDCARD_SCK_PIN 13
// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN 11 // not actually used
//#define SDCARD_SCK_PIN 13 // not actually used
// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN 4
//#define SDCARD_MOSI_PIN 11
//#define SDCARD_SCK_PIN 13
void setup() {
Serial.begin(9600);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
delay(1000);
}
void loop() {
if (playSdWav1.isPlaying() == false) {
Serial.println("Start playing");
playSdWav1.play("SDTEST2.WAV");
delay(10); // wait for library to parse WAV info
}
// do nothing while playing...
}