My project for the Internet of Holiday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don’t need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.
In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system. I also setup the place for the lighting with some homemade arts and crafts and give a preview of the system setup. I explained the Library I made for the Infineon Shield as well as the implementation for the MoodLights and made them Dynamic. I also made a XMAS Tree with LEDs and some stuff.
In this post I add a minion element to the project. I had initially planned to have a Santa Claus ring his bell everytime someone wishes me on twitter, but santa is busy and I have minions…
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.
Next I used a stapler and a knife to make a prop.
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.
The minions stood by and I used glue to MAKE them participate in my experiment. Their styrofoam spines stuck like… styrofoam!
And lastly an old toy that was relieved of it’s limbs, became useful again!
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.
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.
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.
At this point I am almost done with my project but I need to complete the documentation for the actual living room. I hope to complete that tomorrow. A lot of time and energy has been put in to make this project and I hope everyone likes the results.