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!
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
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
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?
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.
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
And I recommend that you don't complicate things by doing that
Follow these steps using the IDE that you already have installed
Close all instances of the IDE
Open a single instance of the IDE
Select all of the text in the edit window and delete it
Select all of the text in my suggested code using the button top/right of the code in the forum
Paste the selected code into the empty IDE edit window
Open the File/Preferences menu in the IDE and turn on "Show verbose output during compilation and upload and close the dialogue
Click the Upload icon in the IDE
DO NOT DO ANYTHING WITH THE DEBUGGING MENU because you do not have any debugging hardware attached to your project
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