basic tutorial how to control a LED from in Puredata with a slider
http://nf-interactive.blogspot.com/2011/02/pure-data-to-arduino.html
(2) PureData | Arduino serial tutorial
basic tutorial how to control a LED from in Puredata with a slider
http://nf-interactive.blogspot.com/2011/02/pure-data-to-arduino.html
Just yesterday I was reading about Arduinos and LEDs, and the article claimed you need a resistor that matches the voltage to the LED, otherwise, you can burn the LED. So, you might add that as a disclaimer to the post, if it's true.
I'm a complete electrical n00b though.
@danijel said:
Just yesterday I was reading about Arduinos and LEDs, and the article claimed you need a resistor that matches the voltage to the LED, otherwise, you can burn the LED. So, you might add that as a disclaimer to the post, if it's true.
I'm a complete electrical n00b though.
well in this case the LED is wired in port 9. wich is a digital port, so no voltage is involved, in this case it can not burn since the value ( pwm 255 ) is the highest possible. only with analog ports ( 5v ) the LED can burn
@nf-interactive said:
well in this case the LED is wired in port 9. wich is a digital port, so no voltage is involved, in this case it can not burn since the value ( pwm 255 ) is the highest possible. only with analog ports ( 5v ) the LED can burn
aha, thanks.... hope that will make sense to me one day
yes, you "always" have to add a resistor connecting the analog pins to an LED but Arduino has the pin 13 which has a built in resistor so you can use that one to experiment without an external resistor.
Hey; I've followed this tutorial and managed to get it working fine. But I was wondering how I would add a second fader in PD to control another led on pin 8, like what the additional coding in Arduino would be and if any extra objects are needed in pure data?
I've tried to hazard a guess at it as can be seen here:
I've changed the faders to bangs as I want to make a little drum machine that triggers a different led per instrument. This works if I stick to the initial tutorial and keep it to 1 bang in place of the fader, but it all seems to fall apart the second I try to add a second bang (fader) in.
@nf-interactive said:
well in this case the LED is wired in port 9. wich is a digital port, so no voltage is involved, in this case it can not burn since the value ( pwm 255 ) is the highest possible. only with analog ports ( 5v ) the LED can burn
If you check this tutorial http://arduino.cc/en/Tutorial/Fade you'll see that a 220 ohm resistor is needed.
Pulse width modulation is digital which means that you can have only two states, a HIGH and a LOW. HIGH and LOW stands for voltage state. Voltage is off course involved, otherwise how would the LED light up?
@alistair_blunt said:
yes, you "always" have to add a resistor connecting the analog pins to an LED but Arduino has the pin 13 which has a built in resistor so you can use that one to experiment without an external resistor.
True, but you can't do PWM with pin 13.
Great tutorial. I'm rather new to pure data, and was wondering how to add more faders? I'm trying to control a RGB led. I assume multiplexing would easily take care of this? But i can't seem to find a sketch and patch for this anywhere. Maybe another solution is to use standardFirmata, but then again i would not know how to. This is probably pretty basic stuff for someone above my level, so any help on guiding me in the right direction, would be greatly appreciated. Thanks!
RGB LEDs need only three pins, so multiplexing is not necessary. But you need to do PWM on all three pins to control the density of each color. In your case Serial.parseInt() is your friend. It parses i coming numbers, so if you send three number as a list you have to do the following in Arduino
x=Serial.parseInt()
y=Serial.parseInt()
z=Serial.parseInt()
and you'll assign your three number to your three variables respectively. The thing is that when you send data from Pd to Arduino, it receives them as ASCII values, so you have to take care of that. I don't remember exactly how to do this.
For multiplexing check an older thread of mine http://puredata.hurleur.com/sujet-8867-arduino-multiplexers-solved
Thanks for the quick reply. I can't find much documentation on Serial.parseInt on the reference page?
I have to browse the web for some examples, so I can figure it out somehow. Regarding ASCII i suppose Pd should send i.e. 88 for the arduino to pick up an X ?
This is what I have for the Arduino so far...
int red = 9;
int green = 10;
int blue = 11;
int R = 0;
int G = 0;
int B = 0;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
int R = Serial.parseInt(); // R ASCII DEC 82
int G = Serial.parseInt(); // G ASCII DEC 71
int B = Serial.parseInt(); // B ASCII DEC 66
// say what you got:
analogWrite(red, R);
analogWrite(green, G);
analogWrite(blue, ;
}
}
What module/message should I put in pure data between comport and the slider, to hold the ASCII decimal in order for sending the right value?
Thanks again.
Arduino reads the digitis of a number as ASCII. For example the number 100 should be sent as a list like this [49 48 48( where 49 is ASCII 1 and 48 ASCII 0. If you want to send more than one number at the same time, you'll have to separate them with a space, so [100 200( would be [49 48 48 32 50 48 48( where 32 is ASCII space.
If you want to use a slider you'll have to parse the digits of the incoming number and add 48 to each digit (ASCII 0). I've already made a patch that does this, but for now I'll leave it to you, it's a better lerning process. If you can't make it, come back and ask for help
Once again, thank you Alexandros for enlighten me. I like that you don't just give it away, that would be too easy. The whole point of this tinkering, is to learn along. It is probably related to the fact, that I am impatient and want to learn it all at once, is surely making it a bit hard to grasp. It was after i got my arduino and watched some tutorials, on how to interact with it, that opened my eyes to Pure Data and it's awesomeness. I guess the right place to start, would be with some of the basics tutorials. Regarding the arduino I found this tutorial, which seems to have helped others understanding the basics of serial communication:
http://jhaskellsblog.blogspot.dk/2011/05/serial-comm-fundamentals-on-arduino.html
I'll have a look at it, and then give a shot
Thanks!
Oops! Looks like something went wrong!