A lamp that shimmers when your sweetheart mentions you in her tweet (Arduino Yun + Temboo)
Get link
Facebook
X
Pinterest
Email
Other Apps
-
I have talked out my Floor Lamp (Ikea Orgel Vreten Floor Lamp) and how I got a Jugaad Plug-in Dimmer made for it. I had an Arduino Yún lying around and had just read up on Temboo. That's when I realized I could use the Arduino to control the lamp from the internet very easily. I noticed that Temboo could fetch tweets and so I got an idea - I could program the Arduino to dim in and dim out the lamp whenever @ZeniaIrani mentioned me in her tweets. I call the project "The Zenomaniac's Lamp"
Here is how I got it done:
Configured the Arduino Yún to connect to to my WiFi. Installed the latest version of Arduino IDE on my PC.
Assembled the circuit and installed everything in a plastic lunch box. I used white three cored cable used for electric irons for the AC input and AC output - they are long lasting and look nice. Installed 2 pin socket and plugs on the ends of the wire for easily attaching/detaching of the circuit to the lamp.
Got a Temboo account. The free account allows you to add only one application. I renamed my default application (My Account > Applications) to "Zenomania" and noted down the application key. The free plan will allow you only 1000 calls per month - meaning you can check your twitter feed only that many times in a given month window before the thing stops working - this is sad!
Got a Twitter Dev account - visit this link, login with your usual twitter account and create an application. I named mine "Zenomania". The Temboo application running on Arduino Yún requires four things - Access token, Access token secret, API key, API Secret. The API Key and API secret are shown on the API keys tab under the Application Management page. For the Access token and Access token secret, I had to click on "Test OAuth" Button - twitter then asked me to sign in once again with my twitter credentials and then displayed the Access token and secret.
I added the secrets and API keys to the Temboo read-a-tweet example and downloaded the code to Arduino over the network. The Temboo keys go into TembooAccount.h where as the Twitter keys go into the .ino file. Once I was able to get the example to working, I moved on to the next step.
I modified the Temboo read-a-tweet code so that instead of fetching tweets from my timeline, it instead fetched tweets that mentioned me. I added a function to shimmer the lamp - cycle through the 16 levels (to and fro) of dimming supported by the sunrom's digital dimmer. From the code I would call the Temboo API to fetch the latest tweet that mentions me every 65 seconds (Twitter has throttling active on all apps - you can fetch data only 15 times in a 15 minutes window before you are blocked until the end of that window). I would then check if the tweet is new and if its by ZeniaIrani. If yes, I enable the lamp to shimmer for the next 65 seconds until I check for tweets again.
So once ZeniaIrani mentions me in a tweets, it may take upto 65 seconds before the lamp starts blinking. As mentioned earlier, because of limitations imposed by twitter, we can't check the tweets more often otherwise we will start getting HTTP error codes. Similarly, once you run out of 1000 API calls per month, the lamp will stop working till the end of the 30 days period. Temboo might not be that great after all.
The Connection Diagram
16 Step dimmer modules from Sunrom.
There are also 256 Step ones available that can be
controlled using a single UART pin.
A lunch box to put everything in.
D'Cold for curing the stuffy nose syndrome.
The Arduino, dimmer and power supply for Arduino all connected.
White colored power supply was actually a phone charger.
Everything mounted neatly inside the lunchbox.
I had to break open the phone charger shell to decrease its size,
so that I could fit everything inside the box.
Used hot glue gun to stick everything inside.
For Arduino, I used screws and mounted it on the inside of the lid.
The Zenomaniac's lamp - All installed, online and working
The Shimmering Zenomaniac's Lamp
Zenomania.ino
(Assign your Twitter keys and key secrets to the four string constants declared in the beginning of the code. Modify the author name in line 123 to your own sweetheart's name)
/* ReadATweet Demonstrates retrieving the most recent Tweet from a user's home timeline using the Temboo Arduino Yun SDK. This example code is in the public domain. */#include <Bridge.h>#include <Temboo.h>#include "TembooAccount.h" // contains Temboo account information/*** SUBSTITUTE YOUR VALUES BELOW: ***/// Note that for additional security and reusability, you could// use #define statements to specify these values in a .h file.constStringTWITTER_ACCESS_TOKEN="5ghgfhgfhgfhgfhgfhgfhgfhgfhgfhgfhghfgJ";constStringTWITTER_ACCESS_TOKEN_SECRET="9xSrXMhIhgjdfkjghdfgjdfkljgXrgumB24";constStringTWITTER_CONSUMER_KEY="ECfgkjhdfkjgjdfhgkjdhfkrQ";constStringTWITTER_CONSUMER_SECRET="Tt9lgfjdfklgjdfkljgfkGjU";Stringlast_author;Stringlast_tweet;unsignedchardim_val=0;unsignedchardim_dir=0;unsignedchardim_state=1;unsignedintloop_ctr=0;voidsetup(){pinMode(2,OUTPUT);pinMode(3,OUTPUT);pinMode(4,OUTPUT);pinMode(5,OUTPUT);Bridge.begin();}voidloop(){TembooChoreoHomeTimelineChoreo;if(loop_ctr==650){// wait 65 seconds between HomeTimeline callsloop_ctr=0;// invoke the Temboo client.// NOTE that the client must be reinvoked, and repopulated with// appropriate arguments, each time its run() method is called.HomeTimelineChoreo.begin();// set Temboo account credentialsHomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT);HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);HomeTimelineChoreo.setAppKey(TEMBOO_APP_KEY);// tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline)HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/Mentions");// set the required choreo inputs// see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/// for complete details about the inputs for this ChoreoHomeTimelineChoreo.addInput("Count","1");// the max number of Tweets to return from each requestHomeTimelineChoreo.addInput("AccessToken",TWITTER_ACCESS_TOKEN);HomeTimelineChoreo.addInput("AccessTokenSecret",TWITTER_ACCESS_TOKEN_SECRET);HomeTimelineChoreo.addInput("ConsumerKey",TWITTER_CONSUMER_KEY);HomeTimelineChoreo.addInput("ConsumerSecret",TWITTER_CONSUMER_SECRET);// next, we'll define two output filters that let us specify the // elements of the response from Twitter that we want to receive.// see the examples at http://www.temboo.com/arduino// for more on using output filters// we want the text of the tweetHomeTimelineChoreo.addOutputFilter("tweet","/[1]/text","Response");// and the name of the authorHomeTimelineChoreo.addOutputFilter("author","/[1]/user/screen_name","Response");// tell the Process to run and wait for the results. The // return code will tell us whether the Temboo client // was able to send our request to the Temboo serversunsignedintreturnCode=HomeTimelineChoreo.run();// a response code of 0 means success; print the API responseif(returnCode==0){Stringauthor;// a String to hold the tweet author's nameStringtweet;// a String to hold the text of the tweet// choreo outputs are returned as key/value pairs, delimited with // newlines and record/field terminator characters, for example:// Name1\n\x1F// Value1\n\x1E// Name2\n\x1F// Value2\n\x1E // see the examples at http://www.temboo.com/arduino for more details// we can read this format into separate variables, as follows:while(HomeTimelineChoreo.available()){// read the name of the output itemStringname=HomeTimelineChoreo.readStringUntil('\x1F');name.trim();// read the value of the output itemStringdata=HomeTimelineChoreo.readStringUntil('\x1E');data.trim();// assign the value to the appropriate Stringif(name=="tweet"){tweet=data;}elseif(name=="author"){author=data;}}if((last_author==author)&&(last_tweet==tweet)){//Nothing newdim_state=0;//Turn off the lamp now}elseif(author=="ZeniaIrani"){//New Tweet from Zenialast_tweet=tweet;last_author=author;dim_state=1;}else{//New Tweet but not from Zenialast_tweet=tweet;last_author=author;dim_state=0;}}else{// there was an errordim_state=0;}HomeTimelineChoreo.close();}if(dim_state==1){//Yes we must blink the lampif(dim_dir==0){dim_val=dim_val+1;}else{dim_val=dim_val-1;}if(dim_val==16){dim_dir=1;dim_val=15;}elseif(dim_val==0){dim_dir=0;dim_val=1;}if((dim_val&0x01)==0x01){digitalWrite(2,HIGH);}else{digitalWrite(2,LOW);}if((dim_val&0x02)==0x02){digitalWrite(3,HIGH);}else{digitalWrite(3,LOW);}if((dim_val&0x04)==0x04){digitalWrite(4,HIGH);}else{digitalWrite(4,LOW);}if((dim_val&0x08)==0x08){digitalWrite(5,HIGH);}else{digitalWrite(5,LOW);}}elseif(dim_state==0){//Turn off the lampdigitalWrite(2,HIGH);digitalWrite(3,HIGH);digitalWrite(4,HIGH);digitalWrite(5,HIGH);}delay(100);loop_ctr=loop_ctr+1;}
TembooAccount.h
(Modify the 3 defines to match your own temboo login name, application name and application key. Place this file in the same folder as .ino file)
1
2
3
#define TEMBOO_ACCOUNT "lithiumhead" // your Temboo account name #define TEMBOO_APP_KEY_NAME "Zenomania" // your Temboo app key name#define TEMBOO_APP_KEY "fgdfsgdfgdfgdfgdffgdfgc" // your Temboo app key
Mobile Phone/Tablet charging Power Banks can be used to power so many DIY projects. But if your project is low power and draws very little current, the power bank will auto turn off after a few seconds thinking that it isn't being used to charge gadget (because the current draw is very low). I need to figure out a way to hack one and locate and replace the current sense resistor with one of a higher value. Here is how I did it. This told me that the resistor would be located on the return path (ground path) of the output USB connector. I promptly located the R100 SMD resistor in my iBall portable charger. The fact that this resistor was fatter (higher power dissipation rating) and that it was 0.1 ohms in value confirmed that this had to be the current sense resistor Original 0.1 ohms current sense resistor I measured the voltage across it when nothing was connected. It was zero volts and the portable charger turned off in a few seconds when nothing was being charg...
CH375B module. It is usually supplied with a 2 way jumper mounted on TXD and RXD pin. The TXD RXD pins are located next to the female USB receptacle. Please unmount the jumper before use. Get the following components: Arduino Nano Male to female jumper wires - 4 pieces USB Mouse CH375B module Download MeUsb.cpp and MeUsb.h from https://github.com/xeecos/Me-USB-Host On your Windows computer which already has arduino installed, go to your documents folder. There you will find a folder called arduino and within that another folder called libraries. Inside this libraries folder create a new folder called "MeUsb" Place MeUsb.cpp and MeUsb.h in this folder In the arduino\libraries folder, create another folder called "SoftwareSerial_fix" And in this folder download and place SoftwareSerial_fix.cpp and SoftwareSerial_fix.h from the same link as above. Assemble the circuit on the bread board as follows: +5V of Arduino Nano to ...
So here is a pair of programs demonstrating the use of sockets on Linux. The server program is run first. Then whenever the client program is run, it connects to the server on the specified port and they both exchange strings and terminate. TCP is used over IPv4. Simple_tcpserver_ipv4.c: # include < stdio.h > # include < stdlib.h > # include < unistd.h > # include < string.h > # include < sys/types.h > # include < sys/socket.h > # include < netinet/in.h > # include < netdb.h > # include < arpa/inet.h > void error ( char * msg ) { perror ( msg ) ; exit ( 1 ) ; } int main ( int argc , char * argv [ ] ) { int sockfd , newsockfd , portno ; socklen_t clilen ; char buffer [ 256 ] ; struct sockaddr_in serv_addr , cli_addr ; int n ; if ( argc < 2 ) { fprintf ( stderr , " Usage: %s \n " , argv [ 0 ] ) ; exit ( 0 ) ; } ...
Comments
Post a Comment