TJBot - Make Your Robot Respond to Emotions Using Watson

This instructable guides you through connecting a Raspberry Pi to Watson Tone Analyzer and Twitter API. You can control the color of a NeoPixel RGB LED based on public perception of a given keyword (e.g. "education"). The sample code connects to Twitter to analyze the public sentiment about the given keyword in real time, and updates the color of the LED to reflect the sentiment.

Step 1: Parts

Step 2: Prepare Your Pi

If you have used Raspberry Pi before, install Node.js and go to the next step. Otherwise, follow the instructions below to set up your Pi:

Getting Started with Your Pi

Raspberry Pi is similar to a full computer, which means you need a monitor, mouse, and keyboard for it. If you have a TV around, you can connect your Pi to your TV via a HDMI cable. In most of the Pi kits, the SD card is already preloaded with an image of the Raspberry Pi Operating System. You need to put the SD card in the Pi, turn the Pi ON and follow the instructions on screen to complete the installation of the operating system. If you have problems setting up your Pi, you can troubleshoot here.

Step 3: Assemble TJBot

Once your TJBot is ready, get ready to connect your LED to the Pi Pins.

Attention

It's very important to make sure you connect the LED to the right pins, otherwise you may damage your LED or the Pi. ALWAYS start with the GND pin. GND is the longest leg of your LED. The LED has a flat side. The GND is the second leg from the flat side. Again if you are unsure, DO NOT connect the LED to the Pi.

Connect the GND to GND pin on the pi (see the picture). Then connect 'Data in', the 4th leg from the flat side, to the Pi's GPIO pin. Lastly, connect the third leg from the flat side to the 3.3V on the Pi.

Step 4: Download the Sample Code

The sample code is available at github. Download or clone the sample code and execute the following commands from a terminal to install its dependencies.

Almost set! You just need to copy your credentials and add it to the config.js in your application folder.

In order to do this, start with clicking on 'Sevice Credentials' on the left menu and copying your credentials into clipboard.

Now go to the sentiment_analysis folder and make a copy of the default config file.

cp config.default.js config.js

Open config.js file using your favorite text editor and update it with your username and password.

You are done with the Watson credentials, but since your code connects to Twitter, you need to do the same thing with your Twitter credentials. You will need valid Twitter developer credentials in the form of a set of consumer and access tokens/keys. You can get these at https://apps.twitter.com/. Sign in with your Twitter account and begin the process of creating a new app. At the end of the process you should have your keys and access tokens. Now its time to update config.js with your twitter token/keys.

Step 6: Run the Code

Once done with testing the LED, you can run the main module:

sudo node sentiment.js

The default sentiment keyword is set to 'education' but you can change it in config.js.

The default behaviour of the module assigns the following colors to sentiments:

You may test your LED setup to make sure the connections are correct and the library is properly installed. When you run the test module, it should turn your LED on.

cd tjbot/bootstrap/tests
npm install
sudo node test.led.js

If the LED does not light up, you can try moving the power from 3.3 to 5 volts. If neither the 3.3v or 5v pins work, you will need a 1N4001 diode. The diode is inserted between the power pin of the LED (the shorter of the two middle pins) and the 5v pin on the Raspberry Pi. If you have problems with the setup, please refer to Adafruit's Neopixel on Raspbeery Pi guide to troubleshoot.

The LED library uses the PWM module (GPIO 18) to drive the data line of the LEDs. This conflicts with the built-in audio hardware, which uses the same pin to drive the audio output. Depending on your configuration of Raspbian, the sound drivers may be more aggressive in taking away control of GPIO 18 from other processes. If your LED shows random colors instead of the expected color, use this trick to fix it.

And then the code worked. I'm guessing the function called isPulsing does not exist in the code. This was a check to stop the pulsing. My wasn't, so it didn't seem to be a critical check. A reasonable thing to check, but I don't think it's worth the effort to fix, since I didn't write the code myself.

Ok was going back and retracing my steps. At 2:05 in the video, my lines look different. When I type ls there is additionally a folder for tjbot. When I copied what the director of the video did, it gave me a "no such file or directory". So i just typed "tjbot/recipes..." and it found it. But then I typed npm install and it said command not found. I'm really new to this and I feel like i kind of miss the nuances of these instructions somewhat. Any help would be appreciated!

No worries, I can help you with that. You already found the answer to your first question. So great job on finding the right folder. The next step is to go to tjbot/recipes/sentiment_analysis and type "npm install". If it says command not found, it means you haven't install node. Did you follow the instructions on step 2 to set up your Pi? https://www.instructables.com/id/Make-Your-Robot-Respond-to-Emotions-Using-Watson/step2/Set-up-your-Pi/ Follow the instructions on the part labeled as "install packages". This would solve your problem! :)