Posts Tagged Processing

A Processing Java Applet in WordPress

Turns out that figuring out how to embed a Processing Java applet in WordPress was quite the endeavor.   Ended up writing a Wordpress plugin. Here is a link to the tarball: wp-proc-embed.tar.gz

A few brief instructions for installation and use:

  1. Extract into the wp-content/plugins directory (Same as every other plugin for WordPress).  If you can’t figure out how to extract a .tar.gz file, and I’m in a good mood, let me know and I’ll create a zip for you.
  2. Login to wordpress as admin and activate the plugin.
  3. Export your Processing project.
  4. Copy/scp/ftp the entire directory tree of the sketch (which should now include an applet directory) to wp-content/plugins/wp-proc-embed/
  5. As an example of what the directory structure should look like in step 4 I have included the applet “threeballsclass”.  The exported java files appear in wp-content/plugins/wp-proc-embed/threeballsclass/applet/
  6. Make a new post and include the following tag to display the threeballsclass applet with a dimension of 200 x 200:   LEFT BRACKET processing=threeballsclass 200 200 RIGHT BRACKET
  7. Publish and Pray.
  8. I just realized that I called the example project “threeballsclass” and there are actually four balls flying around.  Deal with it.

Here’s the applet in action:

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

(If anyone knows the escape character for the left and right brackets, so I don’t have to use LEFT BRACKET and RIGHT BRACKET above, let me know.  I’m having to do this because otherwise it displays the applet)

Tags: , , , ,

Enabling Serial Communication in Processing/Arduino

I have been trying to dissect the differences between the implementation of serial asynchronous communication in Processing 1.0 and the Arduino IDE.  There are even broader differences between the two environments (Arduino is based on C/C++, and Processing is Java based) but fortunately these do not come into play with the current investigation.  Arduino is a simple development environment which allows for the programming of Arduino boards.  The board I am currently using is the Duemilanove (Italian for 2009), which has at its heart an ATmega.328 micro-controller.

Processing is a programming language that allows users to quickly create programs, or “sketches”, that generate graphics and gives control to input and output devices such as the keyboard, mouse, and serial ports.  More information on Processing can be found here. What follows is how to enable serial communication for both the Arduino IDE and Processing.

The first issue is choosing which serial port to use in the current project.  In the Arduino IDE, this is accomplished by selecting Tools — Serial Port and then choosing the appropriate serial port.

Selecting the Serial Port in Arduino

Note that in the above figure, that Serial Port is not available (grey).  If you have successfully installed the serial drivers, then you should get a list of available ports (I’m not writing this entry from my development machine).  Selecting your serial port in the Arduino is as easy as that.  Processing, however, is a much broader programming environment and therefore hooking up to a serial port must be done manually.  The following code shows how to do this:

// Serial communication in Processing 1.0
 
// Import the processing serial libraries
import processing.serial.*;
 
// Declare a serial port:
Serial myPort;
 
// List all available serial ports:
println(Serial.list());
 
/*
Open whatever port is the one you're using.  Mine is zero,
hence Serial.list()[0].  Also, 9600 is the bps (bits per second) of
the connection.
*/
 
myPort = new Serial(this, Serial.list()[0], 9600);
 
// Send an E to the serial port.  69 is the ASCII value for capital E.
myPort.write(69);

I would imagine that something similar to the above block of code is actually running when selecting the serial port from the drop-down menu in the case of the Arduino IDE. Also worth mentioning is that when using the Arduino IDE, the serial libraries have already been included, and therefore do not have to included manually as was the case with Processing.

Tags: , , ,