I’m working with the Grove Speech Recognizer and the FRDM K64F with the Grove Base Shield v2 for connection. The datasheet says that the speech recognizer returns a value between 1 and 22 and examples use the Arduino SoftwareSerial library.
Thank you for you quick response. I’m trying to use AnalogIn now but I’m confused about how to convert the analog value to its corresponding digital value?
The sensor seems to be connected to digital pins but it communicates over UART (default baudrate: 9600) probably. Because in the example according to Grove - Speech Recognizer - Seeed Wiki (seeedstudio.com) (scroll down to an example code for Arduino) is used a SoftwareSerial library.
So you can not use AnalogIn or DigitalIn.
Just try to connect the sensor to an UART of your board and check the output via some Mbed API - UnbufferedSerial or BufferedSerial
I do not have this hardware so I can not test it but you will see.
For code click here
#include "mbed.h"
// HERE PLACE YOUR UART PINS!!!!!!!
#define SERIAL_RX_PIN D2
#define SERIAL_TX_PIN D3
BufferedSerial serial(SERIAL_RX_PIN,SERIAL_TX_PIN);
DigitalOut led(LED1);
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",
};
int main(){
printf("Example\n");
char buf;
while(true) {
if (uint32_t num = serial.read(&buf, sizeof(buf))) {
// Toggle the LED.
led = !led;
printf("Result - %s\n", voiceBuffer[buf - 1]);
}
}
}