Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: CODE 2 - Errors

  1. #1
    Junior Member
    Join Date
    Jan 2023
    Location
    New York
    Posts
    8

    CODE 2 - Errors

    Why am I getting these errors when I am trying to compile my sketch?


    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.
       Files are saved on SD card as 44.1kHz, 16-bit, mono signed integer RAW audio format
       --> changed this to WAV recording, DD4WH 2022_07_31
       --> added MTP support, which enables copying WAV files from the SD card via the USB connection, DD4WH 2022_08_01
       Playback button allows all messages currently saved on SD card through earpiece
    
    
    
       Frank DD4WH, August 1st 2022
       for a DBP 611 telephone (closed contact when handheld is lifted) & with recording to WAV file
       contact for switch button 0 is closed when handheld is lifted
    
       GNU GPL v3.0 license
    
    */
    
                    #include <Bounce.h>
    
    
    #include <Audio.h>
    
    
    #include <Wire.h>
    
    
    #include <SPI.h>
    
    
    #include <SD.h>
    
    
    #include <TimeLib.h>
    
    
    #include <MTP_Teensy.h>
    
    
    #include "play_sd_wav.h" // local copy with fixes
    
    
    
    
    
    // DEFINES
    
    
    // Define pins used by Teensy Audio Shield
    
     -38,12 +39,14 
    
    
    #define HOOK_PIN 0
    
    
    #define PLAYBACK_BUTTON_PIN 1
    
    
    
    
    
    #define noINSTRUMENT_SD_WRITE
    
    
    
    
    
    // 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
    
    
    AudioPlaySdWav              playWav1; // Play 44.1kHz 16-bit PCM greeting WAV file
    
    
    AudioPlaySdWavX              playWav1; // Play 44.1kHz 16-bit PCM greeting WAV file
    
    
    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
    
    @@ -69,6 +72,8 @@ Mode mode = Mode::Initialising;
    
    
    
    
    
    float beep_volume = 0.04f; // not too loud :-)
    
    
    
    
    
    uint32_t MTPcheckInterval; // default value of device check interval [ms]
    
    
    
    
    
    // variables for writing to WAV file
    
    
    unsigned long ChunkSize = 0L;
    
    
    unsigned long Subchunk1Size = 16;
    
    @@ -91,6 +96,7 @@ void setup() {
    
    
        // wait for serial port to connect.
    
    
      }
    
    
      Serial.println("Serial set up correctly");
    
    
      Serial.printf("Audio block set to %d samples\n",AUDIO_BLOCK_SAMPLES);
    
    
      print_mode();
    
    
      // Configure the input pins
    
    
      pinMode(HOOK_PIN, INPUT_PULLUP);
    
    
    @@ -129,13 +135,15 @@ void setup() {
    
    
      }
    
    
        else Serial.println("SD card correctly initialized");
    
    
    
    
    
    
    
    
      // mandatory to begin the MTP session.
    
    
        MTP.begin();
    
    
    
    
    
      // Add SD Card
    
    
    //    MTP.addFilesystem(SD, "SD Card");
    
    
        MTP.addFilesystem(SD, "Kais Audio guestbook"); // choose a nice name for the SD card volume to appear in your file explorer
    
    
        Serial.println("Added SD card via MTP");
    
    
        MTPcheckInterval = MTP.storage()->get_DeltaDeviceCheckTimeMS();
    
    
    
    
    
        // Value in dB
    
    
    //  sgtl5000_1.micGain(15);
    
    
    @@ -226,10 +234,36 @@ void loop() {
    
    
        case Mode::Initialising: // to make compiler happy
    
    
          break;  
    
    
      }   
    
    
      MTP.loop();  //This is mandatory to be placed in the loop code.
    
    
    
    
    
      MTP.loop();  // This is mandatory to be placed in the loop code.
    
    
    }
    
    
    
    
    
    void setMTPdeviceChecks(bool nable)
    
    
    {
    
    
      if (nable)
    
    
      {
    
    
        MTP.storage()->set_DeltaDeviceCheckTimeMS(MTPcheckInterval);
    
    
        Serial.print("En");
    
    
      }
    
    
      else
    
    
      {
    
    
        MTP.storage()->set_DeltaDeviceCheckTimeMS((uint32_t) -1);
    
    
        Serial.print("Dis");
    
    
      }
    
    
      Serial.println("abled MTP storage device checks");
    
    
    }
    
    
    
    
    
    
    
    
    #if defined(INSTRUMENT_SD_WRITE)
    
    
    static uint32_t worstSDwrite, printNext;
    
    
    #endif // defined(INSTRUMENT_SD_WRITE)
    
    
    
    
    
    void startRecording() {
    
    
      setMTPdeviceChecks(false); // disable MTP device checks while recording
    
    
    #if defined(INSTRUMENT_SD_WRITE)
    
    
      worstSDwrite = 0;
    
    
      printNext = 0;
    
    
    #endif // defined(INSTRUMENT_SD_WRITE)
    
    
      // Find the first available file number
    
    
    //  for (uint8_t i=0; i<9999; i++) { // BUGFIX uint8_t overflows if it reaches 255  
    
    
      for (uint16_t i=0; i<9999; i++) {   
    
    @@ -255,21 +289,39 @@ void startRecording() {
    
    
    }
    
    
    
    
    
    void continueRecording() {
    
    
    #if defined(INSTRUMENT_SD_WRITE)
    
    
      uint32_t started = micros();
    
    
    #endif // defined(INSTRUMENT_SD_WRITE)
    
    
    #define NBLOX 16  
    
    
      // Check if there is data in the queue
    
    
      if (queue1.available() >= 2) {
    
    
        byte buffer[512];
    
    
      if (queue1.available() >= NBLOX) {
    
    
        byte buffer[NBLOX*AUDIO_BLOCK_SAMPLES*sizeof(int16_t)];
    
    
        // 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();
    
    
        for (int i=0;i<NBLOX;i++)
    
    
        {
    
    
          memcpy(buffer+i*AUDIO_BLOCK_SAMPLES*sizeof(int16_t), queue1.readBuffer(), AUDIO_BLOCK_SAMPLES*sizeof(int16_t));
    
    
          queue1.freeBuffer();
    
    
        }
    
    
        // Write all 512 bytes to the SD card
    
    
        frec.write(buffer, 512);
    
    
        recByteSaved += 512;
    
    
        frec.write(buffer, sizeof buffer);
    
    
        recByteSaved += sizeof buffer;
    
    
      }
    
    
    
    
    
    #if defined(INSTRUMENT_SD_WRITE)
    
    
      started = micros() - started;
    
    
      if (started > worstSDwrite)
    
    
        worstSDwrite = started;
    
    
    
    
    
      if (millis() >= printNext)
    
    
      {
    
    
        Serial.printf("Worst write took %luus\n",worstSDwrite);
    
    
        worstSDwrite = 0;
    
    
        printNext = millis()+250;
    
    
      }
    
    
    #endif // defined(INSTRUMENT_SD_WRITE)
    
    
    }
    
    
    
    
    
    void stopRecording() {
    
    @@ -278,15 +330,16 @@ void stopRecording() {
    
    
      // Flush all existing remaining data from the queue
    
    
      while (queue1.available() > 0) {
    
    
        // Save to open file
    
    
        frec.write((byte*)queue1.readBuffer(), 256);
    
    
        frec.write((byte*)queue1.readBuffer(), AUDIO_BLOCK_SAMPLES*sizeof(int16_t));
    
    
        queue1.freeBuffer();
    
    
        recByteSaved += 256;
    
    
        recByteSaved += AUDIO_BLOCK_SAMPLES*sizeof(int16_t);
    
    
      }
    
    
      writeOutHeader();
    
    
      // Close the file
    
    
      frec.close();
    
    
      Serial.println("Closed file");
    
    
      mode = Mode::Ready; print_mode();
    
    
      setMTPdeviceChecks(true); // enable MTP device checks, recording is finished
    
    
    }
    
    
    
    
    
    
    
    
    @@ -412,8 +465,8 @@ void writeOutHeader() { // update WAV header with final filesize/datasize
    
    
    
    
    
    //  NumSamples = (recByteSaved*8)/bitsPerSample/numChannels;
    
    
    //  Subchunk2Size = NumSamples*numChannels*bitsPerSample/8; // number of samples x number of channels x number of bytes per sample
    
    
      Subchunk2Size = recByteSaved;
    
    
      ChunkSize = Subchunk2Size + 36;
    
    
      Subchunk2Size = recByteSaved - 42; // because we didn't make space for the header to start with! Lose 21 samples...
    
    
      ChunkSize = Subchunk2Size + 34; // was 36;
    
    
      frec.seek(0);
    
    
      frec.write("RIFF");
    
    
      byte1 = ChunkSize & 0xff;
    Last edited by defragster; 01-24-2023 at 06:52 PM. Reason: both CODE tags needed

  2. #2
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    1,051
    Can I suggest that when you post code that you enclose it between CODE tags using the # button above.
    It makes your code so much more readable and therefore easier for others to potentially help you.
    EDIT:
    You seem to have tried to use code tags but have somehow deleted the beginning code tag.
    It can be difficult to position the cursor in the correct space when pasting between code tags.
    An alternative method which works quite well is to first paste your code WITHOUT code tags.
    Now highlight ALL your code and then press the # button.
    The system automatically encloses your code with the correct code tags.

    I am assuming that you are trying to compile the "Standard" Audio Guestbook but your post above does NOT show what errors you are experiencing.
    In fact it looks like your entry was truncated so no-one can attempt to compile/run your code because it is incomplete and no errors are shown.

    When I am making a post I always use "Go Advanced".
    It shows what your entry will look like when posted on the system and allows you to make any changes that are deemed necessary after having seen the actual final format.
    Last edited by BriComp; 01-24-2023 at 06:24 PM.

  3. #3
    Junior Member
    Join Date
    Jan 2023
    Location
    New York
    Posts
    8
    Quote Originally Posted by BriComp View Post
    Can I suggest that when you post code that you enclose it between CODE tags using the # button above.
    It makes your code so much more readable and therefore easier for others to potentially help you.
    EDIT:
    You seem to have tried to use code tags but have somehow deleted the beginning code tag.
    It can be difficult to position the cursor in the correct space when pasting between code tags.
    An alternative method which works quite well is to first paste your code WITHOUT code tags.
    Now highlight ALL your code and then press the # button.
    The system automatically encloses your code with the correct code tags.

    I am assuming that you are trying to compile the "Standard" Audio Guestbook but your post above does NOT show what errors you are experiencing.
    In fact it looks like your entry was truncated so no-one can attempt to compile/run your code because it is incomplete and no errors are shown.

    When I am making a post I always use "Go Advanced".
    It shows what your entry will look like when posted on the system and allows you to make any changes that are deemed necessary after having seen the actual final format.




    Compiling sketch...

    "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/precompile_helper" "C:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr/cores/teensy4" "C:\\Users\\ronni\\AppData\\Local\\Temp\\arduino_b uild_86922" "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -x c++-header -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=157 -DARDUINO=10816 -DARDUINO_TEENSY40 -DF_CPU=600000000 -DUSB_MTPDISK -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr/cores/teensy4" "C:\\Users\\ronni\\AppData\\Local\\Temp\\arduino_b uild_86922/pch/Arduino.h" -o "C:\\Users\\ronni\\AppData\\Local\\Temp\\arduino_b uild_86922/pch/Arduino.h.gch"

    "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=157 -DARDUINO=10816 -DARDUINO_TEENSY40 -DF_CPU=600000000 -DUSB_MTPDISK -DLAYOUT_US_ENGLISH "-IC:\\Users\\ronni\\AppData\\Local\\Temp\\arduino_b uild_86922/pch" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teen sy4" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ Bounce" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ Audio" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ SPI" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ SD\\src" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ SdFat\\src" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ SerialFlash" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ Wire" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ Time" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ MTP_Teensy-main\\src" "C:\\Users\\ronni\\AppData\\Local\\Temp\\arduino_b uild_86922\\sketch\\audio-guestbook_2.ino.cpp" -o "C:\\Users\\ronni\\AppData\\Local\\Temp\\arduino_b uild_86922\\sketch\\audio-guestbook_2.ino.cpp.o"

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:103:1: error: stray '@' in program

    @@ -69,6 +72,8 @@ Mode mode = Mode::Initialising;

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:103:2: error: stray '@' in program

    @@ -69,6 +72,8 @@ Mode mode = Mode::Initialising;

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:103:16: error: stray '@' in program

    @@ -69,6 +72,8 @@ Mode mode = Mode::Initialising;

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:103:17: error: stray '@' in program

    @@ -69,6 +72,8 @@ Mode mode = Mode::Initialising;

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:129:1: error: stray '@' in program

    @@ -91,6 +96,7 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:129:2: error: stray '@' in program

    @@ -91,6 +96,7 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:129:16: error: stray '@' in program

    @@ -91,6 +96,7 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:129:17: error: stray '@' in program

    @@ -91,6 +96,7 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:153:1: error: stray '@' in program

    @@ -129,13 +135,15 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:153:2: error: stray '@' in program

    @@ -129,13 +135,15 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:153:20: error: stray '@' in program

    @@ -129,13 +135,15 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:153:21: error: stray '@' in program

    @@ -129,13 +135,15 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:201:1: error: stray '@' in program

    @@ -226,10 +234,36 @@ void loop() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:201:2: error: stray '@' in program

    @@ -226,10 +234,36 @@ void loop() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:201:20: error: stray '@' in program

    @@ -226,10 +234,36 @@ void loop() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:201:21: error: stray '@' in program

    @@ -226,10 +234,36 @@ void loop() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:314:1: error: stray '@' in program

    @@ -255,21 +289,39 @@ void startRecording() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:314:2: error: stray '@' in program

    @@ -255,21 +289,39 @@ void startRecording() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:314:20: error: stray '@' in program

    @@ -255,21 +289,39 @@ void startRecording() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:314:21: error: stray '@' in program

    @@ -255,21 +289,39 @@ void startRecording() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:457:1: error: stray '@' in program

    @@ -278,15 +330,16 @@ void stopRecording() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:457:2: error: stray '@' in program

    @@ -278,15 +330,16 @@ void stopRecording() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:457:20: error: stray '@' in program

    @@ -278,15 +330,16 @@ void stopRecording() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:457:21: error: stray '@' in program

    @@ -278,15 +330,16 @@ void stopRecording() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:514:1: error: stray '@' in program

    @@ -412,8 +465,8 @@ void writeOutHeader() { // update WAV header with final filesize/datasize

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:514:2: error: stray '@' in program

    @@ -412,8 +465,8 @@ void writeOutHeader() { // update WAV header with final filesize/datasize

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:514:18: error: stray '@' in program

    @@ -412,8 +465,8 @@ void writeOutHeader() { // update WAV header with final filesize/datasize

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:514:19: error: stray '@' in program

    @@ -412,8 +465,8 @@ void writeOutHeader() { // update WAV header with final filesize/datasize

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:56:2: error: expected unqualified-id before '-' token

    -38,12 +39,14

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:92:1: error: 'AudioPlaySdWavX' does not name a type

    AudioPlaySdWavX playWav1; // Play 44.1kHz 16-bit PCM greeting WAV file

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:103:4: error: expected unqualified-id before '-' token

    @@ -69,6 +72,8 @@ Mode mode = Mode::Initialising;

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:129:4: error: expected unqualified-id before '-' token

    @@ -91,6 +96,7 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:138:3: error: 'Serial' does not name a type

    Serial.println("Serial set up correctly");

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:141:3: error: 'Serial' does not name a type

    Serial.printf("Audio block set to %d samples\n",AUDIO_BLOCK_SAMPLES);

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:144:15: error: expected constructor, destructor, or type conversion before ';' token

    print_mode();

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:150:10: error: expected constructor, destructor, or type conversion before '(' token

    pinMode(HOOK_PIN, INPUT_PULLUP);

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:153:4: error: expected unqualified-id before '-' token

    @@ -129,13 +135,15 @@ void setup() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:159:5: error: expected unqualified-id before 'else'

    else Serial.println("SD card correctly initialized");

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:171:5: error: 'MTP' does not name a type

    MTP.begin();

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:183:5: error: 'MTP' does not name a type

    MTP.addFilesystem(SD, "Kais Audio guestbook"); // choose a nice name for the SD card volume to appear in your file explorer

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:186:5: error: 'Serial' does not name a type

    Serial.println("Added SD card via MTP");

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:189:5: error: 'MTPcheckInterval' does not name a type

    MTPcheckInterval = MTP.storage()->get_DeltaDeviceCheckTimeMS();

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:201:4: error: expected unqualified-id before '-' token

    @@ -226,10 +234,36 @@ void loop() {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:213:3: error: 'MTP' does not name a type

    MTP.loop(); //This is mandatory to be placed in the loop code.

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:219:3: error: 'MTP' does not name a type

    MTP.loop(); // This is mandatory to be placed in the loop code.

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:222:1: error: expected declaration before '}' token

    }

    ^

    Multiple libraries were found for "MTP_Teensy.h"

    Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\MTP_Te ensy-main

    Not used: C:\Program Files (x86)\Arduino\libraries\MTP_Teensy-main

    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

    Using library Bounce in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Bounce (legacy)

    Using library Audio at version 1.3 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio

    Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI

    Using library SD at version 2.0.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD

    Using library SdFat at version 2.1.2 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat

    Using library SerialFlash at version 0.5 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Serial Flash

    Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire

    Using library Time at version 1.6.1 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time

    Using library MTP_Teensy-main at version 1.0.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\MTP_Te ensy-main

    Error compiling for board Teensy 4.0.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,408
    Looks like something went wrong when you copied this code into Arduino.

    Here is a portion of the code shown in msg #1:

    Code:
    // variables for writing to WAV file
    
    
    unsigned long ChunkSize = 0L;
    
    
    unsigned long Subchunk1Size = 16;
    
    @@ -91,6 +96,7 @@ void setup() {
    
    
        // wait for serial port to connect.
    
    
      }
    
    
      Serial.println("Serial set up correctly");
    This part highlighted in red is NOT supposed to be part of the code. Somehow it got mistakenly added. How, I can only guess, since I can't see your computer screen (and even if I could see, to know what went wrong I would also need a time machine and stand watching over your shoulder to see what actually happened). But my best guess is perhaps you selected all the code on a site like Github which sometimes shows extra stuff on the screen, and that extra stuff got copied together with the code.

    And knowing this now, hopefully you can understand why the compiler was giving the error message "error: stray '@' in program".

    To solve this problem, just open a new window in Arduino (click File > New Sketch), delete the template code Arduino puts into every new window, and go find the Audio Guestbook code again. This time, be careful that you copy only the code without any extra stuff. If using Github, loop for this "Raw" button which gives you a page with only the code and no other stuff.

    Click image for larger version. 

Name:	rawbutton.png 
Views:	0 
Size:	5.9 KB 
ID:	30230

    Viewing the code on that raw page should eliminate the possible error of accidentally copying non-code stuff. Also if using Github, pay careful attention to what sort of page you're viewing. Some pages are meant to show you the whole file. Other pages are meant to show what changed between 2 different files. If you try to copy the code from that sort of "diff" page, you're almost certain to get something that doesn't work. Make sure you're on a page which has the purpose of showing you the entire file.

    You could also perhaps download the code to your hard drive. If using Github, look for a green "Code" button. The simplest way is "Download ZIP". When you extract the ZIP file, you should get a complete copy of the code, without the possibility of this sort of mistake where the wrong stuff gets copied.

  5. #5
    Junior Member
    Join Date
    Jan 2023
    Location
    New York
    Posts
    8

    Newest Error

    Ok Paul, Thank You.. That Worked. Here is the newest error


    "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=157 -DARDUINO=10816 -DARDUINO_TEENSY40 -DF_CPU=600000000 -DUSB_MTPDISK -DLAYOUT_US_ENGLISH "-IC:\\Users\\ronni\\AppData\\Local\\Temp\\arduino_b uild_86922/pch" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teen sy4" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ Bounce" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ Audio" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ SPI" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ SD\\src" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ SdFat\\src" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ SerialFlash" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ Wire" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ Time" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\ MTP_Teensy-main\\src" "C:\\Users\\ronni\\AppData\\Local\\Temp\\arduino_b uild_86922\\sketch\\audio-guestbook_2.ino.cpp" -o "C:\\Users\\ronni\\AppData\\Local\\Temp\\arduino_b uild_86922\\sketch\\audio-guestbook_2.ino.cpp.o"

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:56:2: error: expected unqualified-id before '-' token

    -38,12 +39,14

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:92:1: error: 'AudioPlaySdWavX' does not name a type

    AudioPlaySdWavX playWav1; // Play 44.1kHz 16-bit PCM greeting WAV file

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:127:2: error: expected unqualified-id before '{' token

    {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:136:3: error: 'Serial' does not name a type

    Serial.println("Serial set up correctly");

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:139:3: error: 'Serial' does not name a type

    Serial.printf("Audio block set to %d samples\n",AUDIO_BLOCK_SAMPLES);

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:142:15: error: expected constructor, destructor, or type conversion before ';' token

    print_mode();

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:148:10: error: expected constructor, destructor, or type conversion before '(' token

    pinMode(HOOK_PIN, INPUT_PULLUP);

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:157:5: error: expected unqualified-id before 'else'

    else Serial.println("SD card correctly initialized");

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:169:5: error: 'MTP' does not name a type

    MTP.begin();

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:181:5: error: 'MTP' does not name a type

    MTP.addFilesystem(SD, "Kais Audio guestbook"); // choose a nice name for the SD card volume to appear in your file explorer

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:184:5: error: 'Serial' does not name a type

    Serial.println("Added SD card via MTP");

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:187:5: error: 'MTPcheckInterval' does not name a type

    MTPcheckInterval = MTP.storage()->get_DeltaDeviceCheckTimeMS();

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:199:2: error: expected unqualified-id before '{' token

    {

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:211:3: error: 'MTP' does not name a type

    MTP.loop(); //This is mandatory to be placed in the loop code.

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:217:3: error: 'MTP' does not name a type

    MTP.loop(); // This is mandatory to be placed in the loop code.

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:220:1: error: expected declaration before '}' token

    }

    ^

    Multiple libraries were found for "MTP_Teensy.h"

    Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\MTP_Te ensy-main

    Not used: C:\Program Files (x86)\Arduino\libraries\MTP_Teensy-main

    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

    Using library Bounce in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Bounce (legacy)

    Using library Audio at version 1.3 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio

    Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI

    Using library SD at version 2.0.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD

    Using library SdFat at version 2.1.2 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat

    Using library SerialFlash at version 0.5 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Serial Flash

    Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire

    Using library Time at version 1.6.1 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time

    Using library MTP_Teensy-main at version 1.0.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\MTP_Te ensy-main

    Error compiling for board Teensy 4.0.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,408
    I'm pretty sure "error: 'AudioPlaySdWavX' does not name a type" means this project has other files you also need to copy.

    Like the main code, and all software source code, attention to detail is important. This is a good time to review the project's readme file, video tutorial, and any other documentation to make sure you're not missing any steps or forgetting something else important.

  7. #7
    Additonaly, that first error in the latest attempt looks like a continuation of the original error:

    Code:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\audio-guestbook_2\audio-guestbook_2.ino:56:2: error: expected unqualified-id before '-' token
    
    -38,12 +39,14
    Looks like the same issue with just the "@" characters gone. You might want to try getting rid of this project and pulling a full, fresh copy of the project from where you originally got it (git?).

Posting Permissions

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