TJBot - Make Your Robot Respond to Emotions

14,518

53

11

About: TJBot is an open source paper robot that I designed to help you learn programming Artificial Intelligence in a fun way! You can laser cut or 3D print him, then use one of his recipes to bring him to life! I ...

This instructable guides you through connecting a Raspberry Pi to IBM 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.

Install Packages

Open a terminal application on the Pi and execute the following commands to install the latest version of Node.js and npm (Node Package Manager). You need these packages later to run your code.

curl -sL http://ibm.biz/tjbot-bootstrap | sudo sh -

Step 3: Assemble TJBot

Here is a quick video of how to fold the kit. The detailed instructions are available on another instructable: Build TJBot out of Cardboard

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.

Here are the instructions for how to clone a repository from github if you have not done that before.

git clone https://github.com/ibmtjbot/tjbot.git
cd tjbot/recipes/sentiment_analysis
npm install

Pro tip: if you get an error for npm install that says npm not found, you should first install npm on your machine.

This is the command line to install npm
sudo apt-get install npm

Step 5: Update Your Twitter and Watson Credentials

In this step, we help you get API access to the Tone Analyzer. Tone analyzer enables you discover, understand, and revise the language tones in text.

Let's start with creating a Tone Analyzer instance on IBM Cloud (If you don't have an account, you can create a free trial). Create an instance of the Watson Tone Analyzer service and note the authentication credentials.

Create a set of Twitter developer credentials and note the consumer key, consumer secret, access token key, and access token secret.

Make a copy the default configuration file and update it with the Watson service credentials.

$ cp config.default.js config.js
$ nano config.js

enter your credentials in the specified places> 

Step 6: Run the Code

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

sudo node sentiment.js

At this point, TJBot will begin listening to Twitter for tweets containing the specified keyword (specified in exports.sentiment_keyword). It may take some time to collect enough tweets to perform sentiment analysis, so please be patient.

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

exports.sentiment_keyword = "education"; // keyword to monitor in Twitter

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

  • Anger (Red)
  • Joy (Yellow)
  • Fear (Magenta)
  • Sadness (Blue)

You can change these colors by editing the shineForEmotion() function.


Also note that the Tone Analyzer API returns three language tones: analytical, confident, and tentative. Try modifying the recipe to do something new depending on which language tone is dominant.
Hint: you may want to eliminate the filter() on tone.document_tone.tones to be able to examine the language tones.


Troubleshoot

Is the LED not lighting up or it shows a wrong color? No worries, we can fix it. Check out the troubleshoot guide for this recipe.

Enjoy! Don't forget to share a picture/video of your setup #TJBot! :-)

We suggest, you check out 'Build a talking robot with Watson' next!

Share

    Recommendations

    • Gardening Contest

      Gardening Contest
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Arduino Contest 2019

      Arduino Contest 2019

    11 Discussions

    0
    None
    SarthakM18

    1 year ago

    After running conversation.js,no error came but the led color won't change....

    I am using a simple RGB led(4 pins)

    0
    None
    perfectlax

    1 year ago

    Hello everybody:

    After running the sudo node sentiment.js command, I'm getting the following error

    Unhandled rejection TypeError: tj.isPulsing is not a function

    at /home/pi/tjbot/recipes/sentiment_analysis/sentiment.js:118:32

    at Array.forEach (native)

    at /home/pi/tjbot/recipes/sentiment_analysis/sentiment.js:108:48

    at tryCatcher (/home/pi/tjbot/recipes/sentiment_analysis/node_modules/bluebird/js/release/util.js:16:23)

    at Promise._settlePromiseFromHandler (/home/pi/tjbot/recipes/sentiment_analysis/node_modules/bluebird/js/release/promise.js:512:31)

    at Promise._settlePromise (/home/pi/tjbot/recipes/sentiment_analysis/node_modules/bluebird/js/release/promise.js:569:18)

    at Promise._settlePromise0 (/home/pi/tjbot/recipes/sentiment_analysis/node_modules/bluebird/js/release/promise.js:614:10)

    at Promise._settlePromises (/home/pi/tjbot/recipes/sentiment_analysis/node_modules/bluebird/js/release/promise.js:693:18)

    at Async._drainQueue (/home/pi/tjbot/recipes/sentiment_analysis/node_modules/bluebird/js/release/async.js:133:16)

    at Async._drainQueues (/home/pi/tjbot/recipes/sentiment_analysis/node_modules/bluebird/js/release/async.js:143:10)

    at Immediate.Async.drainQueues (/home/pi/tjbot/recipes/sentiment_analysis/node_modules/bluebird/js/release/async.js:17:14)

    at runCallback (timers.js:672:20)

    at tryOnImmediate (timers.js:645:5)

    at processImmediate [as _immediateCallback] (timers.js:617:5)

    Any ideas to fix this problem?

    Thank you very much for your help!

    Regards

    2 replies
    0
    None
    IDeliverInsightsperfectlax

    Reply 1 year ago

    Hi,

    I commented out these 3 lines in the code (sentiment.js)

    if (tj.isPulsing()) {

    tj.stopPulsing();

    }

    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.

    Hope this works for you.

    0
    None
    perfectlax

    1 year ago

    Hello:

    I cannot find the blacklist-rgb-led.conf file, where is located?

    Thanks for the help!

    1 reply
    0
    None
    CallistoB

    2 years ago

    Hi im getting this error when I try to run it. However... while trying to troubleshoot, I got the LED to change from blue to purple?? No idea what is happening

    IMG_4644.JPG
    2 replies
    0
    None
    CallistoBCallistoB

    Reply 2 years ago

    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!

    0
    None
    TJBotCallistoB

    Reply 2 years ago

    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! :)

    0
    None
    TJBotMarkK236

    Reply 2 years ago

    Thanks, Mark. It's fixed! :-)