Pure data + Arduino Serial - Control 2 LEDs + PWM at a time

Hello, I'm having some problems sending data from Pure Data to Arduino. I am using PD to control 16 LEDs with only 2 on at any one time.

I have a discussion going on on the PD forum here, but thought some help the Arduino end may be useful.

In PD I am reading a text file and then sending values to control two LEDs (LED1 and LED2) and their PWM. The LED2PWM = 255-LED1PWM.

I have found this to half-work (see joe_working.zip) sending 2 values (LED1 and PWM1).

With this code I get a good PWM increase/decrease on the correct LED

I need to send a string of 3 values out of PD and read them into Arduino, however - when I add another message to the PD end everything stops working (see original_code_3).

I also tried another approach which choked up and turned random LEDs on (see using_serialprint2_example).

Finally I attempted to trick the joe_working patch and sketch into doing what I wanted by alternating the values between different LEDs (see joe_working.zip).

All text files and abstractions are included in each zip file.

Any help would be really greatly appreciated. I am very stuck, confused and frustrated lol.

All the best,

Joe

joe_working.zip (7.04 KB)

using_serialprintln2_example.zip (6.2 KB)

original_code_3.zip (5.99 KB)

I don't know anything about PureData and I have not looked at your zip files - why not just show the code in your Post or add it as a .ino file ?

You may find some useful stuff in serial input basics. Examples 2 an 3 could receive any number of pieces of data.

...R

The Arduino code is attached in the zip files. There are three different codes to go with each PD patch. I thought it would make it easier to match them up. Here is some Arduino code for one of the patches:

#include <Tlc5940.h>
int ledNo1 =0;
int ledNo2 =0;
int pwmVal =0;


void setup() {
  Serial.begin(57600);
  Tlc.init();
}

void loop() {

  while(Serial.available()){
    
    int intVal1=Serial.parseInt();
    int pwmVal=Serial.parseInt(); 
    int intVal2=Serial.parseInt();  
  
   if (intVal1 <= 16){
      
      ledNo1=intVal1-1;
    }
    
    if (intVal2 <= 16){
      
      ledNo2=intVal2-1;
    }

  Tlc.set(ledNo1, pwmVal); 
  Tlc.set(ledNo2, pwmVal); 
 
  Tlc.update();
  delay(50);
  }

Tlc.clear();

}

I have done Serial comms. successfully before between different Arduinos and other software etc.

The problems with PD is that it does not allow you to send characters which makes delimiting difficult. If you look at the attached file joe_working you will see that this works, however when 1 additional value is added it does not. I will have a look at your examples and see if they help.

Joe

There seems to be a huge amount of stuff in the joe_working zip file.

Can you just give some examples of the output data that PureData produces ?

...R