This guide 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 will monitor 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 the COM 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 plug into 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 share your 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 1
digitalWrite(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 TwitterVB2
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Dim twitter As New TwitterAPI
Dim PinCommand As String = "z"
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 -----------------------------------
techbitar (author) says:
Jul 31, 2012. 4:41 AMReply
techbitar (author) says:
Aug 14, 2012. 12:55 PMReply
techbitar (author) says:
Dec 9, 2011. 2:46 AMReply

















Not Nice



















Visit Our Store »
Go Pro Today »



