My Teensy 3.1 has a piggybacked Audio Adaptor Board.
The Teensy is powered from a 1A 5V supply to Vin (pin 24), and the same 5V supply is powering a TSOP4856 IR Detector wired pin Pin 2.
1) Without trying to read IR via pulseIn, I can play .WAV files from my SD card without error.
2) Without audio playing, I can decode SIRC style pulses (600us on/off) modulated at 56kHz without error.
3) However, if there is a wav file playing, I cannot consistently decode IR pulses and sometimes the Teensy just locks up and I get a solid "beeeeeee" tone in the headphones. More often than not, pulseIn misses at least half of the pulses sent. I think the audio playback takes more clock cycles and "busy time" that won't allow Pulsein to run properly. I'd sure love to be able to play .WAVs while the Teensy looks for pulses and sends pulses, and looks for serial, all at the same time. Does anyone know if there is a fix, or am I just stuck?
Audio playback is boilerplate, lifted from Paul's WavFilePlayer example from the Audio library.
My IR code is sprinkled in for seasoning.
The Teensy is powered from a 1A 5V supply to Vin (pin 24), and the same 5V supply is powering a TSOP4856 IR Detector wired pin Pin 2.
1) Without trying to read IR via pulseIn, I can play .WAV files from my SD card without error.
2) Without audio playing, I can decode SIRC style pulses (600us on/off) modulated at 56kHz without error.
3) However, if there is a wav file playing, I cannot consistently decode IR pulses and sometimes the Teensy just locks up and I get a solid "beeeeeee" tone in the headphones. More often than not, pulseIn misses at least half of the pulses sent. I think the audio playback takes more clock cycles and "busy time" that won't allow Pulsein to run properly. I'd sure love to be able to play .WAVs while the Teensy looks for pulses and sends pulses, and looks for serial, all at the same time. Does anyone know if there is a fix, or am I just stuck?
Audio playback is boilerplate, lifted from Paul's WavFilePlayer example from the Audio library.
My IR code is sprinkled in for seasoning.
Code:
// Audio
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// GUItool: begin automatically generated code
AudioPlaySdWav playWav1; //xy=154,78
AudioOutputI2S i2s1; //xy=334,89
AudioConnection patchCord1(playWav1, 0, i2s1, 0);
AudioConnection patchCord2(playWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=240,153
// GUItool: end automatically generated code
int received[19];
void setup()
{
// IR INPUT INIT
pinMode(2, INPUT);
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(5);
sgtl5000_1.enable();
sgtl5000_1.volume(0.50); // HEAPHONES
// Set Pin Overrides
SPI.setMOSI(7);
SPI.setSCK(14);
if (!(SD.begin(10))) {
// stop here, but print a message repetitively
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
}
void loop()
{
if (!playWav1.isPlaying())
{
playFile("SDTEST1.WAV");
}
CheckForIR();
}
void playFile(const char *filename)
{
Serial.print("Playing file: ");
Serial.println(filename);
// Start playing the file. This sketch continues to
// run while the file plays.
playWav1.play(filename);
// A brief delay for the library read WAV info
delay(5);
}
void CheckForIR()
{
int error = 0;
if(digitalRead(2) == LOW)
{
received[0] = 0;
// Get the Header pulse, and wait until it is done.
while(digitalRead(2) == LOW){}
for(int i = 1; i < 18; i++)
{
received[i] = pulseIn(2, LOW, 5000);
}
}
}