Related Posts in the Internet Of Holiday Lights Challenge

 

Preface

I did a project for the IOT Holiday Lights and the links to the details are given above. In addition to the YUN, I used a Raspberry Pi to automate some DIY Minions and in this small post I guide you through the process of making some yourself. Lets go...

 

The Post

Instead of linking my original post, I am copying data here for convenience.

 

Getting Minions and assigning them positions

Now minions don't exactly submit their resume via email and the ones I have a pretty lazy hence I embarked on a long journey to... Well actually I had my wife make some We had two types of minions where the first type were lazy and wanted to enjoy the party by the fireplace. These were handmade by my wife and were featured in a previous blog. The second type were party type and I printed them out and cut out the outlines. Making these minions dance was a challenge since they needed some 'support'. Now I don't have a fancy 3Dprinter(hint hint )so I resorted to what I did have and that was a lot of empty element14 cardboard boxes. And thus began my evil plan to make the minions work overtime. Muahhaa ha ha! Take a look.

 

I took apart the cardboard boxes for raw materials.

903c742fc9f2065998315eb4913098a6.jpg

Next I used a stapler and a knife to make a prop.

b6d58bbfa37eed95aa99e223f7301135.jpg

 

Next I added some mechano part from an earlier experiment. These were quite cheap 10years ago when they were presented to me. Thus my CAM and PISTON Design began to emerge from the fires of mount cardboard.

9bf504ac1629d9fef286e226ceb83a25.jpg

The minions stood by and I used glue to MAKE them participate in my experiment. Their styrofoam spines stuck like... styrofoam!

9139616cc99b8373c11be1b3417bb32f.jpg

Laughing gas..!

aa9ea315d7552e66551f5eef5402a9d1.jpg

And lastly an old toy that was relieved of it's limbs, became useful again!

5ef6dd7e03f6642ca8de9659f19f6e77.jpg

 

With that, now I have minions that dance at will.

 

Epileptic Minions -

Disclaimer! No minions were harmed(without consent) in the making of this project. The minions do dance but since the mechanism is made from material that is not stiff enough, it tends to cause... kind of epilepsy in the minions. The motor and gear system I use is from a discarded toy and due to it's gear-ratios and placement of cam, the whole thing pulls around 300mA when working. See video below.

Its clear that its not perfect and a better mechanism would solve the problem. The reason why I did not use a servo motor is because I don't have any. I got one which I used for the minion bot for the 'forgetmenot' challenge. But it works and I am willing to admit that my minions dance bad, but they can dance.

Unfortunately, the geared system sucked up too much power and it broke down a few days ago. Hence I went out and bought out a geared motor and after a little DIY magic, I got the arrangement shown below.

3c6f760a1928a323f4e34c099b9ec138.jpg

 

Moving on to the control part...

 

A simple motor switch

The minions dance when a small voltage is supplied to the motor. This I need to control via the raspberry Pi. Why not the YUN? I will that part explain later. For now, I need to make a small circuit that enables me to connect a small motor to the raspberry pi. The input signal is from the raspberry pi and the motor runs on 5V. The new motors draw around 100 -175mA at 5V which is not bad and I made a little transistor driver which can work as a switch. In order to control the speed, I simply added a 1K present between the motor and the transistor. That should enable me to calibrate the speed without messing with the PWM module. See, I took care of the simple stuff in the simplest way! The circuit is shown in the images below.

5a89dff8888204e8d13d905ce0f2d322.jpg

 

The speed is adjusted and it looks a little better than before. How better, you be the judge of that but this is the best I could do. Now to control it via the RPi

 

Raspberry Pi program to control the motor

In order to control the motor, we need to write a program to toggle the GPIO which is connected to the transistor. This can be done in a number of languages but I chose python. This is relatively simple and there are lots of tutorials on the internet for this part. I wrote and tested some code and it is given below.

 

#! /bin/python
import RPi.GPIO as GPIO
import time


#setup the Pin for the control
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, false)


#loop the loop
while(True):
    GPIO.output(18, true)
    time.sleep(10)
    GPIO.output(18, false)
    time.sleep(10)








 

This works and makes the minions dance for 10 seconds and stay still for 10 seconds and repeat.

 

Getting Tweets with Python

In my initial proposal, I wanted to have Santa ring his bell to greetings published on twitter with me mentioned. In the present case, I would use them to make the minions dance. Easier said than done and there are a number of tutorials out there about accessing twitter and the like using python. In my case, I wanted the tweets with hashtags like #happynewyear and #happyholidays etc to trigger the actions. I want only tweets with mentions to me @ip_v1 on twitter which can be accomplished a number of ways. This would involve reading the twitter feed and finding mentions and then searching for hashtags. If one is found, then the action is to be initiated. Additionally some record of the hashtag must be retained so as to distinguish between redundant instances. In my experiments, I tried do thing by many methods where the timestamps were grabbed and a few other hoops but at the end, I found a simpler method that just works.

 

Say hello to Temboo

Temboo is an online service that allows you to generate code for IOT applications in a variety of languages and devices such as CC3200 and the Arduino YUN. I used it to generate code to get tweets with mentions in python. The tweets are received in JSON format but for my solution I don't care about that. I simple use the find function

 

#! /usr/bin/python

from temboo.Library.Twitter.Timelines import Mentions
from temboo.core.session import TembooSession


import json
import re
import time

#Some global stuff here
prt_dept=50 #dept of fingerprint characters
finger_print = 'NULL'
keywrd1 = '#happy'


# Create a session with your Temboo account details
session = TembooSession("inderpreet", "myFirstApp", "XXXX")


# Instantiate the Choreo
mentionsChoreo = Mentions(session)


# Get an InputSet object for the Choreo
mentionsInputs = mentionsChoreo.new_input_set()


# Set the Choreo inputs
mentionsInputs.set_AccessToken("XXXX")
mentionsInputs.set_AccessTokenSecret("XXXX")
mentionsInputs.set_ConsumerSecret("XXXX")
mentionsInputs.set_ConsumerKey("XXXX")


while(True):
    print '\n#######################\nWoke up!'
    #Code to get the mentions


    # Execute the Choreo
    mentionsResults = mentionsChoreo.execute_with_results(mentionsInputs)
    response = mentionsResults.get_Response();


    #My work begins here
    #Mentions are now in response so convert to lower case
    resp_lower=response.lower()


    #match string1
    index1=resp_lower.find(keywrd1)


    #IF we find a match, then
    if(index1>0):
        #get new fingerprint
        new_fingerprint = resp_lower[(index1-prt_dept):index1]


        #Compare Fingerprints for new and if it IS then...
        if(finger_print!=new_fingerprint):
            finger_print=new_fingerprint;
            #Do the required action here
            print 'Found New Mention'
        else:
            print '\nNothing New'
            #else Nothing
    #Sleep for 1 minute
    print 'Sleeping...'
    time.sleep(60)


 

This code works out and I have commented it for anyone who wants to modify it for their use and if you have a better way of doing this, please do let me know.

 

Putting it all together

Once I put together the code as well as the mechanical structure, the whole thing works. Below is a video demo for documentation purposes.

 

 

Doing more with Python

You may do a lot more and I implemented some stuff using MQTT in Python. For those interested, please visit the links at the top and if there are any queries, lemme know and I will do my best to help out...

 

For now,

 

Cheers,

IP