Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 3 1 2 3 LastLast
Results 1 to 25 of 52

Thread: problem with 4.0

  1. #1

    problem with 4.0

    getting this error message i am a total newbie with this so be gentle plz

    Arduino: 1.8.19 (Windows 10), TD: 1.57, Board: "Teensy 4.0, Serial, 600 MHz, Faster, United Kingdom"

    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:129:0,

    Multiple libraries were found for "SD.h"

    from C:\Users\iandi\Documents\Arduino\Audio_GuestBook1\ Audio_GuestBook1.ino:31:

    Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio/play_serialflash_raw.h:33:25: fatal error: SerialFlash.h: No such file or directory

    Not used: C:\Program Files (x86)\Arduino\libraries\SD

    compilation terminated.

    Error compiling for board Teensy 4.0.



    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,707
    It's not finding the SerialFlash library.

    Simplest solution is the run the Teensyduino installer again. On the screen for which optional libraries to install, best to just install them all. SerialFlash is one of those. Audio needs it, even if you don't use that sort of memory chip, because it needs to compile code which could read from that type of memory.

    Sometimes lame anti-virus software or even Windows Defender can interfere with writing files to your hard drive. Usually this affects exe programs rather than source code file, but those anti-virus programs are really unpredictable. If you run the installer again and select all libraries, or at least make sure SerialFlash is checked, but this problem persists, you might need to temporarily disable anti-virus while running the installer. The installer does not use internet access in any way, so you can unplug from the internet while anti-virus is off, run the installer, then turn it back on and plug back into the net.

  3. #3
    re installed programme now getting this message


    Arduino: 1.8.19 (Windows 10), TD: 1.57, Board: "Teensy 4.0, Serial, 600 MHz, Faster, United Kingdom"

    sketch_feb01a: In function 'void loop()':

    sketch_feb01a:148: warning: enumeration value 'Initialising' not handled in switch

    switch(mode){

    ^

    sketch_feb01a: In function 'void playAllRecordings()':

    C:\Users\iandi\Documents\Arduino\Audio_GuestBook1\ sketch_feb01a\sketch_feb01a.ino:304:36: warning: invalid conversion from 'const char*' to 'char*' [-fpermissive]

    if (strstr(strlwr(entry.name() + (len - 4)), ".raw")) {

    ^

    In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\stdlib.h:11:0,

    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4/WProgram.h:34,

    from C:\Users\iandi\AppData\Local\Temp\arduino_build_89 9385\pch\Arduino.h:6:

    c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\string.h:150:7: note: initializing argument 1 of 'char* strlwr(char*)'

    char *_EXFUN(strlwr,(char *));

    ^

    sketch_feb01a: In function 'void setup()':

    sketch_feb01a:363: error: redefinition of 'void setup()'

    }void setup() {

    ^

    C:\Users\iandi\Documents\Arduino\Audio_GuestBook1\ sketch_feb01a\sketch_feb01a.ino:87:6: note: 'void setup()' previously defined here

    void setup() {

    ^

    sketch_feb01a: In function 'void loop()':

    sketch_feb01a:368: error: redefinition of 'void loop()'

    void loop() {

    ^

    C:\Users\iandi\Documents\Arduino\Audio_GuestBook1\ sketch_feb01a\sketch_feb01a.ino:143:6: note: 'void loop()' previously defined here

    void loop() {

    ^

    sketch_feb01a: In function 'void setup()':

    sketch_feb01a:371: error: redefinition of 'void setup()'

    }void setup() {

    ^

    C:\Users\iandi\Documents\Arduino\Audio_GuestBook1\ sketch_feb01a\sketch_feb01a.ino:87:6: note: 'void setup()' previously defined here

    void setup() {

    ^

    sketch_feb01a: In function 'void loop()':

    sketch_feb01a:376: error: redefinition of 'void loop()'

    void loop() {

    ^

    C:\Users\iandi\Documents\Arduino\Audio_GuestBook1\ sketch_feb01a\sketch_feb01a.ino:143:6: note: 'void loop()' previously defined here

    void loop() {

    ^

    Multiple libraries were found for "SD.h"

    Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD

    Not used: C:\Program Files (x86)\Arduino\libraries\SD

    redefinition of 'void setup()'



    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.


    this is the code i am trying to get to work

    Code:
    /**
     * Audio Guestbook, Copyright (c) 2022 Playful Technology
     * 
     * Tested using a Teensy 4.0 with Teensy Audio Shield, although should work 
     * with minor modifications on other similar hardware
     * 
     * When handset is lifted, a pre-recorded greeting message is played, followed by a tone.
     * Then, recording starts, and continues until the handset is replaced.
     * Playback button allows all messages currently saved on SD card through earpiece 
     * 
     * Files are saved on SD card as 44.1kHz, 16-bit, mono signed integer RAW audio format
     * These can be loaded directly into Audacity (https://www.audacityteam.org/). Or else, converted to WAV/MP3 format using SOX (https://sourceforge.net/projects/sox/)
     * 
     **/
     
    
    // **********   Rik  6/22/2022  -   My mods are marked with RAM in comments.  *********
    
    // ************  GREETING MUST BE RECORDED IN .RAW FORMAT  (16 BIT 44.1Khz. MONO)   ****************************************************************
    
    
    // INCLUDES
    // The default "sketchbook" location in which Arduino IDE installs libraries is:
    // C:\Users\alast\Documents\Arduino
    // However, the TeensyDuino installer installs libraries in:
    // C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries
    // To ensure the correct libraries are used when targetting Teensy platform in Arduino IDE, go File->Preferences and change the sketchbook location to avoid conflicts with Arduino libraries.
    // When targetting Arduino boards, change it back again to default
    #include <Bounce.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <TimeLib.h>
    
    
    // DEFINES
    // Define pins used by Teensy Audio Shield
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  7
    #define SDCARD_SCK_PIN   14
    // And those used for inputs
    #define HOOK_PIN 0
    #define PLAYBACK_BUTTON_PIN 1
    
     
    int     hookRead;  // Added to check for hang up before playing greeting.  RAM
    int     x;
    
    // GLOBALS
    // Audio initialisation code can be generated using the GUI interface at https://www.pjrc.com/teensy/gui/
    // Inputs
    AudioSynthWaveform      waveform1; // To create the "beep" sfx
    AudioInputI2S           i2s2; // I2S input from microphone on audio shield
    AudioPlaySdRaw          playRaw1; // Play .RAW audio files saved on SD card
    AudioPlaySdWav          playWav1; // Play 44.1kHz 16-bit PCM greeting WAV file
    // Outputs
    AudioRecordQueue         queue1; // Creating an audio buffer in memory before saving to SD
    AudioMixer4              mixer; // Allows merging several inputs to same output
    AudioOutputI2S           i2s1; // I2S interface to Speaker/Line Out on Audio shield
    // Connections
    AudioConnection patchCord1(waveform1, 0, mixer, 0); // wave to mixer 
    AudioConnection patchCord2(playRaw1, 0, mixer, 1); // raw audio to mixer
    AudioConnection patchCord3(playWav1, 0, mixer, 2); // wav file playback mixer
    AudioConnection patchCord4(mixer, 0, i2s1, 0); // mixer output to speaker (L)
    AudioConnection patchCord5(i2s2, 0, queue1, 0); // mic input to queue (L)
    
    AudioConnection patchcord6(i2s2, 0, mixer, 3); // Added mic input to mixer to hear talking through handset speaker.  RAM
    
    AudioControlSGTL5000     sgtl5000_1;
    
    // Filename to save audio recording on SD card
    char filename[15];
    // The file object itself
    File frec;
    
    // Use long 100ms debounce time on hook switch
    Bounce buttonRecord = Bounce(HOOK_PIN, 100);    // default (40).  RAM
    Bounce buttonPlay = Bounce(PLAYBACK_BUTTON_PIN, 100);   // default (8).  RAM
    
    
    
    // Keep track of current state of the device
    enum Mode {Initialising, Ready, Prompting, Recording, Playing};
    Mode mode = Mode::Initialising;
    
    void setup() {
    
      // Note that Serial.begin() is not required for Teensy - 
      // by default it initialises serial communication at full USB speed
      // See https://www.pjrc.com/teensy/td_serial.html
      // Serial.begin()
      Serial.println(__FILE__ __DATE__);
      
      // Configure the input pins
      pinMode(HOOK_PIN, INPUT_PULLUP);
      pinMode(PLAYBACK_BUTTON_PIN, INPUT_PULLUP);
    
      // Audio connections require memory, and the record queue
      // uses this memory to buffer incoming audio.
      AudioMemory(60);
    
      // Enable the audio shield, select input, and enable output
      sgtl5000_1.enable();
      // Define which input on the audio shield to use (AUDIO_INPUT_LINEIN / AUDIO_INPUT_MIC)
      sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
      
      sgtl5000_1.volume(0.6);  // Output speaker volume.  default (.5).   RAM
    
      // Play a beep to indicate system is online
      waveform1.begin(WAVEFORM_SINE);
      waveform1.frequency(440);
      waveform1.amplitude(0.9);
      wait(250);
      waveform1.amplitude(0);
      delay(1000);
    
      // Initialize the SD card
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
      if (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here if no SD card, but print a message
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
    
      // Mic Gain (Value in dB)
      sgtl5000_1.micGain(38);   // default (15).  RAM
    
      // Synchronise the Time object used in the program code with the RTC time provider.
      // See https://github.com/PaulStoffregen/Time
      setSyncProvider(getTeensy3Time);
      
      // Define a callback that will assign the correct datetime for any file system operations
      // (i.e. saving a new audio recording onto the SD card)
      FsDateTime::setCallback(dateTime);
    
      mode = Mode::Ready;
    }
    
    void loop() {
      // First, read the buttons
      buttonRecord.update();
      buttonPlay.update();
    
      switch(mode){
        case Mode::Ready:
          // Rising edge occurs when the handset is lifted
          if (buttonRecord.risingEdge()) {
            Serial.println("Handset lifted");
            mode = Mode::Prompting;
          }
          else if(buttonPlay.fallingEdge()) {
            playAllRecordings();
          }
          break;
          
    
        case Mode::Prompting:
    
        
                 // Wait a second for users to put the handset to their ear.   RAM
                 // Added to read hook pin to check if handset has been replaced before proceeding.  RAM
                          
          x=0;   // Clear counter.   
          while (x < 30)  {
            wait(50);   // Wait 50 mS.  
            x=x+1;      // Increment counter
            Serial.println(x);  // Print counter value
            hookRead=digitalRead(HOOK_PIN);  // Check if handset replaced.  
              if (hookRead==0)  {
              Serial.println("Handset Replaced Before Message");
              mode = Mode::Ready;  // Return to ready mode if hang up.
              return;
            }
          }
          
     
               
          // Play the greeting inviting them to record their message
          playRaw1.play("greeting.raw");    //  Changed from default (.wav) to (.raw) format.  Greeting MUST be recorded in .raw format.   RAM
          // Wait until the  message has finished playing
          while (playRaw1.isPlaying()) {
          
            // Check whether the handset is replaced
            buttonRecord.update();
            // Handset is replaced
            if(buttonRecord.fallingEdge()) {
              playRaw1.stop();
              mode = Mode::Ready;
              return;
    
              
            }
            
          }
          // Debug message
          Serial.println("Starting Recording");
          // Play the tone sound effect
          waveform1.frequency(440);
          waveform1.amplitude(0.9);
          wait(250);
          waveform1.amplitude(0);
          // Start the recording function
          startRecording();
          break;
    
        case Mode::Recording:
          // Handset is replaced
          if(buttonRecord.fallingEdge()){
            // Debug log
            Serial.println("Stopping Recording");
            // Stop recording
            stopRecording();
            // Play audio tone to confirm recording has ended
            waveform1.frequency(523.25);
            waveform1.amplitude(0.9);
            wait(50);
            waveform1.amplitude(0);
            wait(50);
            waveform1.amplitude(0.9);
            wait(50);
            waveform1.amplitude(0);
          }
          else {
            continueRecording();
          }
          break;
    
        case Mode::Playing:
          break;  
      }   
    }
    
    void startRecording() {
      // Find the first available file number
      for (uint8_t i=0; i<9999; i++) {
        // Format the counter as a five-digit number with leading zeroes, followed by file extension
        snprintf(filename, 11, " %05d.RAW", i);
        // Create if does not exist, do not open existing, write, sync after write
        if (!SD.exists(filename)) {
          break;
        }
      }
      frec = SD.open(filename, FILE_WRITE);
      if(frec) {
        Serial.print("Recording to ");
        Serial.println(filename);
        queue1.begin();
        mode = Mode::Recording;
      }
      else {
        Serial.println("Couldn't open file to record!");
      }
    }
    
    void continueRecording() {
      // Check if there is data in the queue
      if (queue1.available() >= 2) {
        byte buffer[512];
        // Fetch 2 blocks from the audio library and copy
        // into a 512 byte buffer.  The Arduino SD library
        // is most efficient when full 512 byte sector size
        // writes are used.
        memcpy(buffer, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        memcpy(buffer+256, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        // Write all 512 bytes to the SD card
        frec.write(buffer, 512);
      }
    }
    
    void stopRecording() {
      // Stop adding any new data to the queue
      queue1.end();
      // Flush all existing remaining data from the queue
      while (queue1.available() > 0) {
        // Save to open file
        frec.write((byte*)queue1.readBuffer(), 256);
        queue1.freeBuffer();
      }
      // Close the file
      frec.close();
      mode = Mode::Ready;
    }
    
    
    void playAllRecordings() {
      // Recording files are saved in the root directory
      File dir = SD.open("/");
      
      while (true) {
        File entry =  dir.openNextFile();
        if (!entry) {
          // no more files
          entry.close();
          break;
        }
    
        int8_t len = strlen(entry.name());
        if (strstr(strlwr(entry.name() + (len - 4)), ".raw")) {
          Serial.print("Now playing ");
          Serial.println(entry.name());
          // Play a short beep before each message
          waveform1.amplitude(0.5);
          wait(250);
          waveform1.amplitude(0);
          // Play the file
          playRaw1.play(entry.name());
          mode = Mode::Playing;
        }
        entry.close();
    
        while (playRaw1.isPlaying()) {
          buttonPlay.update();
          buttonRecord.update();
          // Button is pressed again
          if(buttonPlay.risingEdge() || buttonRecord.fallingEdge()) {
            playRaw1.stop();
            mode = Mode::Ready;
            return;
          }   
        }
      }
      // All files have been played
      mode = Mode::Ready;
    }
    
    // Retrieve the current time from Teensy built-in RTC
    time_t getTeensy3Time(){
      return Teensy3Clock.get();
    }
    
    // Callback to assign timestamps for file system operations
    void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
    
      // Return date using FS_DATE macro to format fields.
      *date = FS_DATE(year(), month(), day());
    
      // Return time using FS_TIME macro to format fields.
      *time = FS_TIME(hour(), minute(), second());
    
      // Return low time bits in units of 10 ms.
      *ms10 = second() & 1 ? 100 : 0;
    }
    
    // Non-blocking delay, which pauses execution of main program logic,
    // but while still listening for input 
    void wait(unsigned int milliseconds) {
      elapsedMillis msec=0;
    
      while (msec <= milliseconds) {
        buttonRecord.update();
        buttonPlay.update();
        if (buttonRecord.fallingEdge()) Serial.println("Button (pin 0) Press");
        if (buttonPlay.fallingEdge()) Serial.println("Button (pin 1) Press");
        if (buttonRecord.risingEdge()) Serial.println("Button (pin 0) Release");
        if (buttonPlay.risingEdge()) Serial.println("Button (pin 1) Release");
      }
    }void setup() {
      // put your setup code here, to run once:
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }void setup() {
      // put your setup code here, to run once:
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    Last edited by KurtE; 02-01-2023 at 12:14 PM. Reason: code tag

  4. #4
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    1,147
    Code:
    /**
     * Audio Guestbook, Copyright (c) 2022 Playful Technology
     *
     * Tested using a Teensy 4.0 with Teensy Audio Shield, although should work
     * with minor modifications on other similar hardware
     *
     * When handset is lifted, a pre-recorded greeting message is played, followed by a tone.
     * Then, recording starts, and continues until the handset is replaced.
     * Playback button allows all messages currently saved on SD card through earpiece
     *
     * Files are saved on SD card as 44.1kHz, 16-bit, mono signed integer RAW audio format
     * These can be loaded directly into Audacity (https://www.audacityteam.org/). Or else, converted to WAV/MP3 format using SOX (https://sourceforge.net/projects/sox/)
     *
     **/
    
    
     // **********   Rik  6/22/2022  -   My mods are marked with RAM in comments.  *********
    
     // ************  GREETING MUST BE RECORDED IN .RAW FORMAT  (16 BIT 44.1Khz. MONO)   ****************************************************************
    
    
     // INCLUDES
     // The default "sketchbook" location in which Arduino IDE installs libraries is:
     // C:\Users\alast\Documents\Arduino
     // However, the TeensyDuino installer installs libraries in:
     // C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries
     // To ensure the correct libraries are used when targetting Teensy platform in Arduino IDE, go File->Preferences and change the sketchbook location to avoid conflicts with Arduino libraries.
     // When targetting Arduino boards, change it back again to default
    #include <Bounce.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <TimeLib.h>
    
    
    // DEFINES
    // Define pins used by Teensy Audio Shield
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  7
    #define SDCARD_SCK_PIN   14
    // And those used for inputs
    #define HOOK_PIN 0
    #define PLAYBACK_BUTTON_PIN 1
    
    
    int     hookRead;  // Added to check for hang up before playing greeting.  RAM
    int     x;
    
    // GLOBALS
    // Audio initialisation code can be generated using the GUI interface at https://www.pjrc.com/teensy/gui/
    // Inputs
    AudioSynthWaveform      waveform1; // To create the "beep" sfx
    AudioInputI2S           i2s2; // I2S input from microphone on audio shield
    AudioPlaySdRaw          playRaw1; // Play .RAW audio files saved on SD card
    AudioPlaySdWav          playWav1; // Play 44.1kHz 16-bit PCM greeting WAV file
    // Outputs
    AudioRecordQueue         queue1; // Creating an audio buffer in memory before saving to SD
    AudioMixer4              mixer; // Allows merging several inputs to same output
    AudioOutputI2S           i2s1; // I2S interface to Speaker/Line Out on Audio shield
    // Connections
    AudioConnection patchCord1(waveform1, 0, mixer, 0); // wave to mixer 
    AudioConnection patchCord2(playRaw1, 0, mixer, 1); // raw audio to mixer
    AudioConnection patchCord3(playWav1, 0, mixer, 2); // wav file playback mixer
    AudioConnection patchCord4(mixer, 0, i2s1, 0); // mixer output to speaker (L)
    AudioConnection patchCord5(i2s2, 0, queue1, 0); // mic input to queue (L)
    
    AudioConnection patchcord6(i2s2, 0, mixer, 3); // Added mic input to mixer to hear talking through handset speaker.  RAM
    
    AudioControlSGTL5000     sgtl5000_1;
    
    // Filename to save audio recording on SD card
    char filename[15];
    // The file object itself
    File frec;
    
    // Use long 100ms debounce time on hook switch
    Bounce buttonRecord = Bounce(HOOK_PIN, 100);    // default (40).  RAM
    Bounce buttonPlay = Bounce(PLAYBACK_BUTTON_PIN, 100);   // default (8).  RAM
    
    
    
    // Keep track of current state of the device
    enum Mode { Initialising, Ready, Prompting, Recording, Playing };
    Mode mode = Mode::Initialising;
    
    void setup() {
    
        // Note that Serial.begin() is not required for Teensy - 
        // by default it initialises serial communication at full USB speed
        // See https://www.pjrc.com/teensy/td_serial.html
        // Serial.begin()
        Serial.println(__FILE__ __DATE__);
    
        // Configure the input pins
        pinMode(HOOK_PIN, INPUT_PULLUP);
        pinMode(PLAYBACK_BUTTON_PIN, INPUT_PULLUP);
    
        // Audio connections require memory, and the record queue
        // uses this memory to buffer incoming audio.
        AudioMemory(60);
    
        // Enable the audio shield, select input, and enable output
        sgtl5000_1.enable();
        // Define which input on the audio shield to use (AUDIO_INPUT_LINEIN / AUDIO_INPUT_MIC)
        sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
    
        sgtl5000_1.volume(0.6);  // Output speaker volume.  default (.5).   RAM
    
        // Play a beep to indicate system is online
        waveform1.begin(WAVEFORM_SINE);
        waveform1.frequency(440);
        waveform1.amplitude(0.9);
        wait(250);
        waveform1.amplitude(0);
        delay(1000);
    
        // Initialize the SD card
        SPI.setMOSI(SDCARD_MOSI_PIN);
        SPI.setSCK(SDCARD_SCK_PIN);
        if (!(SD.begin(SDCARD_CS_PIN))) {
            // stop here if no SD card, but print a message
            while (1) {
                Serial.println("Unable to access the SD card");
                delay(500);
            }
        }
    
        // Mic Gain (Value in dB)
        sgtl5000_1.micGain(38);   // default (15).  RAM
    
        // Synchronise the Time object used in the program code with the RTC time provider.
        // See https://github.com/PaulStoffregen/Time
        setSyncProvider(getTeensy3Time);
    
        // Define a callback that will assign the correct datetime for any file system operations
        // (i.e. saving a new audio recording onto the SD card)
        FsDateTime::setCallback(dateTime);
    
        mode = Mode::Ready;
    }
    
    void loop() {
        // First, read the buttons
        buttonRecord.update();
        buttonPlay.update();
    
        switch (mode) {
        case Mode::Ready:
            // Rising edge occurs when the handset is lifted
            if (buttonRecord.risingEdge()) {
                Serial.println("Handset lifted");
                mode = Mode::Prompting;
            }
            else if (buttonPlay.fallingEdge()) {
                playAllRecordings();
            }
            break;
    
    
        case Mode::Prompting:
    
    
            // Wait a second for users to put the handset to their ear.   RAM
            // Added to read hook pin to check if handset has been replaced before proceeding.  RAM
    
            x = 0;   // Clear counter.   
            while (x < 30) {
                wait(50);   // Wait 50 mS.  
                x = x + 1;      // Increment counter
                Serial.println(x);  // Print counter value
                hookRead = digitalRead(HOOK_PIN);  // Check if handset replaced.  
                if (hookRead == 0) {
                    Serial.println("Handset Replaced Before Message");
                    mode = Mode::Ready;  // Return to ready mode if hang up.
                    return;
                }
            }
    
    
    
            // Play the greeting inviting them to record their message
            playRaw1.play("greeting.raw");    //  Changed from default (.wav) to (.raw) format.  Greeting MUST be recorded in .raw format.   RAM
            // Wait until the  message has finished playing
            while (playRaw1.isPlaying()) {
    
                // Check whether the handset is replaced
                buttonRecord.update();
                // Handset is replaced
                if (buttonRecord.fallingEdge()) {
                    playRaw1.stop();
                    mode = Mode::Ready;
                    return;
    
    
                }
    
            }
            // Debug message
            Serial.println("Starting Recording");
            // Play the tone sound effect
            waveform1.frequency(440);
            waveform1.amplitude(0.9);
            wait(250);
            waveform1.amplitude(0);
            // Start the recording function
            startRecording();
            break;
    
        case Mode::Recording:
            // Handset is replaced
            if (buttonRecord.fallingEdge()) {
                // Debug log
                Serial.println("Stopping Recording");
                // Stop recording
                stopRecording();
                // Play audio tone to confirm recording has ended
                waveform1.frequency(523.25);
                waveform1.amplitude(0.9);
                wait(50);
                waveform1.amplitude(0);
                wait(50);
                waveform1.amplitude(0.9);
                wait(50);
                waveform1.amplitude(0);
            }
            else {
                continueRecording();
            }
            break;
    
        case Mode::Playing:
            break;
        }
    }
    
    void startRecording() {
        // Find the first available file number
        for (uint8_t i = 0; i < 9999; i++) {
            // Format the counter as a five-digit number with leading zeroes, followed by file extension
            snprintf(filename, 11, " %05d.RAW", i);
            // Create if does not exist, do not open existing, write, sync after write
            if (!SD.exists(filename)) {
                break;
            }
        }
        frec = SD.open(filename, FILE_WRITE);
        if (frec) {
            Serial.print("Recording to ");
            Serial.println(filename);
            queue1.begin();
            mode = Mode::Recording;
        }
        else {
            Serial.println("Couldn't open file to record!");
        }
    }
    
    void continueRecording() {
        // Check if there is data in the queue
        if (queue1.available() >= 2) {
            byte buffer[512];
            // Fetch 2 blocks from the audio library and copy
            // into a 512 byte buffer.  The Arduino SD library
            // is most efficient when full 512 byte sector size
            // writes are used.
            memcpy(buffer, queue1.readBuffer(), 256);
            queue1.freeBuffer();
            memcpy(buffer + 256, queue1.readBuffer(), 256);
            queue1.freeBuffer();
            // Write all 512 bytes to the SD card
            frec.write(buffer, 512);
        }
    }
    
    void stopRecording() {
        // Stop adding any new data to the queue
        queue1.end();
        // Flush all existing remaining data from the queue
        while (queue1.available() > 0) {
            // Save to open file
            frec.write((byte*)queue1.readBuffer(), 256);
            queue1.freeBuffer();
        }
        // Close the file
        frec.close();
        mode = Mode::Ready;
    }
    
    
    void playAllRecordings() {
        // Recording files are saved in the root directory
        File dir = SD.open("/");
    
        while (true) {
            File entry = dir.openNextFile();
            if (!entry) {
                // no more files
                entry.close();
                break;
            }
    
            int8_t len = strlen(entry.name());
            if (strstr(strlwr(entry.name() + (len - 4)), ".raw")) {
                Serial.print("Now playing ");
                Serial.println(entry.name());
                // Play a short beep before each message
                waveform1.amplitude(0.5);
                wait(250);
                waveform1.amplitude(0);
                // Play the file
                playRaw1.play(entry.name());
                mode = Mode::Playing;
            }
            entry.close();
    
            while (playRaw1.isPlaying()) {
                buttonPlay.update();
                buttonRecord.update();
                // Button is pressed again
                if (buttonPlay.risingEdge() || buttonRecord.fallingEdge()) {
                    playRaw1.stop();
                    mode = Mode::Ready;
                    return;
                }
            }
        }
        // All files have been played
        mode = Mode::Ready;
    }
    
    // Retrieve the current time from Teensy built-in RTC
    time_t getTeensy3Time() {
        return Teensy3Clock.get();
    }
    
    // Callback to assign timestamps for file system operations
    void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
    
        // Return date using FS_DATE macro to format fields.
        *date = FS_DATE(year(), month(), day());
    
        // Return time using FS_TIME macro to format fields.
        *time = FS_TIME(hour(), minute(), second());
    
        // Return low time bits in units of 10 ms.
        *ms10 = second() & 1 ? 100 : 0;
    }
    
    // Non-blocking delay, which pauses execution of main program logic,
    // but while still listening for input 
    void wait(unsigned int milliseconds) {
        elapsedMillis msec = 0;
    
        while (msec <= milliseconds) {
            buttonRecord.update();
            buttonPlay.update();
            if (buttonRecord.fallingEdge()) Serial.println("Button (pin 0) Press");
            if (buttonPlay.fallingEdge()) Serial.println("Button (pin 1) Press");
            if (buttonRecord.risingEdge()) Serial.println("Button (pin 0) Release");
            if (buttonPlay.risingEdge()) Serial.println("Button (pin 1) Release");
        }
    }void setup() {
        // put your setup code here, to run once:
    
    }
    
    void loop() {
        // put your main code here, to run repeatedly:
    
    }void setup() {
        // put your setup code here, to run once:
    
    }
    
    void loop() {
        // put your main code here, to run repeatedly:
    
    }
    When posting code please enclose it between CODE tags using the # button at the top of the entry form.
    It makes the code much easier to read, understand and therefore de-bug.
    Your problem is that you have more than one occurrences of void setup and void loop (See the end of the code you have posted here). In fact you have three of each.
    Looks like you have been copy and pasting your code.
    Last edited by BriComp; 02-01-2023 at 12:28 PM.

  5. #5
    im new to this how do i sort it plz not a programmer lol

  6. #6
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    1,147
    Delete this.....
    Code:
    void setup() {
        // put your setup code here, to run once:
    
    }
    
    void loop() {
        // put your main code here, to run repeatedly:
    
    }void setup() {
        // put your setup code here, to run once:
    
    }
    
    void loop() {
        // put your main code here, to run repeatedly:
    
    }
    ... from the end of your program.

  7. #7
    done that got this now
    Arduino: 1.8.19 (Windows 10), TD: 1.57, Board: "Teensy 4.0, Serial, 600 MHz, Faster, United Kingdom"

    Audio_2: In function 'void loop()':

    Audio_2:148: warning: enumeration value 'Initialising' not handled in switch

    switch(mode){

    ^

    Audio_2: In function 'void playAllRecordings()':

    C:\Users\iandi\Documents\Arduino\Audio_GuestBook1\ Audio_2\Audio_2.ino:304:36: warning: invalid conversion from 'const char*' to 'char*' [-fpermissive]

    if (strstr(strlwr(entry.name() + (len - 4)), ".raw")) {

    ^

    In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\stdlib.h:11:0,

    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4/WProgram.h:34,

    from C:\Users\iandi\AppData\Local\Temp\arduino_build_59 8846\pch\Arduino.h:6:

    c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\string.h:150:7: note: initializing argument 1 of 'char* strlwr(char*)'

    char *_EXFUN(strlwr,(char *));

    ^

    Audio_2: In function 'void wait(unsigned int)':

    Audio_2:362: error: expected '}' at end of input

    }

    ^

    Multiple libraries were found for "SD.h"

    Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD

    Not used: C:\Program Files (x86)\Arduino\libraries\SD

    expected '}' at end of input



    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,707
    Please remember, we can't see your screen. Showing us the error messages is good, but not enough. We also need to see the code that was in the Arduino window.

    When posting the code, in Arduino type CTRL-A to select all and CTRL-C to copy to clipboard. Then here on the forum, click the # button in the forum's editor toolbar (it's the last one, on the right hand side). You'll see the code tags appear, with the cursor positioned between them. Press CTRL-V to paste all the code, between those special tags. Doing it that way makes it easier for us to see it properly and better help figure out what's really wrong.

    It's ok, we can help you, but we need to see what you've done.

  9. #9
    Code:
    /**
     * Audio Guestbook, Copyright (c) 2022 Playful Technology
     * 
     * Tested using a Teensy 4.0 with Teensy Audio Shield, although should work 
     * with minor modifications on other similar hardware
     * 
     * When handset is lifted, a pre-recorded greeting message is played, followed by a tone.
     * Then, recording starts, and continues until the handset is replaced.
     * Playback button allows all messages currently saved on SD card through earpiece 
     * 
     * Files are saved on SD card as 44.1kHz, 16-bit, mono signed integer RAW audio format
     * These can be loaded directly into Audacity (https://www.audacityteam.org/). Or else, converted to WAV/MP3 format using SOX (https://sourceforge.net/projects/sox/)
     * 
     **/
     
    
    // **********   Rik  6/22/2022  -   My mods are marked with RAM in comments.  *********
    
    // ************  GREETING MUST BE RECORDED IN .RAW FORMAT  (16 BIT 44.1Khz. MONO)   ****************************************************************
    
    
    // INCLUDES
    // The default "sketchbook" location in which Arduino IDE installs libraries is:
    // C:\Users\alast\Documents\Arduino
    // However, the TeensyDuino installer installs libraries in:
    // C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries
    // To ensure the correct libraries are used when targetting Teensy platform in Arduino IDE, go File->Preferences and change the sketchbook location to avoid conflicts with Arduino libraries.
    // When targetting Arduino boards, change it back again to default
    #include <Bounce.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <TimeLib.h>
    
    
    // DEFINES
    // Define pins used by Teensy Audio Shield
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  7
    #define SDCARD_SCK_PIN   14
    // And those used for inputs
    #define HOOK_PIN 0
    #define PLAYBACK_BUTTON_PIN 1
    
     
    int     hookRead;  // Added to check for hang up before playing greeting.  RAM
    int     x;
    
    // GLOBALS
    // Audio initialisation code can be generated using the GUI interface at https://www.pjrc.com/teensy/gui/
    // Inputs
    AudioSynthWaveform      waveform1; // To create the "beep" sfx
    AudioInputI2S           i2s2; // I2S input from microphone on audio shield
    AudioPlaySdRaw          playRaw1; // Play .RAW audio files saved on SD card
    AudioPlaySdWav          playWav1; // Play 44.1kHz 16-bit PCM greeting WAV file
    // Outputs
    AudioRecordQueue         queue1; // Creating an audio buffer in memory before saving to SD
    AudioMixer4              mixer; // Allows merging several inputs to same output
    AudioOutputI2S           i2s1; // I2S interface to Speaker/Line Out on Audio shield
    // Connections
    AudioConnection patchCord1(waveform1, 0, mixer, 0); // wave to mixer 
    AudioConnection patchCord2(playRaw1, 0, mixer, 1); // raw audio to mixer
    AudioConnection patchCord3(playWav1, 0, mixer, 2); // wav file playback mixer
    AudioConnection patchCord4(mixer, 0, i2s1, 0); // mixer output to speaker (L)
    AudioConnection patchCord5(i2s2, 0, queue1, 0); // mic input to queue (L)
    
    AudioConnection patchcord6(i2s2, 0, mixer, 3); // Added mic input to mixer to hear talking through handset speaker.  RAM
    
    AudioControlSGTL5000     sgtl5000_1;
    
    // Filename to save audio recording on SD card
    char filename[15];
    // The file object itself
    File frec;
    
    // Use long 100ms debounce time on hook switch
    Bounce buttonRecord = Bounce(HOOK_PIN, 100);    // default (40).  RAM
    Bounce buttonPlay = Bounce(PLAYBACK_BUTTON_PIN, 100);   // default (8).  RAM
    
    
    
    // Keep track of current state of the device
    enum Mode {Initialising, Ready, Prompting, Recording, Playing};
    Mode mode = Mode::Initialising;
    
    void setup() {
    
      // Note that Serial.begin() is not required for Teensy - 
      // by default it initialises serial communication at full USB speed
      // See https://www.pjrc.com/teensy/td_serial.html
      // Serial.begin()
      Serial.println(__FILE__ __DATE__);
      
      // Configure the input pins
      pinMode(HOOK_PIN, INPUT_PULLUP);
      pinMode(PLAYBACK_BUTTON_PIN, INPUT_PULLUP);
    
      // Audio connections require memory, and the record queue
      // uses this memory to buffer incoming audio.
      AudioMemory(60);
    
      // Enable the audio shield, select input, and enable output
      sgtl5000_1.enable();
      // Define which input on the audio shield to use (AUDIO_INPUT_LINEIN / AUDIO_INPUT_MIC)
      sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
      
      sgtl5000_1.volume(0.6);  // Output speaker volume.  default (.5).   RAM
    
      // Play a beep to indicate system is online
      waveform1.begin(WAVEFORM_SINE);
      waveform1.frequency(440);
      waveform1.amplitude(0.9);
      wait(250);
      waveform1.amplitude(0);
      delay(1000);
    
      // Initialize the SD card
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
      if (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here if no SD card, but print a message
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
    
      // Mic Gain (Value in dB)
      sgtl5000_1.micGain(38);   // default (15).  RAM
    
      // Synchronise the Time object used in the program code with the RTC time provider.
      // See https://github.com/PaulStoffregen/Time
      setSyncProvider(getTeensy3Time);
      
      // Define a callback that will assign the correct datetime for any file system operations
      // (i.e. saving a new audio recording onto the SD card)
      FsDateTime::setCallback(dateTime);
    
      mode = Mode::Ready;
    }
    
    void loop() {
      // First, read the buttons
      buttonRecord.update();
      buttonPlay.update();
    
      switch(mode){
        case Mode::Ready:
          // Rising edge occurs when the handset is lifted
          if (buttonRecord.risingEdge()) {
            Serial.println("Handset lifted");
            mode = Mode::Prompting;
          }
          else if(buttonPlay.fallingEdge()) {
            playAllRecordings();
          }
          break;
          
    
        case Mode::Prompting:
    
        
                 // Wait a second for users to put the handset to their ear.   RAM
                 // Added to read hook pin to check if handset has been replaced before proceeding.  RAM
                          
          x=0;   // Clear counter.   
          while (x < 30)  {
            wait(50);   // Wait 50 mS.  
            x=x+1;      // Increment counter
            Serial.println(x);  // Print counter value
            hookRead=digitalRead(HOOK_PIN);  // Check if handset replaced.  
              if (hookRead==0)  {
              Serial.println("Handset Replaced Before Message");
              mode = Mode::Ready;  // Return to ready mode if hang up.
              return;
            }
          }
          
     
               
          // Play the greeting inviting them to record their message
          playRaw1.play("greeting.raw");    //  Changed from default (.wav) to (.raw) format.  Greeting MUST be recorded in .raw format.   RAM
          // Wait until the  message has finished playing
          while (playRaw1.isPlaying()) {
          
            // Check whether the handset is replaced
            buttonRecord.update();
            // Handset is replaced
            if(buttonRecord.fallingEdge()) {
              playRaw1.stop();
              mode = Mode::Ready;
              return;
    
              
            }
            
          }
          // Debug message
          Serial.println("Starting Recording");
          // Play the tone sound effect
          waveform1.frequency(440);
          waveform1.amplitude(0.9);
          wait(250);
          waveform1.amplitude(0);
          // Start the recording function
          startRecording();
          break;
    
        case Mode::Recording:
          // Handset is replaced
          if(buttonRecord.fallingEdge()){
            // Debug log
            Serial.println("Stopping Recording");
            // Stop recording
            stopRecording();
            // Play audio tone to confirm recording has ended
            waveform1.frequency(523.25);
            waveform1.amplitude(0.9);
            wait(50);
            waveform1.amplitude(0);
            wait(50);
            waveform1.amplitude(0.9);
            wait(50);
            waveform1.amplitude(0);
          }
          else {
            continueRecording();
          }
          break;
    
        case Mode::Playing:
          break;  
      }   
    }
    
    void startRecording() {
      // Find the first available file number
      for (uint8_t i=0; i<9999; i++) {
        // Format the counter as a five-digit number with leading zeroes, followed by file extension
        snprintf(filename, 11, " %05d.RAW", i);
        // Create if does not exist, do not open existing, write, sync after write
        if (!SD.exists(filename)) {
          break;
        }
      }
      frec = SD.open(filename, FILE_WRITE);
      if(frec) {
        Serial.print("Recording to ");
        Serial.println(filename);
        queue1.begin();
        mode = Mode::Recording;
      }
      else {
        Serial.println("Couldn't open file to record!");
      }
    }
    
    void continueRecording() {
      // Check if there is data in the queue
      if (queue1.available() >= 2) {
        byte buffer[512];
        // Fetch 2 blocks from the audio library and copy
        // into a 512 byte buffer.  The Arduino SD library
        // is most efficient when full 512 byte sector size
        // writes are used.
        memcpy(buffer, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        memcpy(buffer+256, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        // Write all 512 bytes to the SD card
        frec.write(buffer, 512);
      }
    }
    
    void stopRecording() {
      // Stop adding any new data to the queue
      queue1.end();
      // Flush all existing remaining data from the queue
      while (queue1.available() > 0) {
        // Save to open file
        frec.write((byte*)queue1.readBuffer(), 256);
        queue1.freeBuffer();
      }
      // Close the file
      frec.close();
      mode = Mode::Ready;
    }
    
    
    void playAllRecordings() {
      // Recording files are saved in the root directory
      File dir = SD.open("/");
      
      while (true) {
        File entry =  dir.openNextFile();
        if (!entry) {
          // no more files
          entry.close();
          break;
        }
    
        int8_t len = strlen(entry.name());
        if (strstr(strlwr(entry.name() + (len - 4)), ".raw")) {
          Serial.print("Now playing ");
          Serial.println(entry.name());
          // Play a short beep before each message
          waveform1.amplitude(0.5);
          wait(250);
          waveform1.amplitude(0);
          // Play the file
          playRaw1.play(entry.name());
          mode = Mode::Playing;
        }
        entry.close();
    
        while (playRaw1.isPlaying()) {
          buttonPlay.update();
          buttonRecord.update();
          // Button is pressed again
          if(buttonPlay.risingEdge() || buttonRecord.fallingEdge()) {
            playRaw1.stop();
            mode = Mode::Ready;
            return;
          }   
        }
      }
      // All files have been played
      mode = Mode::Ready;
    }
    
    // Retrieve the current time from Teensy built-in RTC
    time_t getTeensy3Time(){
      return Teensy3Clock.get();
    }
    
    // Callback to assign timestamps for file system operations
    void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
    
      // Return date using FS_DATE macro to format fields.
      *date = FS_DATE(year(), month(), day());
    
      // Return time using FS_TIME macro to format fields.
      *time = FS_TIME(hour(), minute(), second());
    
      // Return low time bits in units of 10 ms.
      *ms10 = second() & 1 ? 100 : 0;
    }
    
    // Non-blocking delay, which pauses execution of main program logic,
    // but while still listening for input 
    void wait(unsigned int milliseconds) {
      elapsedMillis msec=0;
    
      while (msec <= milliseconds) {
        buttonRecord.update();
        buttonPlay.update();
        if (buttonRecord.fallingEdge()) Serial.println("Button (pin 0) Press");
        if (buttonPlay.fallingEdge()) Serial.println("Button (pin 1) Press");
        if (buttonRecord.risingEdge()) Serial.println("Button (pin 0) Release");
        if (buttonPlay.risingEdge()) Serial.println("Button (pin 1) Release");

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,707
    Looks like you accidentally deleted the last part of the program, while trying to get rid of the extra junk that was at the end.

    Recommend finding the original code again. Probably best to just open a new Arduino window. Delete the template stuff Arduino automatically puts into every new window (this is probably where things went wrong last time), so you have a completely blank window. Then carefully select all of the code. Before pressing CTRL-C to copy to clipboard, visually double check to make sure you got it all selected and you did not accidentally select any extra stuff.

  11. #11
    paul can u message me plz so i can send you what i have

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,707
    Just post it here. I answer tech questions here, not by private messages.

  13. #13
    Code:
    Code:
    /**
     * Audio Guestbook, Copyright (c) 2022 Playful Technology
     * 
     * Tested using a Teensy 4.0 with Teensy Audio Shield, although should work 
     * with minor modifications on other similar hardware
     * 
     * When handset is lifted, a pre-recorded greeting message is played, followed by a tone.
     * Then, recording starts, and continues until the handset is replaced.
     * Playback button allows all messages currently saved on SD card through earpiece 
     * 
     * Files are saved on SD card as 44.1kHz, 16-bit, mono signed integer RAW audio format
     * These can be loaded directly into Audacity (https://www.audacityteam.org/). Or else, converted to WAV/MP3 format using SOX (https://sourceforge.net/projects/sox/)
     * 
     **/
     
    
    // **********   Rik  6/22/2022  -   My mods are marked with RAM in comments.  *********
    
    // ************  GREETING MUST BE RECORDED IN .RAW FORMAT  (16 BIT 44.1Khz. MONO)   ****************************************************************
    
    
    // INCLUDES
    // The default "sketchbook" location in which Arduino IDE installs libraries is:
    // C:\Users\alast\Documents\Arduino
    // However, the TeensyDuino installer installs libraries in:
    // C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries
    // To ensure the correct libraries are used when targetting Teensy platform in Arduino IDE, go File->Preferences and change the sketchbook location to avoid conflicts with Arduino libraries.
    // When targetting Arduino boards, change it back again to default
    #include <Bounce.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <TimeLib.h>
    
    
    // DEFINES
    // Define pins used by Teensy Audio Shield
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  7
    #define SDCARD_SCK_PIN   14
    // And those used for inputs
    #define HOOK_PIN 0
    #define PLAYBACK_BUTTON_PIN 1
    
     
    int     hookRead;  // Added to check for hang up before playing greeting.  RAM
    int     x;
    
    // GLOBALS
    // Audio initialisation code can be generated using the GUI interface at https://www.pjrc.com/teensy/gui/
    // Inputs
    AudioSynthWaveform      waveform1; // To create the "beep" sfx
    AudioInputI2S           i2s2; // I2S input from microphone on audio shield
    AudioPlaySdRaw          playRaw1; // Play .RAW audio files saved on SD card
    AudioPlaySdWav          playWav1; // Play 44.1kHz 16-bit PCM greeting WAV file
    // Outputs
    AudioRecordQueue         queue1; // Creating an audio buffer in memory before saving to SD
    AudioMixer4              mixer; // Allows merging several inputs to same output
    AudioOutputI2S           i2s1; // I2S interface to Speaker/Line Out on Audio shield
    // Connections
    AudioConnection patchCord1(waveform1, 0, mixer, 0); // wave to mixer 
    AudioConnection patchCord2(playRaw1, 0, mixer, 1); // raw audio to mixer
    AudioConnection patchCord3(playWav1, 0, mixer, 2); // wav file playback mixer
    AudioConnection patchCord4(mixer, 0, i2s1, 0); // mixer output to speaker (L)
    AudioConnection patchCord5(i2s2, 0, queue1, 0); // mic input to queue (L)
    
    AudioConnection patchcord6(i2s2, 0, mixer, 3); // Added mic input to mixer to hear talking through handset speaker.  RAM
    
    AudioControlSGTL5000     sgtl5000_1;
    
    // Filename to save audio recording on SD card
    char filename[15];
    // The file object itself
    File frec;
    
    // Use long 100ms debounce time on hook switch
    Bounce buttonRecord = Bounce(HOOK_PIN, 100);    // default (40).  RAM
    Bounce buttonPlay = Bounce(PLAYBACK_BUTTON_PIN, 100);   // default (8).  RAM
    
    
    
    // Keep track of current state of the device
    enum Mode {Initialising, Ready, Prompting, Recording, Playing};
    Mode mode = Mode::Initialising;
    
    void setup() {
    
      // Note that Serial.begin() is not required for Teensy - 
      // by default it initialises serial communication at full USB speed
      // See https://www.pjrc.com/teensy/td_serial.html
      // Serial.begin()
      Serial.println(__FILE__ __DATE__);
      
      // Configure the input pins
      pinMode(HOOK_PIN, INPUT_PULLUP);
      pinMode(PLAYBACK_BUTTON_PIN, INPUT_PULLUP);
    
      // Audio connections require memory, and the record queue
      // uses this memory to buffer incoming audio.
      AudioMemory(60);
    
      // Enable the audio shield, select input, and enable output
      sgtl5000_1.enable();
      // Define which input on the audio shield to use (AUDIO_INPUT_LINEIN / AUDIO_INPUT_MIC)
      sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
      
      sgtl5000_1.volume(0.6);  // Output speaker volume.  default (.5).   RAM
    
      // Play a beep to indicate system is online
      waveform1.begin(WAVEFORM_SINE);
      waveform1.frequency(440);
      waveform1.amplitude(0.9);
      wait(250);
      waveform1.amplitude(0);
      delay(1000);
    
      // Initialize the SD card
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
      if (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here if no SD card, but print a message
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
    
      // Mic Gain (Value in dB)
      sgtl5000_1.micGain(38);   // default (15).  RAM
    
      // Synchronise the Time object used in the program code with the RTC time provider.
      // See https://github.com/PaulStoffregen/Time
      setSyncProvider(getTeensy3Time);
      
      // Define a callback that will assign the correct datetime for any file system operations
      // (i.e. saving a new audio recording onto the SD card)
      FsDateTime::setCallback(dateTime);
    
      mode = Mode::Ready;
    }
    
    void loop() {
      // First, read the buttons
      buttonRecord.update();
      buttonPlay.update();
    
      switch(mode){
        case Mode::Ready:
          // Rising edge occurs when the handset is lifted
          if (buttonRecord.risingEdge()) {
            Serial.println("Handset lifted");
            mode = Mode::Prompting;
          }
          else if(buttonPlay.fallingEdge()) {
            playAllRecordings();
          }
          break;
          
    
        case Mode::Prompting:
    
        
                 // Wait a second for users to put the handset to their ear.   RAM
                 // Added to read hook pin to check if handset has been replaced before proceeding.  RAM
                          
          x=0;   // Clear counter.   
          while (x < 30)  {
            wait(50);   // Wait 50 mS.  
            x=x+1;      // Increment counter
            Serial.println(x);  // Print counter value
            hookRead=digitalRead(HOOK_PIN);  // Check if handset replaced.  
              if (hookRead==0)  {
              Serial.println("Handset Replaced Before Message");
              mode = Mode::Ready;  // Return to ready mode if hang up.
              return;
            }
          }
          
     
               
          // Play the greeting inviting them to record their message
          playRaw1.play("greeting.raw");    //  Changed from default (.wav) to (.raw) format.  Greeting MUST be recorded in .raw format.   RAM
          // Wait until the  message has finished playing
          while (playRaw1.isPlaying()) {
          
            // Check whether the handset is replaced
            buttonRecord.update();
            // Handset is replaced
            if(buttonRecord.fallingEdge()) {
              playRaw1.stop();
              mode = Mode::Ready;
              return;
    
              
            }
            
          }
          // Debug message
          Serial.println("Starting Recording");
          // Play the tone sound effect
          waveform1.frequency(440);
          waveform1.amplitude(0.9);
          wait(250);
          waveform1.amplitude(0);
          // Start the recording function
          startRecording();
          break;
    
        case Mode::Recording:
          // Handset is replaced
          if(buttonRecord.fallingEdge()){
            // Debug log
            Serial.println("Stopping Recording");
            // Stop recording
            stopRecording();
            // Play audio tone to confirm recording has ended
            waveform1.frequency(523.25);
            waveform1.amplitude(0.9);
            wait(50);
            waveform1.amplitude(0);
            wait(50);
            waveform1.amplitude(0.9);
            wait(50);
            waveform1.amplitude(0);
          }
          else {
            continueRecording();
          }
          break;
    
        case Mode::Playing:
          break;  
      }   
    }
    
    void startRecording() {
      // Find the first available file number
      for (uint8_t i=0; i<9999; i++) {
        // Format the counter as a five-digit number with leading zeroes, followed by file extension
        snprintf(filename, 11, " %05d.RAW", i);
        // Create if does not exist, do not open existing, write, sync after write
        if (!SD.exists(filename)) {
          break;
        }
      }
      frec = SD.open(filename, FILE_WRITE);
      if(frec) {
        Serial.print("Recording to ");
        Serial.println(filename);
        queue1.begin();
        mode = Mode::Recording;
      }
      else {
        Serial.println("Couldn't open file to record!");
      }
    }
    
    void continueRecording() {
      // Check if there is data in the queue
      if (queue1.available() >= 2) {
        byte buffer[512];
        // Fetch 2 blocks from the audio library and copy
        // into a 512 byte buffer.  The Arduino SD library
        // is most efficient when full 512 byte sector size
        // writes are used.
        memcpy(buffer, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        memcpy(buffer+256, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        // Write all 512 bytes to the SD card
        frec.write(buffer, 512);
      }
    }
    
    void stopRecording() {
      // Stop adding any new data to the queue
      queue1.end();
      // Flush all existing remaining data from the queue
      while (queue1.available() > 0) {
        // Save to open file
        frec.write((byte*)queue1.readBuffer(), 256);
        queue1.freeBuffer();
      }
      // Close the file
      frec.close();
      mode = Mode::Ready;
    }
    
    
    void playAllRecordings() {
      // Recording files are saved in the root directory
      File dir = SD.open("/");
      
      while (true) {
        File entry =  dir.openNextFile();
        if (!entry) {
          // no more files
          entry.close();
          break;
        }
    
        int8_t len = strlen(entry.name());
        if (strstr(strlwr(entry.name() + (len - 4)), ".raw")) {
          Serial.print("Now playing ");
          Serial.println(entry.name());
          // Play a short beep before each message
          waveform1.amplitude(0.5);
          wait(250);
          waveform1.amplitude(0);
          // Play the file
          playRaw1.play(entry.name());
          mode = Mode::Playing;
        }
        entry.close();
    
        while (playRaw1.isPlaying()) {
          buttonPlay.update();
          buttonRecord.update();
          // Button is pressed again
          if(buttonPlay.risingEdge() || buttonRecord.fallingEdge()) {
            playRaw1.stop();
            mode = Mode::Ready;
            return;
          }   
        }
      }
      // All files have been played
      mode = Mode::Ready;
    }
    
    // Retrieve the current time from Teensy built-in RTC
    time_t getTeensy3Time(){
      return Teensy3Clock.get();
    }
    
    // Callback to assign timestamps for file system operations
    void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
    
      // Return date using FS_DATE macro to format fields.
      *date = FS_DATE(year(), month(), day());
    
      // Return time using FS_TIME macro to format fields.
      *time = FS_TIME(hour(), minute(), second());
    
      // Return low time bits in units of 10 ms.
      *ms10 = second() & 1 ? 100 : 0;
    }
    
    // Non-blocking delay, which pauses execution of main program logic,
    // but while still listening for input 
    void wait(unsigned int milliseconds) {
      elapsedMillis msec=0;
    
      while (msec <= milliseconds) {
        buttonRecord.update();
        buttonPlay.update();
        if (buttonRecord.fallingEdge()) Serial.println("Button (pin 0) Press");
        if (buttonPlay.fallingEdge()) Serial.println("Button (pin 1) Press");
        if (buttonRecord.risingEdge()) Serial.println("Button (pin 0) Release");
        if (buttonPlay.risingEdge()) Serial.println("Button (pin 1) Release");

  14. #14
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    1,147
    Quit out of the Arduino IDE.
    Go into your Documents folder, then into Arduino (Documents\Arduino) and delete all Audio Guestbook entries.

    Go to https://github.com/playfultechnology/audio-guestbook and download the Audio-Guestbook code by clicking on the green button labelled <> Code.
    Click on Download ZIP

    Navigate to your "Downloads" folder. Open the audio-guestbook-main.zip zip folder by double clicking on it.
    Right click on audio-guestbook-main and select copy.
    Navigate to your Documents folder then to the Arduino folder as above.
    Right click on some "white Space" and select paste.
    You will now have a NEW CLEAN version of the audio guestbook.
    Start up the Arduino IDE.
    Select File..audio-guestbook-main...and open the audio-guestbook by double clicking on audio-guestbook.ino.

  15. #15
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,707
    Same problem as msg #9, the last essential part of the program was deleted by mistake.

    Hopefully this picture can make it clearer?

    Click image for larger version. 

Name:	screenshot.png 
Views:	10 
Size:	161.2 KB 
ID:	30290

    Please find the original code. Scroll to the end of the Arduino window and carefully compare it. Even if none of the code makes any sense, you can hopefully see whether you got it all properly copied.

  16. #16
    arduino ide dont see my board

    now getting this message with fresh install

    Arduino: 1.8.19 (Windows 10), TD: 1.57-beta1, Board: "Teensy 4.0, Serial, 600 MHz, Faster, United Kingdom"

    C:\Users\iandi\Documents\Arduino\audio-guestbook-main\audio-guestbook\audio-guestbook.ino:30:24: fatal error: MTP_Teensy.h: No such file or directory

    Multiple libraries were found for "SD.h"

    compilation terminated.

    Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD

    Not used: C:\Program Files (x86)\Arduino\libraries\SD

    Error compiling for board Teensy 4.0.

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

  17. #17
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    1,147
    I think you have things in the wrong directories.
    Copy all the contents
    of C:\Users\iandi\Documents\Arduino\audio-guestbook-main\audio-guestbook\
    to C:\Users\iandi\Documents\Arduino\audio-guestbook-main\
    Then delete the directory C:\Users\iandi\Documents\Arduino\audio-guestbook-main\audio-guestbook\ and all its contents.

  18. #18
    done that still same

  19. #19
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,707
    Quote Originally Posted by carpracing View Post
    arduino ide dont see my board
    ....
    Error compiling for board Teensy 4.0.
    No. "Error compiling" means Arduino IDE could not use the files on your PC.

    It didn't even try to talk to Teensy, because the code on your PC is not correct. This is the way the Arduino software works. It compiles first and only tries to upload if the compile is successful.

    To check if Teensy is working with your PC, in Arduino click File > Examples > 01.Basics > Blink. This will open a new window with the very simple LED blink program. Click Upload. After compiling, the small Teensy Loader window should appear, and you should see it do the code loading. Usually takes about 2 seconds, so it's easy to miss if you're not looking.

    During uploads, the red LED near the USB connector should turn on.

    Try editing the code to change the delays from 1000 to only 100. Before uploading, look at the orange LED and get a visual idea of the blinking speed. Then upload with the reduced delay. When the new program is running, you should see a much faster blinking speed.

    And back to the errors, try just typing a random word somewhere in the code. When you attempt to upload, you'll see an error message. You'll see it doesn't even try to talk to Teensy to attempt upload if there is "Error compiling".

  20. #20
    yep can change orange blinking light to slow to fast and when put name in error

  21. #21
    Quote Originally Posted by PaulStoffregen View Post
    No. "Error compiling" means Arduino IDE could not use the files on your PC.

    It didn't even try to talk to Teensy, because the code on your PC is not correct. This is the way the Arduino software works. It compiles first and only tries to upload if the compile is successful.

    To check if Teensy is working with your PC, in Arduino click File > Examples > 01.Basics > Blink. This will open a new window with the very simple LED blink program. Click Upload. After compiling, the small Teensy Loader window should appear, and you should see it do the code loading. Usually takes about 2 seconds, so it's easy to miss if you're not looking.

    During uploads, the red LED near the USB connector should turn on.

    Try editing the code to change the delays from 1000 to only 100. Before uploading, look at the orange LED and get a visual idea of the blinking speed. Then upload with the reduced delay. When the new program is running, you should see a much faster blinking speed.

    And back to the errors, try just typing a random word somewhere in the code. When you attempt to upload, you'll see an error message. You'll see it doesn't even try to talk to Teensy to attempt upload if there is "Error compiling".
    done changes and it does slow down and speed up but still no sd card reading ?????

  22. #22
    any one local to SE London who can help me plzzzzzzzzzzzzzzzzzzzzzzzzz

  23. #23
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    1,147
    So have you got the audio guestbook to compile ok?

  24. #24
    nope still not compiling

    getting this message

    Arduino: 1.8.19 (Windows 10), TD: 1.57, Board: "Teensy 4.0, Serial, 600 MHz, Faster, US English"

    Multiple libraries were found for "SD.h"

    C:\Users\iandi\Documents\Arduino\audio-guestbook-main\audio-guestbook\audio-guestbook.ino:30:24: fatal error: MTP_Teensy.h: No such file or directory

    Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD

    compilation terminated.

    Not used: C:\Program Files (x86)\Arduino\libraries\SD

    Error compiling for board Teensy 4.0.

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

  25. #25
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    1,147
    done changes and it does slow down and speed up but still no sd card reading ?????
    Then what do you mean by the above statement?
    Are you running some other software to read the SD card?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •