Anonymous commenting enabled / on the bottom of the page is a vote for next tutorials

Sunday, February 20, 2011

Pure Data to Arduino

You can control Arduino values from in PureData


01| CONNECTING THE LED TO THE PWM PORT ON THE ARDUINO

1. Place a LED on the breadboard ( you can choose where )

2. Connect a line from the PWM port (9 in this case) to the IN of the LED ( the longest end ) we will also define this in Arduino


3. from the OUT of the LED connect a line to the GND ( ground ) of the arduino board


Thats it for the Arduino connection part.

02| MAKING THE ARUIDNO SKETCH
I made a very understandable sketch.

this is the code ( the code is self-explanatory but if u don't understand something you can always leave a comment with your problem.)

int incomingByte = 0; // for incoming serial data
int led = 9;

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(led, OUTPUT);
}

void loop() {

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
analogWrite(led, incomingByte);
}
}


03| MAKING THE PURE DATA PATCH

4. start by making a "comport 9600" object. comport is the communication port. you will select wich port in the next step. 9600 is the data transfer speed, we will also define this in Arduino


5. Add a message button with "devices", this will list all available devices in the print window (console). You should know wich device it is because you selected this in the arduino toolbar.



6. When you see in the console wich device it is you use for arduino, you can add a "Open #DeviceNumber" in my case "Open 3".


7. Now it's time to make the controlslider for the PWM value of the LED in arduino.
add a "vslider" object. stands for Vertical Slider



8. we need to change the value of the slider so it matches the PWM output values for the LED. the values for a PWM go from "0 - 255". with 255 being Full bright LED.
so we Right click the slider and go to properties and change the value


That's it for the PureData Part.

16 comments:

  1. Thanks, this is way cooler "Hello World!" then the one I was reading about yesterday :)
    I think I'm getting my first breadboard and LED tomorrow ;)

    ReplyDelete
  2. I'm having a bit of a problem. When selecting to open the port (in my case 'open 4') I receive this message:

    get_baud_ratebits: 0.000000
    set_baudrate baudbits: 0
    error: [comport] ** ERROR ** could not set params to ioctl of device /dev/tty.usbserial-A700dAiM

    Any ideas? I really need to get this working :)

    Cheers

    ReplyDelete
    Replies
    1. If you are on linux, your arduino serialport is listed as "/dev/ttyACM0" or something...

      Delete
  3. Any Methods on how to connect board via USB ?Which Objects should I use in Pure Data ?

    Thanks in advance

    ReplyDelete
  4. FOR THE ERROR
    -------------
    have u tried other ports? and is the device connected (usb)? check wich port u chose in the arduino interface

    ReplyDelete
  5. you have helped out my arduino project so much!! thank you. Im trying to combine your light code and sensor code, and it uploads but im not sure if its right. maybe you could look at my code, so i can determine whether to move on to see if its a hardware issue?


    int incomingByte = 0; // for incoming serial data
    int led = 9;
    int sensorValue = analogRead(A0);
    int serialValue = sensorValue / 4;

    void setup() {
    Serial.begin(9600);
    pinMode(led, OUTPUT);
    }

    void loop() {
    Serial.write(serialValue);
    leed;
    }

    void leed() {

    // send data only when you receive data:
    if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    analogWrite(led, incomingByte);
    }
    }

    ReplyDelete
  6. in the loop.. the "leed;" should be "leed();" ? you can try that for a start :) oh and you can email me it's more convenient i think :)
    migzter@gmail.com

    ReplyDelete
  7. Hey,thanks! This basic tutorials are great!

    Would you mind in help me to control a RGB Led using Puredata? I would have to control 3 (instead of only one) of the PWM in the Arduino board. How can I do it?

    ReplyDelete
  8. One thing, I tried the Pd arrangement you gave but its not working, turns out comport takes in 2 parameters, the first is the port number, the second is the speed. Can you rectify that?

    ReplyDelete
  9. Thadfues, the rate is an optional parameter. The standard speed is enough for this application but you can specify it if u need. It's in 'baud'

    ReplyDelete
  10. Hi there;

    Thank you very much for your tutorials, the Arduino and Processing ones have been a great help to me.

    I was wondering; if I wanted to add a second slider to control another LED, what would be the best way of going about this? Other than the 2nd fader is there anything else I would need to add in Pure Data?
    I think I have the code required in Arduino, it's getting that second stream of numbers between the two programs.

    Thank you :)

    ReplyDelete
  11. Thanks, the best and symple tutorial for Pd and Arduino! ;)

    ReplyDelete
  12. I would also like to know more about, additional leds and sliders. I think that the serial communication need to be defined in an array, or something?

    Guess it's pretty easy and basic stuff, for someone with a little more experience...

    Thanks for your tutorial, and getting me so far.

    ReplyDelete
  13. Hi! Your tutorial seems really interesting, I'd love to learn more about this for a project I am running but I can not manage to see the images you posted to illustrate the tutorial. Has something to do with the explorer? I am using Chrome and Safari...

    Thanks very much!

    Teresa

    ReplyDelete
  14. hello,
    great tutorial! is it possible to transmit bigger values than one byte?
    best regards

    paul

    ReplyDelete
  15. Sorry, I can not see the images, and I'm trying for the first time to carry out a project. The connection with Puredata 32-Bit, works well. Instead with pd 64-bit, I get the following message:
    comport number 0 out of range (1-99)
    Could you help me?
    Thank you very much
    a great greeting
    It is a joy for me to be able to learn, puredata is or seems infinite.
    Thank you very much again and if you have the images and you can put them in hand, thank you very much

    ReplyDelete