PiratePad
Full screen

Server Notice:

hide

Public Pad Latest text of pad l31MTqgYxG Saved March 27, 2013

 
     
Installing Processing 2.0b8 on Raspberry PI
 
Install Raspbian “wheezy” on your SD card :
 
Configure your Raspberry PI:
 
Update your Raspberry PI
  • sudo apt-get clean
  • sudo apt-get update
  • sudo apt-get upgrade
 
Install the java 6 sdk:
  • sudo apt-get install librxtx-java openjdk-6-jdk
 
Download Processing 2.0b8:
 
Unzip processing:
  • tar -xvzf processing*.tgz
 
Change your working directory to /home/pi/processing-2.0b8:
  • cd processing-2.0b8
 
Delete the directory /home/pi/processing-2.0b8/java:
  • sudo rm -rf java
 
Create a symbolic link to the system’s java SDK
  • sudo ln -s /usr/lib/jvm/java-6-openjdk-armhf java
 
Delete the RXTXcomm.jar file
  • sudo rm modes/java/libraries/serial/library/RXTXcomm.jar
 
Copy the system’s RXTXcomm.jar file
  • cp /usr/share/java/RXTXcomm.jar modes/java/libraries/serial/library/
 
Now that Processing is configured, let's add HTTP lib to play with twitter
 
Download HTTP library for Processing ( https://github.com/francisli/processing-http ):
Unzip it :
  • unzip http.zip
Delete __MACOSX folder and http.zip
  • sudo rm -rf __MACOSX
  • sudo rm http.zip
Copy http folder inside Processing java libraries and delete original
  • sudo cp -a http modes/java/libraries/
  • sudo rm - rf http
 
 
Open Processing from the file manager (or LZTerminal)
(ignore the ‘Not fond of this java VM‘ warning!)
 
Get your key from Twitter: https://dev.twitter.com/
 
Processing sketch:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import com.francisli.processing.http.*;
 
HttpClient client;
 
void setup() {
    size(640, 480);
    
    client = new HttpClient(this, "upload.twitter.com");
    // using SSL is optional, but recommended
    client.useSSL = true;
    // turn on OAuth request signing
    client.useOAuth = true;
    // set up OAuth signing parameters
    client.oauthConsumerKey = "insert your app consumer key here";
    client.oauthConsumerSecret = "insert your app consumer secret here";
    client.oauthAccessToken = "insert your user access token here";
    client.oauthAccessTokenSecret = "insert your user access token secret here";
    
    sendTweet();
}
 
void sendTweet(){
    // draw a PGraphics
    PGraphics pg = createGraphics(width,height);
    pg.beginDraw();
    pg.background(0);
    pg.noStroke();
    pg.fill(255);
    int t = 40;
    for (int y = 0; y < height; y += t) {
        for (int x = 0; x < width; x += t) {
            int r = (int) random(4);
            if (r == 0) pg.triangle(x, y, x, y+t, x+t, y);
            else if (r == 1) pg.triangle(x+t, y, x, y, x+t, y+t);
            else if (r == 2) pg.triangle(x+t, y+t, x, y+t, x+t, y);
            else pg.triangle(x, y+t, x, y, x+t, y+t);
        }
    }
    pg.endDraw();
  
    // save PGraphics to a file
    pg.save("sketch.png");
 
    image(pg,0,0);
    
    // set up POST params
    HashMap params = new HashMap();
    params.put("status", "Hello Twitter form Processing on RaspberryPI! check @Makio135 HowTo: http://piratepad.net/ep/pad/view/ro.oFR-vaS0OGx/latest");
    HashMap files = new HashMap();
    files.put("media[]", "sketch.png");
    client.POST("/1/statuses/update_with_media.json", params, files);    
}
 
void responseReceived(HttpRequest request, HttpResponse response) {
    println(response.statusCode + ": " + response.statusMessage);
    println(response.getContentAsString());
}
 
void draw() {
}
 
void mousePressed(){
    sendTweet();
}
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
Credits: