Introduction: Twitch - Your Robotic Pet

Picture of Twitch - Your Robotic Pet

This instructable will show you how I built "Twitch". Twitch is a virtual pet that is able to express itself through it's eye, movements, and the sounds it makes, which happens to be sound clips from some of its favorite movies. It can be happy, sad, angry, or neutral depending on how much you interact with it.

Twitch evolved from a project I saw on the Adafruit site called Adafriend the Virtual Pet Cube by John Wall. The original project consisted of an Adafruit Pro Trinket, a LED Matrix and backpack with a 3d printed cube body among other things. I already had an Arduino Uno, and wasn't interested in getting it 3d printed so the project evolved from there.

I used much of the code from the original project, as I liked the animated eye and the different emotions it was able to portray. From there I added a pan/tilt base, capacitive touch sensor and an Adafruit Wave shield to give my pet the voice I was looking for.

In order to successfully complete this project, you should have decent soldering skills. It would be helpful if you have completed at least one Arduino project before, so that you have gotten through setting up the Arduino software and are able to upload sketches to it successfully. You should also have some experience with debugging code, as mine is far from perfect.

Step 1: Required Parts

Step 2: Preparation - the Arduino Wave Shield, LED Matrix and Pan Tilt

Picture of Preparation - the Arduino Wave Shield, LED Matrix and Pan Tilt

Follow the instructions to build the Wave shield. Copy at lease one file to your SD card and make sure you can successfully run the dap_hc sketch (see next step for information on properly formatting the file). Use the serial output to assist in debugging. The output will indicate available RAM, as well as directory and file names it finds and then play them. Although I feel that my soldering skills are pretty decent, I had trouble with this one and had to go over each solder joint a second time until I got it to work. Solder the speaker to the speaker pins near the headphone jack on the shield.

Then solder the LED matrix to the backpack. Note that it is important that you solder it the correct way. I put it upside down the first time. The Backpack library comes with an example sketch. Make sure you can run that sketch successfully before proceeding.

Build the pan tilt kit assembly. You will find that the LED matrix backpack fits into the pan tilt base reasonably well.

Step 3: Preparing the SD Card

The project uses wave files played with the wave shield to help convey its 4 emotional states, sad, happy, angry, and neutral as well as sounds for when the touch sensor is activated. I used about 10 different sound clips from different movies to represent each state, but you can choose songs, animal noises or whatever you want. I got mine from a site called www.moviewavs.com, which I have been using since the late 1990's. Although it is not updated as frequently as it once was, I would highly recommend it.

Although the Wave shield supports 8.3 file names for your files, I names all the files with 2 numbers to save memory. I am sure there is a more efficient way to do this, only I couldn't work it out.

Make sure the sample rate is mono, 22KHz (or less) and 16-bit (or less) or they will not play. I used the open source software Audacity to convert them to the correct format, although there are several other ways to do it as specified in this guide.

I collected several files I wanted to use, organized them into the appropriate emotional states and renamed them as references in the code.

Touch sounds are named

1.WAV - 8.WAV

Neutral sounds

10.WAV - 19.WAV

Angry sounds

30.WAV - 39.WAV

Sad sounds

50.WAV - 59.WAV

Happy sounds

70.WAV - 79.WAV

Copy these sounds to the root directory of your SD card, then insert it into the Wave shield.

Step 4: Wiring It Together

Picture of Wiring It Together

Follow the image to help you wire it all up. The Fritzing library (Software used to create the drawing) does not include an image for the wave shield, but just use the same pins. The wave shield uses pins 10,11,12, and 13 to communicate with the SD card, and 2,3,4 and 5 for the DAC (digital audio converter), so we cannot use those pins for anything else.

Pins A4 and A5 on the arduino are the I2C lines that communicate with the LED matrix. A4 connects to SDA labeled "D" (Data) on the board, and A5 to SCL labed "C" (clock) on the board.

