Wiring and Quartz Composer

From Wiring

Jump to: navigation, search

by Carlos Mario Rodríguez

This tutorial introduces the basic interfacing between the Wiring hardware and Quartz Composer. The brief for the tutorial will be to send data to the Wiring board, the Wiring board will read the data and turn ON or OFF the board LED accordingly, and to read simple values from the Wiring board. It assumes the Wiring software and Quartz Composer 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.

Contents

Wiring Code


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.

Send data
/** 
* Photoresistor / Quartz Composer
*by Carlos Mario Rodríguez
* 
* 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 and send it to Quartz Composer
* Adicionally, the program sends a character '-' (ascii = 45) to devided the values
* when are received by Quartz Composer.
*/

int val; 

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

void loop() 
{
  val = analogRead(0);          // read analog input pin 0
  Serial.println(val/4, DEC);  // prints the value read from the
                                          // sensor in analog pin 0 divided by 4 (range 0-255)
  Serial.write(45);		  //ascii for minus sign
  delay(200);                       // wait 200ms for next reading
}
Receive data
/** 
* Simple Read/Quartz Composer
* 
* Read data from the serial port and turn ON the onboard LED if
* the character received is an 'H' but if the character received is
* an 'L' turn OFF the onboard LED
* For the Wiring boards v1 the on-board LED is on pin 48,
* on Wiring S the on-board LED is on pin 15.
*/
int val;          // variable to receive data from the serial port

void setup() 
{
  pinMode(WLED, OUTPUT);  // pin 15-48 (on-board LED) as OUTPUT
  Serial.begin(9600);       // start serial communication at 9600bps
}

void loop() {
  if( Serial.available() )         // if data is available to read
  {
    val = Serial.read();           // read it and store it in 'val'
    if( val == 72 )               // 72 = H for ASCII code
    {
      digitalWrite(WLED, HIGH);  // turn ON the LED
    } 
    else if( val == 76 )       // 76 = L for ASCII code
    { 
      digitalWrite(WLED, LOW);   // otherwise turn it OFF
    }
  }
  delay(100);                      // wait 100ms for next reading
}

Download and Install Kineme Serial IO patch


Download

Download the Kineme Serial IO patch from here

Note: To acces to the link you must login first in the Kineme website and check the Beta tester box in the edit profile tab.

QuartzComposer01.png

Install

Place the plugin file in

/Users/[you]/Library/Graphics/Quartz Composer Patches/

(Create the folder if it doesn't already exist.)

Setup Quartz Composer


Next step is to setup things in Quartz Composer. Start Quartz Composer and choose a basic composition.

QuartzComposer00.png

Send data

Look for Serial Input, Image With String and Billboard in the Patch Library and connect the objects as shown.

QuartzComposer02.png

Click over the Kineme Serial Input box and set up the Device with the name of the port you connected the Wiring hardware, set the Baud rate if you need it (for this example 9600 it´s ok) and add a minus sign '-' in the Break String text field.

QuartzComposer03.png

Now, you see the data from the Wiring hardware in the viewer. Like this.

QuartzComposer04.png

Receive data

Look for Serial Output and Keyboard in the Patch Library and connect the objects as shown.

QuartzComposer05.png

The Kineme Serial Output connected to the up arrow must be set up like this.

QuartzComposer06.png

The other one must be set up like this.

QuartzComposer07.png

Remember you must set up the Device with the name of the port you connected the Wiring hardware.

Now you go to the viewer and if you press the up arrow in the keyboard turn ON the onboard LED but if you press the down arrow turn OFF the onboard LED.

Language: English
Personal tools