Back to tutorial index

Pure Data to Arduino Over Serial

Contents:

A basic example of getting the Arduino to make music using Pure Data.
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // Change to whatever you hooked 
                                 // RX, TX up to
	
void setup() {
 mySerial.begin(9600);
}

void loop() {
 for (int i=0; i<255; i++) {
 mySerial.write(i);
 delay(100);
 }
 for (int i=255; i>0; i--) {
 mySerial.write(i);
 delay(100);
 }
}

#N canvas 499 140 450 300 10;
#X msg -158 30 devices;
#X floatatom -120 111 5 0 0 0 - - -;
#X msg -94 32 open 2;
#X obj -120 78 comport 2 9600;
#X msg -37 33 close 2;
#X obj -117 177 osc~;
#X obj -116 212 dac~;
#X obj -120 140 * 10;
#X connect 0 0 3 0;
#X connect 1 0 7 0;
#X connect 2 0 3 0;
#X connect 3 0 1 0;
#X connect 4 0 3 0;
#X connect 5 0 6 0;
#X connect 5 0 6 1;
#X connect 7 0 5 0;
A nice feature of Pd is that all the patches are in a simple text format.

To Get this Example Working:

          pd

You should see output of the comport changing, and should hear a rising and falling tone.

Pure Data to Arduino over serial in Action - Shown with "Hello Arduino" Board"