use twitter to control arduino uno via visual basi
DESCRIPTION
Use Twitter to Control Arduino Uno via Visual BasiTRANSCRIPT
http://www.instructables.com/id/Use-Twitter-to-control-Arduino-Uno-via-Visual-Basi/
Food Living Outside Play Technology Workshop
Use Twitter to control Arduino Uno via Visual Basic 2010by techbitar on September 24, 2011
Table of Contents
Use Twitter to control Arduino Uno via Visual Basic 2010 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Intro: Use Twitter to control Arduino Uno via Visual Basic 2010 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
http://www.instructables.com/id/Use-Twitter-to-control-Arduino-Uno-via-Visual-Basi/
Intro: Use Twitter to control Arduino Uno via Visual Basic 2010(For some reason, I am unable to re-order some of the slides. As a result, the slide about adding reference to TwitterVB is not in order. )
This Instructable is a skeletal VB/Sketch app that shows how a Tweet can control Arduino Uno using Visual Basic 2010 and Arduino Sketch.
No net shield is needed for this. Just a PC with internet connection and Arduino Uno.
So you can develop apps based on this utility to send a tweet with a special keyword from anywhere in the world, and the PC running this app or your mix of the app willmonitor and intercept it then send it to the Arduino Uno to turn a light on, shut down a PC, turn the music on, etc.
The app presents the user with a form to enter the name of the Twitter user ID to monitor and the keyword/code in the Twitter status line to look for, as well as the theCOM port number used to communicate with Arduino, and whether to turn pin 13 on or off.
Most of this code is mixed from work of others such as DWRoelands (http://twittervb.codeplex.com/) and Jason (http://jdsitecare.com/1041/twitter-api-vb)
These are the main steps I followed to accomplish this integration:
- Create a Twitter account. You will need a Twitter user ID to register a Twitter application: http://www.twitter.com
- Register a Twitter App: https://dev.twitter.com/apps/new (make sure you create it as Read/Write). When done, twitter will provide you with info that you will need to pluginto the VB code to allow it to access your Twitter account/status.
- Download & install Visual Basic 2010 Express: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express
- Download the TwitterVB.dll library (TwitterVB-3.0) : http://twittervb.codeplex.com
- Create a new Visual Basic project and change Advanced Compile Option's Target .NET Framework from 4.0 to 3.5. Then add the SerialPort control to Form1
- Connect your PC to Arduino Uno
- Connect your PC to the internet
- Use the VB 2010 and Sketch code I supplied to test integration. You can then change it to suit your requirements.
- Run twitter2VB2arduino and fill form then click Monitor Twitter button. The VB app will search Twitter and if a match is found it will send either 1 or 0 (depends on your selection) over serial port to Arduino Uno to turn PIN 13 on or off.
NOTE: Efficiency of VB and Sketch code was compromised in pursuit of simplicity. I am sure there are better ways of doing this Instructable so please feel free to shareyour thoughts.
--------------------- Arduino Uno Sketch ----------------------------------------
// Mixed by: Hazim Bitar and based on many examples// NOTE: For some reason if I keep the Serial Monitor open, I get a COM port access denied error on VB app
int valPin = 13;
void setup() { Serial.begin(9600); // COM port speed pinMode(valPin, OUTPUT);}
void loop(){ while (Serial.available() == 0); // keep looping if nothing is sent over serial port int valAct = Serial.read() - '0'; // if there's data read it Serial.print(valAct);
if (valAct == 1) { // test for 1digitalWrite(valPin, HIGH); // turn on LED}else if (valAct == 0) // test for command 0{digitalWrite(valPin, LOW); // turn off LED}else{// do nothing}Serial.flush(); // clear serial port} ---------------- END OF SKETCH --------------------------------------
--------------------START OF VB 2010 CODE ------------------------' Mixed by Hazim Bitar / email: techbitar {@} gmail {dot} com / date: 24 Sep 2011' Based on the good work of DWRoelands http://www.codeplex.com/site/users/view/DWRoelands and to Jason http://jdsitecare.com/1041/twitter-api-vb/
Imports TwitterVB2Imports System.IOImports System.IO.PortsImports System.Threading
Public Class Form1 Dim twitter As New TwitterAPI Dim PinCommand As String = "z"
http://www.instructables.com/id/Use-Twitter-to-control-Arduino-Uno-via-Visual-Basi/
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click s.Close() s.PortName = "com" + txtCOM.Text s.BaudRate = 9600 s.DataBits = 8 s.Parity = Parity.None s.StopBits = StopBits.One s.Handshake = Handshake.None s.Encoding = System.Text.Encoding.Default
For Each Tweet As TwitterStatus In twitter.HomeTimeline 'txtTweets.AppendText(Tweet.User.ScreenName + vbNewLine + Tweet.Text + vbNewLine + Str(Tweet.ID) + vbNewLine + Tweet.CreatedAt + vbNewLine +vbNewLine) If Trim(LCase(Tweet.Text)) = Trim(LCase(txtCommand.Text)) And LCase(Tweet.User.ScreenName) = LCase(Trim(txtUser.Text)) Then TweetCreated = Tweet.CreatedAt If btnOFF.Checked = True Then PinCommand = "0" s.Open() s.Write(PinCommand) s.Close() ElseIf btnON.Checked = True Then PinCommand = "1" s.Open() s.Write(PinCommand) s.Close() End If ' DEBUG: MsgBox(txtCommand.Text + " | " + txtCOM.Text + " | " + txtPIN.Text + " | " + txtUser.Text + " | " + PinCommand + " | " + TweetCreated) Exit For End If Next End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load twitter.AuthenticateWith("Your ConsumerKey", "Your ConsumerSecret", "Your TokenKey", "Your TokenSecret") ' the above keys and tokens are generated by Twitter when you register your application
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub
End Class
-------------------------END OF VB CODE -----------------------------------
Image Notes1. This is your Twitter user ID which will be checked by the VB app for pre-defined keyword to trigger certain actions for Arduino. In this program, we usekeywords to turn on or off Pin 13.2. This is the keyword that you want the VB to search for. The keyword could beanything that you want it to be. NOTE: The VB app assumes the keyword is theONLY word in the Twitter status. So if your keyword is TURNMOTOR, the VBapp will not recognize a Tweet that says TIME TO TURNMOTOR. OnlyTURNMOTOR by itself in the Twitter status line.3. Match this field with the COM port your PC connects to Arduino.4. This is where you send a command 1 or 0 for Arduino to turn PIN 13 on or off.5. For this VB app, I hard-coded PIN 13 to send commands to. You can changethat in the code or from the text box default value.6. For this version of the VB program, this button will only search Twitter once fora user/command match.
Image Notes1. One way to register a Twitter App is to go to "Profile" then click "Developer"link.
http://www.instructables.com/id/Use-Twitter-to-control-Arduino-Uno-via-Visual-Basi/
Image Notes1. Create a Twitter app so you can use its access info in your VB app tocommunicate with Twitter Image Notes
1. If you don't have a website for your Twitter application simply type a validdomain name
Image Notes1. Click on this button to generate the needed Twitter access info to be used byexternal application such as the VB app in this example to access your Twitteraccount and tweets.
Image Notes1. When you clicked button "Create my access tokens" Twitter generated thosetokens which seem like long strings of random numbers and chars. You will usethose strings to give your VB app access to your Twitter user account.
Image Notes1. These are the twitter VB parameters which need to be replaced with thenumbers generated by Twitter. Sorry for poor quality of image. It must be thescaling that takes place after the uploading.
Image Notes1. 1) From VB project explorer, right click on project name and select "AddReference"2. 2) From VB 2010, browse to directory where you downloaded TwitterVB.dlland select/OK file.
http://www.instructables.com/id/Use-Twitter-to-control-Arduino-Uno-via-Visual-Basi/
Image Notes1. 1) In VB project explorer, right click on project name to open up projectproperties.2. 2) Click the "Compile" tab3. 3) Click "Advanced Compile Options"
Image Notes1. 4) Change "Target framework" to .NET Framework 3.5
File Downloads
SerialPort.pde (746 bytes)[NOTE: When saving, if you see .tmp as the file ext, rename it to 'SerialPort.pde']
Form1.Designer.vb (10 KB)[NOTE: When saving, if you see .tmp as the file ext, rename it to 'Form1.Designer.vb']
Form1.vb (2 KB)[NOTE: When saving, if you see .tmp as the file ext, rename it to 'Form1.vb']
Related Instructables
Using VisualBasic 2010 tocontrol ArduinoUno (Photos) bytechbitar
Arduino motordrives cheaptoy car (Photos)by techbitar
TwittercontrolledArduinoOutputs - no PC- LCD Display +Sensor data toTwitter byXenonJohn
AlarmingTweetby willnue
Twitter MentionMood Light bypdxnat
Tweet-a-Pot:Twitter EnabledCoffee Pot byfrenzy
http://www.instructables.com/id/Use-Twitter-to-control-Arduino-Uno-via-Visual-Basi/
Comments
2 comments Add Comment
randofo says: Sep 25, 2011. 8:56 AM REPLYNice interface. Do you have any plans to do anything fancy with it and the Arduino?
techbitar says: Sep 25, 2011. 10:28 AM REPLYI do but soon as I get the other half done (sending from Arduino to Twitter)