Tuesday, November 17, 2009

PD to Ardunio - Serial working :)

I've managed to send serial data to the arduino using the 'comport' object. Here's how you do it:


On the arduino IDE code:

add following lines to the void start() code:

void start()
{
Serial.begin(115200); // start serial communication to Pd
}
&

add following lines to the void loop() code:

void loop()
{
...
...
enableState = digitalRead(enablepin); // read the state of the enable pin

// send the value to the serial port (Pd)
if (Serial.available() > 0)
{
enaState = Serial.read(); // receive data from Pd
digitalWrite(enablepin, enaState); // turn the leds on/off
}
...
...
}

After I uploaded the code to the Arduino and opened the PD patch, I could toggle the LEDs on and off using a toggle.

No comments:

Post a Comment