[SOLVED] Control multiple servos with Isadora -> Arduino (example attached)

  • I want to send serial data from Isadora to 4 separate servos.

    I thought I would use the send Serial actor and create an string with an identifier for each servo followed by the position, so one of my send serial actors would have:

    "A" P1

    P1 will be an integer that will be the servo position.

    My arduino code for handling the serial in data is:

      if (Serial.available() > 0) {
        inString = Serial.read();
        if (inString.substring(0,0) == 'A') {
          String valString  = inString.substring(1);
          pos = valString.toInt();
          inString = "";
        if (inString.substring(0,0) == 'B') {
          String valString  = inString.substring(1);
          pos = valString.toInt();
         inString = "";

    I get a response from the servo, but not what I want, any ideas or examples on how to do this properly? I figure this is not really going to work as I cannot send data to 2 servos at the same time.

    If I have a send serial actor with P1 P2 P3 P4 how can I get these as separate values in Arduino?

  • @fred

    So now I have something that works, but it is very slow, I cannot update more than 1 time per second and commands seem to lag one behind (they send through when I send another command).

    I took a pretty different route that I have used before with my own code but not via Isadora: I send all the data at once as a string and parse it on the arduino side, here is the arduino code:

    #include <Servo.h>
    Servo myServos[4];  // create servo object to control a servo
    // twelve servo objects can be created on most boards int pos = 0;    // variable to store the servo position
    String serialString;         // incoming serial byte
    int servoPositions[4];
    void setup() {
      myServos[0].attach(8);  // attaches the servo on pin 9 to the servo object
    } void loop() {   if (Serial.available()) {     serialString = Serial.readString();
        String servo1 = serialString.substring(serialString.indexOf('A') + 1, serialString.indexOf('B') );
        servoPositions[0] = servo1.toInt();
        String servo2 = serialString.substring(serialString.indexOf('B') + 1, serialString.indexOf('C') );
        servoPositions[1] = servo2.toInt();
        String servo3 = serialString.substring(serialString.indexOf('C') + 1, serialString.indexOf('D') );
        servoPositions[2] = servo3.toInt();
        String servo4 = serialString.substring(serialString.indexOf('D') + 1, serialString.indexOf('|') );
        servoPositions[3] = servo4.toInt();     serialString = "";
        for (int i = 0; i < 4; i++) {
          myServos[i] .write(servoPositions[i]);

    And my send serial actor now has:

     "A" P1 "B" P2 "C" P3 "D" P4 "|\r"

    It works, but so slowly that it is not useable. 

    Maybe @mark (help...sorry to tag you), or anyone else can provide a better way to do this? I have done communication the other way a lot, Arduino to Isadora, but not this way, I see some references to posts on the old forum, but no examples or posts that are relevant

  • Tech Staff


    can you post the Isadora file you are suing to send the strings?
    I can't imagine why it would be limited in speed. The string is much shorter than a universe of dmx, and that is easy sent at 40hz.

  • @dusx I am assuming I have made a fundamental error in my approach to solving this, but here is the patch.Isasdora 4 servos.izz

  • Tech Staff


    I don't see any reason that it shouldn't be able to run much faster.
    The Serial send is very simple.
    The Arduino code isn't running any large loops or any thing.

    Are the Baud rates matched?

  • @dusx yes, I tried a lot of baud rates (always matching). Looking at the serial monitor I. Isadora they dont send fast either. I'll try with raw serial tomorrow.

  • Tech Staff

    Hmmm interesting. I just did a project with controlling Servo's using Isadora, personally I use OSC to make the communication between both. It makes no sense that Isadora has a limit on the speed of the Serial output, your code is correct.

  • Beta Gold

    Did you try to control servo's from IDE Arduino directly? Do they behave like they used to do? Maybe the problem is there.

  • @barneybroomer All servos work fine without Isadora

  • @dusx I think there is a problem with the serial send function in Isadora, not sure. I just made the same structure with openframeworks, the same Arduino and same servos and pins etc and it works perfectly. Also just sending a string a cutting it up the same way on the Arduino.

    I have marginally better results with send raw serial, but still not at all usable, massive delays and commands seem to queue.

    This is for a class, so now I need to run an intermediate app and get OSC from Isadora.

    It would be great if someone else could test this, or suggest another way to send multiple values and verify that the send serial is functioning, before I go for a bug report. To me it seems there is something wrong with the serial sending, like it is sending a really huge buffer that is pre allocated and takes ages to send and receive.

  • @juriaan I would love to use OSC but I am looking at a pile of arduino UNO's so no joy.

  • Beta Platinum

    @fred said:

    a problem with the serial send function in Isadora

     Hi @Fred,

    I have just fired up an Arduino Micro with a PMW 12v relay plus a 3v infrared remote, I had no problem communicating to both at the same time running a pulse generator at 30 hz through a sequential trigger to switch the relay and a pulse generator at 5 hz switching the remote. I did not see any issues with the Send Serial Data in the patch setup. 

  • @bonemap can you send me your patch and Arduino code to test here? I did not have trouble when using single parameters with the send serial but only with multiple parameters on a send serial.

  • Beta Platinum

    @fred said:

    send me your patch and Arduino code

    Here it is, but be aware that the code and the patch are not well annotated.

    Arduino-Isadora-Relay-Fan-test.zip (apologies I uploaded the wrong files - these are a match)

  • @bonemap Cheers, I just took a look, and I also had no trouble sending single characters as you are doing in this example, the issue I am getting is sending more than that, I need to control 4 servos so I have to send 4 different kinds of messages, that should be readable as strings and then split them out at the other end. I make a string like this (using either send serial or send raw serial) A<intvalA>B<intvalB>C<intvalC>D<intvalD>| where <intvalN> are integers (without using the :C delimiter in the send serial so they are sent as ascii), or just using the text formater and creating a string and sending with send Raw Serial.

    Either way the messages are received properly but with a lot of delay and not reliably. As I said, the simple versions, just sending a char to switch a Boolean seems to work fine, but more than that gives issues.

    Sending the same strings from an application I wrote myself works fine and is very responsive, so either I am misunderstanding how the formatting in the send serial actor works, or there is an issue. It would still be great if someone can test something closer to what I am doing.

  • Beta Platinum

    @fred said:

    great if someone can test something closer to what I am doing

     Yep! well my other projects use NodeMCU and OSC, have not used longer strings through the Send Serial Data modules that I can recall. I hope you can work it out.

    best wishes


  • @bonemap yes I much prefer to use other protocols but this should work, and it is for teaching....it is easier to keep everything in one place for beginner students.

    At any rate, here is the Isadora patch and the arduino file in case anyone has the time to take a look.Isadora-Arduino serial version _not working.zip

  • Tech Staff

    Will hook up an Arduino and give it a shot when I get back from work.

  • @juriaan @bonemap

    I found out what the issue is. Arduino read as string is very slow and takes 2.5 seconds to resolve. I have a version now that reads byte by byte and it works great. I have attached the Arduino and Isadora files here.Isadora-Arduino serial version _WORKING!.zip

  • Tech Staff


    Good to hear.. I was actually going thru your code to debug this last night and felt it was on the processing side but couldn't be sure yet.