Error (Need help solving):

Good afternoon Arduino community.

I need help fixing an issue involving the Arduino IDE Software and my Arduino UNO R4 WiFi. For context, I am doing a science experiment that involves connecting a Grove Speech Recognizer to an Arduino by using wires (I chose the R4 WiFi model) and then connecting the Arduino to an IoT Relay. The full instructions to the science experiment can be found here: Build a Voice-Controlled Lamp | Science Project.

However, when trying to paste the example code from the Grove - Speech Recognizer Wiki Page to the Arduino IDE Software, I get the following error message:

C:\Users\allys\AppData\Local\Temp\.arduinoIDE-unsaved2025028-18780-1jcftyu.biix\sketch_jan28a\sketch_jan28a.ino: In function 'void setup()':
C:\Users\allys\AppData\Local\Temp\.arduinoIDE-unsaved2025028-18780-1jcftyu.biix\sketch_jan28a\sketch_jan28a.ino:7:1: error: 'SoftwareSerial' was not declared in this scope
 SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN);
 ^~~~~~~~~~~~~~
C:\Users\allys\AppData\Local\Temp\.arduinoIDE-unsaved2025028-18780-1jcftyu.biix\sketch_jan28a\sketch_jan28a.ino:36:1: error: a function-definition is not allowed here before '{' token
 {
 ^
C:\Users\allys\AppData\Local\Temp\.arduinoIDE-unsaved2025028-18780-1jcftyu.biix\sketch_jan28a\sketch_jan28a.ino:43:1: error: a function-definition is not allowed here before '{' token
 {
 ^

exit status 1

Compilation error: 'SoftwareSerial' was not declared in this scope`

Upon selecting the "Start Debugging" button, the following prompt appears:

Unable to find executable file at C:/Users\allys\AppData\Local\arduino\sketches\CC31196B6E5891E504ABAC72EB47DAB4\sketch_jan28a.ino.elf.

Because I am not a very technology savvy individual, I can't seem to make sense of what these error messages are trying to convey to me. I tried resetting the Arduino and going into the file mentioned in the Debugging error message, but no results yielded from these actions. If possible, could someone on this forum with more experience than I do with Arduinos assist me in solving this error? Thank you!

Welcome to the forum

Please post the full sketch that you are trying to compile, using code tags when you do

I suspect that the code was written for the original Uno not the Uno R4 and used SoftwareSerial because the original Uno only has a single hardware Serial interface

However, the R4 has 2 hardware Serial interfaces so SoftwareSerial is not supported

Once you post the code we can provide further help and suggestions

Here is the code that I inputted into the Arduino IDE:

#include <SoftwareSerial.h>

#define SOFTSERIAL_RX_PIN  2
#define SOFTSERIAL_TX_PIN  3

SoftwareSerial softSerial(SOFTSERIAL_RX_PIN,SOFTSERIAL_TX_PIN);

const char *voiceBuffer[] =
{
    "Turn on the light",
    "Turn off the light",
    "Play music",
    "Pause",
    "Next",
    "Previous",
    "Up",
    "Down",
    "Turn on the TV",
    "Turn off the TV",
    "Increase temperature",
    "Decrease temperature",
    "What's the time",
    "Open the door",
    "Close the door",
    "Left",
    "Right",
    "Stop",
    "Start",
    "Mode 1",
    "Mode 2",
    "Go",
};

void setup()
{
    Serial.begin(9600);
    softSerial.begin(9600);
    softSerial.listen();
}

void loop()
{
    char cmd;

    if(softSerial.available())
    {
        cmd = softSerial.read();
        Serial.println(voiceBuffer[cmd - 1]);
    }
} 

The output from the code resulted in the first error message in my original post. Hope this clarifies things.

Connect the Speech Recognizer to pins 0 and 1 of the R4 (Tx of the module to pin 0 of the R4 and Rx of the module to pin 1 of the R4 and try this sketch. I cannot test it but it compiles

//#include <SoftwareSerial.h>

//#define SOFTSERIAL_RX_PIN  2
//#define SOFTSERIAL_TX_PIN  3

//SoftwareSerial softSerial(SOFTSERIAL_RX_PIN, SOFTSERIAL_TX_PIN);

const char *voiceBuffer[] =
{
  "Turn on the light",
  "Turn off the light",
  "Play music",
  "Pause",
  "Next",
  "Previous",
  "Up",
  "Down",
  "Turn on the TV",
  "Turn off the TV",
  "Increase temperature",
  "Decrease temperature",
  "What's the time",
  "Open the door",
  "Close the door",
  "Left",
  "Right",
  "Stop",
  "Start",
  "Mode 1",
  "Mode 2",
  "Go",
};

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
//  softSerial.begin(9600);
//  softSerial.listen();
}

void loop()
{
  char cmd;

  if (Serial1.available())
  {
    cmd = Serial1.read();
    Serial.println(voiceBuffer[cmd - 1]);
  }
}

Note that Serial1 is the second Serial interface of teh R4 on pins 0 and 1

Sorry for the late reply (I was out of the house doing something with my parents). When you say "Connect the Speech Recognizer to pins 0 and 1 of the Arduino," could you elaborate on this a bit more? Do you mean altering some of the already connected pins shown in step 2 of the experiment to connect to pins 0 and 1 (and if so, what pins) or do you mean something else?

Do you mean altering some of the already connected pins shown in step 2 of the experiment to connect to pins 0 and 1

The instructions of step2 look like this:

Plug the included cable into the 4-pin header on the Grove Speech Recognizer board.
Use jumper wires to connect the wires in the cable to your Arduino (Figure 3):
Black wire to Arduino GND
Red wire to Arduino 5V
Yellow wire to Arduino pin2
White wire to Arduino pin3

The code you are using has this

#define SOFTSERIAL_RX_PIN  2
#define SOFTSERIAL_TX_PIN  3

RX and TX are from the point of view of the Arduino.

On the R4 , as previously stated, D1 is TX and D0 is RX.

So the yellow wire will go to D0 and the white wire to D1

If it doesn't communicate, reverse the connections :wink:

So, I tried connecting the yellow and white wires to the same places you said (and reversing the connections) @cattledog, but I still got the same error message as before. What could be going wrong?

Are you running the code using Serial1 instead of software serial which was posted by @UKHeliBob in post #4?

Ok. I tested the modifications to the Arduino along with the new set of code by UKHeliBob in post 4, and I got the following error message:

C:\Users\allys\AppData\Local\Temp\.arduinoIDE-unsaved2025028-18780-1jcftyu.biix\sketch_jan28a\sketch_jan28a.ino: In function 'void setup()':
C:\Users\allys\AppData\Local\Temp\.arduinoIDE-unsaved2025028-18780-1jcftyu.biix\sketch_jan28a\sketch_jan28a.ino:36:1: error: a function-definition is not allowed here before '{' token
 {
 ^
C:\Users\allys\AppData\Local\Temp\.arduinoIDE-unsaved2025028-18780-1jcftyu.biix\sketch_jan28a\sketch_jan28a.ino:44:1: error: a function-definition is not allowed here before '{' token
 {
 ^
C:\Users\allys\AppData\Local\Temp\.arduinoIDE-unsaved2025028-18780-1jcftyu.biix\sketch_jan28a\sketch_jan28a.ino:54:13: error: a function-definition is not allowed here before '{' token
 void loop() {
             ^
C:\Users\allys\AppData\Local\Temp\.arduinoIDE-unsaved2025028-18780-1jcftyu.biix\sketch_jan28a\sketch_jan28a.ino:57:1: error: expected '}' at end of input
 }
 ^

exit status 1

Compilation error: a function-definition is not allowed here before '{' token.

What could this mean, now? I apologize, this is my first time using one of these devices for an experiment.

My guess is that you made a cut and paste error and missed a bracket.

Use Ctrl +T or Auto Format in the ide to help you find it. Something won't line up.

If you can't find your error, please post the code which cause it.

So, I went through the pasting of the code one more time and made sure to copy every character, to no avail. Here was my inputted code into the IDE:

//#include <SoftwareSerial.h>

//#define SOFTSERIAL_RX_PIN  2
//#define SOFTSERIAL_TX_PIN  3

//SoftwareSerial softSerial(SOFTSERIAL_RX_PIN, SOFTSERIAL_TX_PIN);

const char *voiceBuffer[] =
{
  "Turn on the light",
  "Turn off the light",
  "Play music",
  "Pause",
  "Next",
  "Previous",
  "Up",
  "Down",
  "Turn on the TV",
  "Turn off the TV",
  "Increase temperature",
  "Decrease temperature",
  "What's the time",
  "Open the door",
  "Close the door",
  "Left",
  "Right",
  "Stop",
  "Start",
  "Mode 1",
  "Mode 2",
  "Go",
};

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
//  softSerial.begin(9600);
//  softSerial.listen();
}

void loop()
{
  char cmd;

  if (Serial1.available())
  {
    cmd = Serial1.read();
    Serial.println(voiceBuffer[cmd - 1]);
  }
}

This code compiles successfully for me.

I think there is some sort of cached code which is being compiled, and I do not understand what is going on.

Try compile and upload a blank sketch or blink, and then try the Serial1 code again.

When I select "Start Debugging," this error message pops up. What could this mean and how do I solve it?

File not found "executable": "C:/Users\allys\AppData\Local\arduino\sketches\CC31196B6E5891E504ABAC72EB47DAB4\sketch_jan28a.ino.elf"

I do not use the 2.x ide, and have know knowledge of the debug process with the UNO R4 wifi. I do not have this board.

Given the compile errors you are seeing, I don't think that debug (which isolates running code) will help you find the problem.

Can you load the blink example code to your board?

My guess is that your installation of the IDE is corrupted somehow and you should delete the IDE and try again.

Would the Seeed Studio Wiki Page example code that I posted back in post 3 be my blink code?

No.

In the IDE go to the File pull down and navigate to Examples>Basic>Blink.

Ok. I tried pasting the Blink example code into the "Run permanently" section of the IDE, and the operation still failed. It's getting late here, so I'll try uninstalling and reinstalling the IDE tomorrow after returning from school. I'll @ you if I encounter anymore obstacles or issues. Thank you and @UKHeliBob for your gracious help!

I have no idea what that is. Navigating to the Blink example in the ide and clicking on it should open an ide window with the code in it which can then be uploaded.

I recommend that you install a portable version of the Arduino-IDE version 1.8.19.
IDE Version 1.8.19 has much less bells and whistles to go wrong with and it is easier to use.

The tutorial that you have chosen as your very first project has a rather short documentation and calls itself

You seem to not have this previous experience with Arduino.
That is he reason why youencounter such problems.

These problems are solvable.
But it requires very very very detailed description of all the steps what you do.

As you have no former experience how to use the Arduino-IDE you have to provide always complete sketch and the most verbose output of the Arduino-IDE.

Both posted as a code-section.

And in your case including screenshots how you adjusted the arduino-ide

And I recommend that you don't complicate things by doing that

Follow these steps using the IDE that you already have installed

  1. Close all instances of the IDE
  2. Open a single instance of the IDE
  3. Select all of the text in the edit window and delete it
  4. Select all of the text in my suggested code using the button top/right of the code in the forum
  5. Paste the selected code into the empty IDE edit window
  6. Open the File/Preferences menu in the IDE and turn on "Show verbose output during compilation and upload and close the dialogue
  7. Click the Upload icon in the IDE
  8. DO NOT DO ANYTHING WITH THE DEBUGGING MENU because you do not have any debugging hardware attached to your project
  9. When the upload is finished, either because it succeeds or fails, select all of the output in the bottom window of the IDE and paste it here in code tags to make it easier to read and copy
1 Like