Digital pins 6 and 9 are used to control the servos. 6 is connected to the "X" servo (up and down) and 9 is connected to the "Y" servo (left and right).

Pin A0 is connected to both outputs of the capacitive touch sensor board. If you use a single touch sensor, you would just connect both probes (or antennas) to the input line on the breakout board, and the output would connect to A0.

Step 5: Code

Picture of Code

The code uses the SoftwareSerial library, as the Wave player causes a conflict with the Timer on the Arduino, so you will need to install and use that library to get it to work. If you are familiar with the standard servo library, It works exactly the same, although it requires you to call "SoftwareServo::refresh()" every 50ms to update the servos. You will see it in the code.

The program also uses the adafruit LED backpack and GFX libraries for the LED matrix.

The code is pretty well commented.

Instructables kind of mangled my code, so here is a link to the Github repository.

Step 6: Possible Next Steps

I am fully aware that some of my code is pretty mangled, and that it could really use some optimization. I would really like to be able to fix the hard-coded wave file names, and to use the random number directly to create the filename to play, rather than having to code the filename for each action. Unfortunately I havent had too much luck with that.

I would also smooth out the servo movements to follow the eye movements closer rather than move after the fact. I have made decent progress on that front, although it is not quite there yet. If anybody has some proper coding skills, drop some ideas in the comments.

From here you can certainly customize your project even further. You could add different sensors or create different actions or emotions. If you dig into the code a bit, you can probably figure out how to change how often your pet speaks, or when his emotions change.

In previous versions of this project, it had an IR sensor and receiver, and you could interact with it that way, and it was able to turn off the TV if you ignored it too long. Quite honestly, that ended up not being too much fun for anyone, and a Timer conflict caused a significant amount problems adding other features.

I would also consider adding a small mono amplifier, as the sound output is a little quieter than I'd like.

Comments

BrianH116 (author)2017-09-29

Love this. I'm part way into mine, this is how far i've got so far.

Im using a mega 2560 and had to put a delay(32); in the loop to slow it down a bit as it was going a bit mad! :D

drum303 (author)BrianH1162017-10-02

This looks great. Let me know how it works with the Mega, as I had always considered using it because I ran into problems with running out of memory and had to remove features because of it.

BrianH116 (author)drum3032017-10-11

Well, it works fine with the Mega and although i never got to use it all, there was certainly a stack of memory spare. Unfortunately, I fried it using what i thought was a compatible 9v power supply! Teach me to use an old power pack thats been sitting in a box in the garage for a couple of years!

Anyway, im continuing with the uno and is going ok. Im stripping all the code back and getting it to work bit by bit as part of my learning. Looking into getting it to do programmed sequences hopefully! ;)

Aditya Tripathi (author)2017-02-14

1k views and 40 likes! awesome built

IrishSnow35 (author)2017-02-13

He was able to turn off the TV if you ignored him? I think that little guy's attitude code needs adjustment. xD

gizu_one (author)2017-02-13

Instalike! Your choice on materials and the big eye fits perfect together. I totaly like this little guy. It reminds me a little bit of an robot from the old movie "Flight of the Navigator". Would be my favourite table gadget. :D

Some years ago i started to build an arduino based robot. It should also be able to show impressions (anger=red light, fast driving; scared=blue light, hiding under the couch etc..). After some research i found the kickstarter project "lilltlerobotfriends" and i planned to adapt their arduino code, which they offer for download. But i finished never the project.

Your instrcutable has motivated me to pursue the project further. Thank you!

drum303 (author)gizu_one2017-02-13

I remember that movie. You could make it speak a bunch of quotes from the movie. That would be cool. Let us know how it works out.

About This Instructable

7,776views

155favorites

License:

Bio: Sometimes I make stuff. Mostly I just start big projects and never finish them. Sometimes they take 10 years.
More by drum303:CNC Etching With the SunTwitch - Your Robotic PetLow Cost Indoor Pond
Add instructable to: