Turn on an LED with Watson Conversation

Turn on an LED with Watson Conversation

 

 

 

 

1.)  You will need to have node already installed on your Pi. You may find NPM's rpio-gpio site helpful for syntax.

 

2.)  Run the command npm install rpi-gpio in terminal.

 

3.) We started with the conversation.js file from Watson's TJBot example, and added the following lines before we instantiated our bot.


var gpio = require('rpi-gpio'); var pin = 7; gpio.setup(pin, gpio.DIR_OUT);

The first parameter for setup() is the channel.  Make sure to reference the RPi pin number and not the GPIO.  The second parameter is the direction, DIR_OUT writes to pin #7.  You can also change the name of your bot to something different.  We picked "Bob" as it was less likely to be confused with other words.


// instantiate our TJBot! var tj = new TJBot(hardware, tjConfig, credentials); tj.configuration.robot.name ="Bob";

 

4.) After the utterances part of the code add the following code for speech recognition.


var containsOn = msg.indexOf("on") >= 0; var containsOff = msg.indexOf("off") >= 0; var containsLight = msg.indexOf("light") >= 0; //turns on light if (containsLight && containsOn ) { console.log("Turn on Light") gpio.write(pin,true); };
// turns off light
if (containsLight && containsOff ) { 
console.log("Turn off Light")
gpio.write(pin,false);
};

5.) Setup for the pins.

 

  Raspberry Pi hooked up to LED and breadboard.

 

6.) The complete node js code.

Turn on an LED with Watson Conversation on a Raspberry Pi.

Copyright 2015 - Zagros Robotics, All Rights Reserved - Please send webpage comments or corrections to webmaster@zagrosrobotics.com - Zagros Robotics,12148 Lackland Road, St. Louis, MO 63146- 7342, (314)341-1836, info@zagrosrobotics.com for answers to any questions.

Zagros Robotics, Inc
ASP.NET Shopping Cart Software