teensy 4.0 & audio shield SD Card crash

Status
Not open for further replies.

caroeisbaer

New member
Hello hello!

I am quite new to programming and stumbled upon the teensy board a while ago.
I am using it for a perfromance in which sound is being played from the sd card and triggered by a distance sensor. the distance modulates teh sound with the help of a bit crsuher - the closer the ppl get to the object with the sensor the less the effect of the bitcrusher.
so far so good. 3 out of 5 are working, the last 2 though are not being detected by the port as soon as i insert the sd card in the audio shield. As soon as I insert it while the teensy is connected via usb to the computer the port serial port disappears.

Any ideas??

The show starts on friday, so i would reallyyyyy appreacite fast help :) :D

merci!


Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playWav1;       //xy=326,518
AudioSynthSimpleDrum     drum1;          //xy=343,424
AudioSynthNoiseWhite     noise1;         //xy=350,351
AudioEffectBitcrusher    bitcrusher1;    //xy=508,450
AudioEffectChorus         chorus1;        //xy=518,351
AudioMixer4              mixer1;         //xy=713,411
AudioOutputI2S           audioOutput;    //xy=861,442
AudioConnection          patchCord1(playWav1, 0, bitcrusher1, 0);
AudioConnection          patchCord2(drum1, 0, mixer1, 1);
AudioConnection          patchCord3(noise1, chorus1);
AudioConnection          patchCord4(bitcrusher1, 0, mixer1, 2);
AudioConnection          patchCord5(chorus1, 0, mixer1, 0);
AudioConnection          patchCord6(mixer1, 0, audioOutput, 0);
AudioConnection          patchCord7(mixer1, 0, audioOutput, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=440,688
// GUItool: end automatically generated code




// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14


long timeInterval = 10000;
unsigned long previousMillis;

// VL53L0X.h IR DISTANCE SENSOR SETUP

#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {
  //Serial.begin(9600);

  Serial.begin(115200);

  // wait until serial port opens for native USB devices
  //while (! Serial) {
  //delay(1);
  // }

  Serial.println("Adafruit VL53L0X test");
  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while (1);
  }
  // power
  Serial.println(F("VL53L0X API Simple Ranging example\n\n"));

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(8);

  // Comment these out if not using the audio adaptor board.
  // This may wait forever if the SDA & SCL pins lack
  // pullup resistors
  sgtl5000_1.enable();
  sgtl5000_1.volume(1);

  noise1.amplitude(0.3);

  mixer1.gain(0, 0.5);
  mixer1.gain(1, 0.5);
  mixer1.gain(2, 0.5);
  mixer1.gain(3, 0.5);

  bitcrusher1.bits(16);
  bitcrusher1.sampleRate(8000);  
  
  drum1.frequency(600);
  drum1.length(200);
  

  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here, but print a message repetitively
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}


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(25);

  // Simply wait for the file to finish playing.
  while (playWav1.isPlaying()) {
      VL53L0X_RangingMeasurementData_t measure;
      lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
      uint16_t distance = constrain(pow(measure.RangeMilliMeter, 1.0), 0, 1000);
      
      uint16_t crushAmount = map(distance, 0, 1000, 44100, 0);
    Serial.println(crushAmount);
      bitcrusher1.sampleRate(crushAmount);  

    // uncomment these lines if you audio shield
    // has the optional volume pot soldered
    //float vol = analogRead(15);
    //vol = vol / 1024;
    // sgtl5000_1.volume(vol);
   //   bitcrusher1.sampleRate(8000);  

  }
}


void loop() {
  unsigned long currentMillis = millis();

  VL53L0X_RangingMeasurementData_t measure;

  Serial.print("Reading a measurement... ");
  lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
  } else {
    Serial.println(" out of range ");
    mixer1.gain(0, 0.0);
    mixer1.gain(1, 0.0);
    
  }

  delay(100);


  if (measure.RangeMilliMeter < 600) {
    mixer1.gain(0, 0.1);
    //mixer1.gain(1, 0.1);
    playFile("HYPERL.WAV");  // filenames are always uppercase 8.3 format
    delay (500);
  } else if (measure.RangeMilliMeter < 2000){
    float vol = map(measure.RangeMilliMeter, 600, 2000, 100, 0);
    mixer1.gain(0, vol/100.0);
    //mixer1.gain(1, vol/100.0);
  }

  // play a sample every second
  if(currentMillis - previousMillis >= timeInterval) {
    previousMillis = currentMillis;
    mixer1.gain(1,0.8);
    drum1.noteOn();
    Serial.println("click");
  }
  
  /*

    else if (measure.RangeStatus < 800) {
    playFile("RAUSCHEN.WAV");  // filenames are always uppercase 8.3 format
    delay (500);
    }
    else if (measure.RangeStatus < 1000) {
    playFile("POTATO.WAV");  // filenames are always uppercase 8.3 format
    delay (500);
    }
    Serial.println(ldrVal);
    Serial.println(pot);
    delay(100);
  */
}
 
Nobody answered so far... hm

If this program works on the other boards, there is no reason why it shouldn't work on the problematic boards.
It must be a hardware issue, but nobody can say whats wrong without any information.
Probably a short?
 
Status
Not open for further replies.
Back
Top