Interfacing the Wiring hardware and Pure Data pd~

This tutorial introduces the basic interfacing between the Wiring hardware and Pure Data http://puredata.info. The brief for the tutorial will be to read simple values from the Wiring board. It assumes the Wiring software and Pure Data are installed and the proper Wiring setup has been previously completed. For more Information on Wiring install check out the tutorials about Wiring installation and software setup.

Step 1

Copy and paste the following code on the Wiring editor: Verify your program is free of compiling errors by pressing the Compile/Verify button in the menu bar. Press the Upload button in the menu bar. In case of syntax errors the Wiring environment will print the error messages otherwise it will print the Upload was completed successfully, the uploading process triggers activity in the Rx/Tx LEDs on the Wiring hardware. The new program will start automatically after uploading. Use the Serial Monitor button to watch the data coming from the Wiring board, then close the Serial Monitor again.

/** 
 * Photoresistor / Pure Data

 * 
 * Reads values from a photoresistor connected to the 
 * analog input pin 0. The value read from the sensor is proportional
 * to the amount of light that hits the sensor surface.
 * The value read is printed through the serial to be monitored
 * in the console or received on Pure Data
 */

int val; 

void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
}

void loop() 
{
  val = analogRead(0);     // read analog input pin 0
  Serial.print(val/4, BYTE);  // prints the value read from the
                               // sensor in analog pin 0 divided by 4 (range 0-255)
  delay(200);                  // wait 200ms for next reading
}

 

Step 2

Next step is to setup things in Pure Data. Start Pure Data.

Note: The object "comport" has 2 attributes, the first one is the port number and the second one is the speed of the port which should match the speed set in the Wiring program.

 

Step 3

Connect the objects as shown:

 

Step 4

Press the message "devices" to print in the console the available ports, in this case the correct serial port is the port # 2:

Step 5

Routing the connections sometimes produce a more readable patch, now the patch is ready to be tested, set the right port in the list, automatically the port start to receiving data. The incoming data will be shown in the console and visualized int the horizontal slider.

 

Next >> Sending data to the Wiring board from Pure Data