Control raspberry from twitter

OBJECTIVE:  Use the Raspberry PI to monitor a Twitter feed and control a mechanical device.If you are not interested in the details of the build and just want to see the result you can watch the vid below.

RESULT:  Success!!!  You can control the “The Hand of PI” by sending a tweet to @OurCatDoor.   If your tweet includes any of the text below, the “Hand of PI” obeys your command.  Valid commands are (lowercase):

  • one (holds up one finger)
  • peace (shows the two finger peace sign)
  • three (three fingers up)
  • hookem (if you are a Texas Longhorn fan this one makes sense)
  • fist (the Hand of PI gets ready to fight)
  • open (ready for a ‘high five’)
  • finger (well…  this will be the most tweeted command)

Go ahead, try it!!!  Send a tweet command to @OurCatDoor to let us know you were here.
—–
Basically what you are seeing is the Raspberry PI running a Python script searching any tweet sent to @OurCatDoor.  In the video, an iPad sends a tweet to @OurCatDoor that has the command “finger” in it.  It takes a few seconds, but the Raspberry PI finds the tweet, parses it, and find the “finger” command.  The Python script then sets the PI’s GPIO ports High/Low.  The PI GPIO is connected to a PICAXE 18M2 (via a HC7404 buffer).  The PICAXE 18M2 reads the PI’s GPIO to control five servo motors.  “Hand of PI” reacts with the appropriate gesture.  Watch closely and you can see the text on the screen update as the “finger” command is found and the “Hand of PI” gestures.   There’s a lot going on here.  Confused?

Of course this isn’t full schematic, but it lays out all the I/O to align with the source code you see below.  Really, the interconnects and 5VDC to the servos, PI, PICAXE, and HC7404 is something anyone wanting to duplicate the project should easily understand given the block diagram and source code.

This video is a bit long but demonstrates all the gestures of the “Hand of PI”.  The screen in the background shows output from the Python script.  The screen is not needed, but I included it in the video to show the tweets as they are captured.  Note the “Hand of PI” reacts when a new tweet command is found.
Everyone wants to see the “Hand of PI” flip the bird; that is the last gesture if you want to skip to the end..

Control raspberry from twitterIf you are still with us, enjoy some source code for your reading pleasure.
First the program that is running on the PICAXE 18M2.  It’s job is to read the Raspberry PI’s GPIO output and control the five servo motors on the “Hand of PI”.

‘ PICAXE 18M2 for RaspPI intergration to Tweeter Controlled Hand Gesture Robot APRIL 2013
‘”THE HAND OF PI”
‘ www.whiskeytangohotel.com
‘ NOTE: PICAXE Program Editor Rev newer than 5.3.6 causes servo jitter***
‘ Other than the minium PICAXE 18M2 ‘keep alive’ 22K R & 10K R
‘ no other R, C, L, etc need for the project.
‘ Everything on PICAXE powered by 4.5VDC
‘ The PICAXE drives the servos straight from the chip.
‘ See pinouts in comments

‘ 0 is Thumb (PICAXE pin 6)
‘ 1 is Pointer (PICAXE pin 7)
‘ 2 is Middle (PICAXE pin 8)
‘ 3 is Ring (PICAXE pin 9)
‘ 4 is Pink (PICAXE pin 10)
‘ Normally Open Button Switch is PICAXE pin 18 (pulled HIGH with 10K)
; this button will not be used for the PI intergration

‘ PI GPIO 11 connected to c.0 (PICAXE pin 17)
‘ PI GPIO 13 connected to c.7 (PICAXE pin 16)
‘ PI GPIO 15 connected to c.6 (PICAXE pin 15)

symbol RaspPI11 = pinc.0
symbol RaspPI13 = pinc.7
symbol RaspPI15 = pinc.6

‘Define Servo values to fully EXtend/Open finger
Symbol Ex_Thumb = 60
Symbol Ex_Pointer = 60
Symbol Ex_Middle = 245
Symbol Ex_Ring = 60
Symbol Ex_Pink = 60

‘Define Servo values to fully CLose finger
Symbol CL_Thumb = 225
Symbol CL_Pointer = 240
Symbol CL_Middle = 50
Symbol CL_Ring = 240
Symbol CL_Pink = 240

‘Init the servos
servo 0, Ex_Thumb
servo 1, Ex_Pointer
servo 2, Ex_Middle
servo 3, Ex_Ring
servo 4, Ex_Pink

pause 400

‘Gesture Subroutines are (2^3 = 8 can be PI Callable)
‘ Valid Tweet commands are: one, peace, three, hookem, fist, finger, wave

‘Insure Open_Hand position at program start
gosub Open_Hand
pause 500

main:  ‘This loops until hell freezes over

‘Read the RasPI GPIO bus and  jump to gesture sub routine

If RaspPI15 = 0 and RaspPI13 = 0 and RaspPI11 = 0 then
gosub Open_Hand
end if

If RaspPI15 = 0 and RaspPI13 = 0 and RaspPI11 = 1 then
gosub One
end if

If RaspPI15 = 0 and RaspPI13 = 1 and RaspPI11 = 0 then
gosub Peace
end if

If RaspPI15 = 0 and RaspPI13 = 1 and RaspPI11 = 1 then
gosub Three
end if

If RaspPI15 = 1 and RaspPI13 = 0 and RaspPI11 = 0 then
gosub Hook_em
end if

If RaspPI15 = 1 and RaspPI13 = 0 and RaspPI11 = 1 then
gosub Fist
end if

If RaspPI15 = 1 and RaspPI13 = 1 and RaspPI11 = 0 then
gosub F_You
end if

‘If RaspPI15 = 1 and RaspPI13 = 1 and RaspPI11 = 1 then
‘ gosub Wave  ‘wave is pretty hard on the servos, so we commented it
‘end if

pause 5
goto main

‘ Gesture Subroutines below:
Open_Hand:
servopos 0, Ex_Thumb
servopos 1, Ex_Pointer
servopos 2, Ex_Middle
servopos 3, Ex_Ring
servopos 4, Ex_Pink
return ‘ Open_Hand

Hook_em:
servopos 0, CL_Thumb
servopos 1, Ex_Pointer
servopos 2, CL_Middle
servopos 3, CL_Ring
servopos 4, Ex_Pink
return ‘Hook_em
Control raspberry from twitter SchematicF_you:
servopos 0, CL_Thumb
servopos 1, CL_Pointer
servopos 2, Ex_Middle
servopos 3, CL_Ring
servopos 4, CL_Pink
return ‘F_you

One:
servopos 0, CL_Thumb
servopos 1, Ex_Pointer
servopos 2, CL_Middle
servopos 3, CL_Ring
servopos 4, CL_Pink
return ‘One

Peace:
servopos 0, CL_Thumb
servopos 1, Ex_Pointer
servopos 2, Ex_Middle
servopos 3, CL_Ring
servopos 4, CL_Pink
return ‘Two

Three:
servopos 0, CL_Thumb
servopos 1, Ex_Pointer
servopos 2, Ex_Middle
servopos 3, Ex_Ring
servopos 4, CL_Pink
return ‘Three

Four:
servopos 0, CL_Thumb
servopos 1, Ex_Pointer
servopos 2, Ex_Middle
servopos 3, Ex_Ring
servopos 4, Ex_Pink
return ‘Four

For more detail: Control raspberry from twitter

Scroll to Top
Read previous post:
Raspberry Pi 433Mhz RF Communication Via ATtiny85

The Experiment: In this experiment were going to explore the possibility to replace the Arduino UNO Wireless Weather Station web...

Close