Not playing sound for Teensy 3.2

Status
Not open for further replies.

nabs

Member
Is my first time here, and I would like to ask for some help.
Is my first time doing this, and I’m not too sure about my mistakes
I commented some of the lines as I’m trying to test each teensy at a time

As for T1 & T3 the audio file is looping
T2 & T4 is using sensor to make the sound appear

Basically I have 4 teensies 3.2 act as slaves, and 1 nodemcu as master.
So for the B0 & B1 , i used it to identify each teensy ID.

So for teensy 1 = 00
T2 = 01
T3 = 10
T4 = 11


So it will be shown in the serial monitor which teensy is playing audio file

I may have some mistakes on the codes but I’m not sure which part.

I’ll appreciate any of your help. ������

Received some replies, and I will try out on that.

If there’s is any mistakes I made, please point out to me, thank u. ����
Code:
#include <Wire.h>
#include <Audio.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
 
int myID;
String mySound;
 
AudioPlaySdWav playSdWav;
AudioOutputI2S i2s;
AudioConnection patchCord1(playSdWav, 0, i2s, 0);
AudioConnection patchCord2(playSdWav, 1, i2s, 1);
AudioControlSGTL5000 sgtl5000;
 
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
 
// Function prototypes
void receiveEvent(int count);
void requestEvent(void);
 
void setup()
{
  // Audio board
  AudioMemory(8);
  sgtl5000.enable();
  sgtl5000.volume(0.8);
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN)))
    Serial.println("Unable to access the SD card");
  delay(100);
 
  //Setup for I2C slave mode, address 0x0C (=12), pins 16/17
 //inset deubg line to check content of b0 b1
  if (B0 == 0 && B1 == 0)
  {
    myID = 0x0B;
    mySound = "PZ_BG_BR.201";
    //playSdWav.play("PZ_BG_BR.201"); change this to string to show file name
    // add a debug line using printf
  }
  else if (B0 == 0 && B1 == 1)
  {
    myID = 0x0C;
    mySound = "PZ_BIKE.203";
    //playSdWav.play("PZ_BIKE.203");
  }
  else if (B0 == 1 && B1 == 0)
  {
    myID = 0x0D;
    mySound = "PZ_BG_WT.202";
    playSdWav.play("PZ_BG_WT.202");
  }
  else
   {
    myID = 0x0E;
    mySound = "PZ_FRG.204";
    playSdWav.play("PZ_FRG.204");
  }

  Wire.begin(myID); // Join I2C bus with the specified address
  /*Wire.begin(0x0C); // Join I2C bus with the specified address
  Wire.begin(0x0D); // Join I2C bus with the specified address
  Wire.begin(0x0E); // Join I2C bus with the specified address*/
  Wire.setSCL(16);
  Wire.setSDA(17);
  // Register I2C events
  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent);
 
  // LED
  pinMode(LED_BUILTIN, OUTPUT); // Initialize as digital pin LED_BUILTIN as an output
 
  
  // Serial
  Serial.begin(9600); // Start serial for debug
}
 
void loop()
{
// Do nothing...
//delay(100);
}
 
// Function that executes whenever data is received from master
void receiveEvent(int howMany)
{
  while(Wire.available())
  {
    char c = Wire.read(); // Receive byte as a character
    Serial.printf("Reading from Master: %c\n", c); // Print the character
 
 if(c == '1')
  {
    // Start = blink once
    digitalWrite(LED_BUILTIN, HIGH); // Turn LED on
    delay(20);
    digitalWrite(LED_BUILTIN, LOW); // Turn LED off
 
   // If not already playing, start playback
  if (playSdWav.isPlaying() == false)
  {
    Serial.printf("Start playing\n");
    //myID;
    //playSdWav.play("PZ_BG_BR.201");
    //insert debug to show name
    playSdWav.play(mySound);
    delay(100); // Wait for library to parse WAV info
  }
 
 /*if (playSdWav.isPlaying() == false)
  {
    Serial.printf("Start playing\n");
    myID2;
    //playSdWav.play("PZ_BIKE.203");
    delay(100); // Wait for library to parse WAV info
  }*/
  }
}
}
 
// Function that executes whenever data is requested from master
void requestEvent(void)
{
  if(playSdWav.isPlaying())
{
  Wire.write("1", 1); // Send a 1-byte message "1" to indicate playback in progress
}
  else
  {
  Wire.write("0", 1); // Send a 1-byte message "0" to indicate no ongoing playback
  }
}
 
Last edited by a moderator:
Status
Not open for further replies.
Back
Top