Members | Sign In
Legacy MOVI User Community Forum (readonly) > MOVI Projects
avatar

Using a MOVI with an Arduino Leonardo as a Keyboard (aka Star Trek computer)

posted Jan 05, 2016 22:40:55 by GeraldFriedland
Hi all,

While we posted this example as a video on our Facebook page, this sketch never made it into the official API, mostly because it requires an Arduino Leonardo. So if you are interested, here you go:

/*****************************************************************************
 * This is an UNOFFICIAL example for the use of
 * Audeme's MOVI(tm) Voice Control Shield ----> http://www.audeme.com/MOVI/
 * 
 * Written by Gerald Friedland at Audeme LLC.
 * Contact: fractor@audeme.com
 * BSD license, all text above must be included in any redistribution.
 *****************************************************************************
 *
 * This basic example shows how to use MOVI's API to train the call 
 * sign "Computer" and two sentences. When the sentences are recognized
 * they send keyboard commands over USB on an Arduino Leonardo.
 *
 * Circuitry:
 * Arduino Leonardo
 * USB connection to a laptop
 * LED on PIN13
 * Cable from PIN2 to GND. This is to make sure we can force the Leonardo from keyboard 
 *                         back into programming mode (and not end up with a bricked board)! 
 *                         See: https://www.youtube.com/watch?v=0fjuJOkk8y4
 * 
 */

#ifdef ARDUINO_ARCH_AVR
#include <SoftwareSerial.h> // MOVI needs SoftwareSerial
#endif

#include "MOVIShield.h"     // Include MOVI library

const int security = 2;
const int led=13;
MOVI recognizer(true);     // Get a MOVI object

void setup()  
{
  pinMode(security, INPUT_PULLUP);
  delay(1); 
  pinMode(led, OUTPUT);
  delay(1); 
  digitalWrite(led, LOW);    


  recognizer.init();      // Initialize MOVI (waits for it to boot)

  //*
  // Note: training can only be performed in setup(). 
  // The training functions are "lazy" and only do something if they have to. 
  // They can be commented out to save memory and startup time once training 
  // has been performed once.
  recognizer.callSign("COMPUTER"); // Train callsign Arduino (may take 20 seconds)
  recognizer.addSentence("list files"); // Add sentence 1
  recognizer.addSentence("clear screen"); // Add sentence 2
  recognizer.train();              // Train sentences (may take 20seconds) 
  //*/

  //  recognizer.setThreshold(5); // uncomment and set to a higher value (valid range 2-95) 
                                  // if you have a problems due to a noisy environment.
}

void loop() // run over and over
{
 // *** DO NOT DELETE THE FOLLOWING LINES OF SAFETY CODE!
 // SEE: https://www.youtube.com/watch?v=0fjuJOkk8y4
  while (digitalRead(2) == HIGH) {
    // do nothing until pin 2 goes low
    delay(500);
    digitalWrite(led, LOW); // Blink LED.   
  }
  // *** SAFETY CODE END
  digitalWrite(led, HIGH); // Blink LED.   
  signed int res=recognizer.poll(); // Get result from MOVI, 0 means nothing happened, 
                                    // negative values denote events (see docs)
  if (res==1) {                     // Sentence 1.
    recognizer.say("Listing");
    Keyboard.println("ls -l");
    Keyboard.releaseAll();
  } 
  if (res==2) {                    // Sentence 2 
    recognizer.say("resetting");
    Keyboard.println("reset");
    Keyboard.releaseAll();
  }
}
[Last edited Jan 05, 2016 23:00:21]
Login below to reply: