• alexandros

    First of all, glad it finally worked!
    Answer 1: The current code looks better than the one you posted above it (which is apparently something I've used, hopefully in my tutorial and not the book...), because analogWrite() and digitalWrite() are only called when needed. In the first code snippet both functions are called whenever there's data in the serial line, which is overhead.
    Answer 2: I don't really have an answer to this. You can send an email to Pd's mailing list where Martin Peach, the developer of [comport] is active. It does sound strange that your computer crashes, as a longer delay just gives time to the Arduino to do the PWM stuff, but that has to do with the Arduino. Maybe there's something strange going on when the Arduino doesn't have enough time to do what it has to do, but I really don't know.

    posted in I/O hardware diyread more
  • alexandros

    Have you detected whether the crash happens with else if (in == 'd') or else if (in == 'p')?
    In the Pd patch it's probably better to swap the $1 and $2 values in the messages. Have the channel set in a cold inlet and the value in a hot one and then write this message print $2c$1v
    I see in the screenshot of the patch that the PWM message is not connected to [comport]. Is this for some particular reason? Maybe the 10ms interval for sending a PWM value to [comport] is a bit too fast. Did you try something slower, like 50ms?
    Another thing would be to try and merge messages for digital and PWM. Since PWM happens automatically, you could append the digital pin message and send something like print $2c$1p$4c$3d where $4 will be the digital pin channel and $3 the value.

    posted in I/O hardware diyread more
  • alexandros

    @cfry the thing is that the last bit of code you posted seems just fine, excluding the calling to pinMode where you're enabling the integrated pull-up resistors. Can you try that code removing these lines in setup(), and instead of heat sensitive sensors or whatever you're currently using, use simple potentiometers and verify whether that works or not? In case it doesn't work, please post a diagram of your circuit in some way (even hand-drawn is ok), as well as the full Arduino sketch and a screenshot of the Pd patch.

    posted in I/O hardware diyread more
  • alexandros

    Have you given this a try and got CPU spikes? I don't think spikes occur when using [switch~].
    As for the second question, it's super responsive. Since it is being controlled in the message domain, expect it to be enabled at the next sample block.

    posted in technical issues read more
  • alexandros

    @cfry definitely not necessary to use two Arduinos. I can't really understand where your problem lies. You didn't reply to my earlier question about the pinMode calls where you use INPUT_PULLUP on analog inputs. Is this really necessary? Also, why not use the analog pins in an array like with the digital pins? It will save a lot of writing and it's less error prone.

    One thing you might want to consider is having the Arduino notify Pd when it's done sending all its data and that it's ready to receive. That could be done at the end of the loop() function like this:

    Serial.print("done ");
    Serial.println("bang");
    

    And in Pd have a [r done] object which will output a bang. Use this bang to send data from Pd to the Arduino by unpacking a list with all the accumulated data, possibly with a [list-abs/list-drip].
    I use this notification technique in my 3dPdModular system, but there's a LOT of data there and it was only necessary. Perhaps you could try it out.

    posted in I/O hardware diyread more
  • alexandros

    I was also asking which Python module you are using to send and receive OSC. @whale-av mentioned oscpy, but there are lots of Python modules for OSC communication. It's not that hard. Can you share some Python code, at least the one you're using to send OSC to Pd.

    posted in technical issues read more
  • alexandros

    Which OSC module are you using in Python? And is it Python 2 or 3?

    posted in technical issues read more
  • alexandros

    Your question is very broad. Can you share a sample of the data you want to use and explain how you intend to use it?

    posted in technical issues read more
  • alexandros

    @cfry why do you call pinMode on pins A0 through A7? You don't need to declare the analog pins. Is this for potentiometers? Is there a reason you need the input_pullup resistors on these pins?
    What about the input dogotal pins?Are you using resistors in your circuit? Cause you're not using the input_pullups there.
    Can you share a schematic of your circuit?

    posted in I/O hardware diyread more
  • alexandros

    First of all, don't separate functions for reading the serial data, even if you want to read data for different kinds of stuff.

    Combining digital with PWM pins should be sort of straight forward. Here's some example code:

    int digitalPins[4] = {2, 4, 7, 10};
    // use an array for all the pins of similar type, e.g. PWM pins, like below
    int pwmPins[6] = {3, 5, 6, 9, 11, 12}; // can't remember the exact pin numbers with PWM, change accordingly
    
    // a global variable to hold which LED we want to control (either digital or PWM)
    int channel = 0;
    
    void setup() {
      for (int i = 0; i < 4; i++) {
        pinMode(digitalPins[i], OUTPUT);
        pinMode(pwmPins[i], OUTPUT);
      Serial.begin(115200);
    }
    
    void loop() {
      if (Serial.available()) {
        static int temp;
        byte in = Serial.read();
        if (isDigit(in)) temp = temp * 10 + in - '0';
        else if (in == 'c') {
          channel = temp;
          temp = 0;
        }
        else if (in == 'd') {
          digitalWrite(digitalPins[channel], temp);
          temp = 0;
        }
        else if (in == 'a') {
          analogWrite(pwmPins[channel], temp);
          temp = 0;
        }
    }
    

    Check this code with Pd by sending messages of the type print $1c$2d for digital values and print $1c$2a for analog values. $1 is the led number (incrementing, starting from 0), and $2 is the value you want to write, 0-1 for digital and 0-255 for PWM.

    posted in I/O hardware diyread more

Internal error.

Oops! Looks like something went wrong!