Voice Recognition module v3.1 (elechouse) with external tact button

Hi, I’m trying to connect tact buttons with Voice Recognition module(VR module).
product
document

It recognizes voice command by comparing recorded data to streaming sound. So it needs to be trained at first, to memorize the keyword.
The training process is quite simple. When it receives message like “sigtrain 0 0”, then it starts to remember sound coming in to the microphone.

What I wanna do is, connect a simple tact button to the arduino and switch in to the “training mode” by pushing the button, which is the same function as I enter “sigtrain …” in the serial monitor, as same as I mentioned above.

I thought it could be able by using ‘Serial.write()’, but it didn’t worked. And I couldn’t find the way out of this problem.

Is there someone who tried things like this? Or someone who knows how to approach this issue?

vr_sample_train.ino (27.2 KB)

I thought it could be able by using 'Serial.write()', but it didn't worked.

What are you trying to write() to? That is, what is connected to the Serial port?

Im trying to send message to VR module, which is connected with the arduino via softwareSerial. I thought it might work, because typing in commands like "sigtrain...." through the serial monitor is the way explained at the documentation.

I'm trying to attach a tact button and push it instead of typing commands in to the serial monitor.

If you're using software serial then trying to use Serial.print to send commands to the VR module probably won't get you very far.

I'm trying to attach a tact button and push it instead of typing commands in to the serial monitor.

if(digitalRead(tactPin) == LOW) // Or high, if high means pressed the way you have the switch wired
{
   memcpy(cmd, "sigtrain...", lengthOfCommand);
}

Put the appropriate command as the second argument, and the length of the command as the third. All the data from the serial port (sent from the PC) ends up in cmd, so pressing the switch can emulate typing data in the serial monitor by simply hard-coding the data in cmd.

Be sure to set the length variable, too.

Thanks for the answer!

I just tried like you said,

if(switch == HIGH){
memcpy(cmd, "sigtrain 0 1", 12);
}

I wrote it in the main loop function, but nothing happen.
I, of course, have checked the switch wiring, and everything else is as same as the example file attached.

If you don't mind, can I ask what exactly the lengthOfCommand means?

if(switch == HIGH){
memcpy(cmd, "sigtrain 0 1", 12);
}

What value did you assign to switch? You are not reading the state of a pin with a switch attached to it.

You need to make len a global variable, and have receiveCmd() not return a value. In that snippet, you need to set len to 12, too.

I attached the switch variable to the right pin, and checked it with simple led if it works. I defined it as a global variable, so it works well.

What do you mean to make len a global variable? Almost every functions in this library has their own len, so which len do you mean to make global?

And what for have not return a value for receiveCmd()? Do you mean I have to make it to a void function?