I am using a MIDI Control Change to move a servo connected to a Leonardo. It works! However, if I move the control too fast the MIDI connection drops and the Leonardo is unresponsive. I have a commercial animatronic board (USB-->MIDI-->MIDI Servo Controller that is working and can keep up with the same setup.
I would like to confirm that Leonardo performance could be the issue. If that's the case I'll try a SAMD21 board when it arrives in the few days.
Here's my code:
#include <Servo.h>
#include "MIDIUSB.h"
Servo myservo;
void setup() {
Serial.begin(115200);
myservo.attach(9);
}
void loop() {
midiEventPacket_t rx;
do {
rx = MidiUSB.read();
if (rx.header != 0) {
int val = map(rx.byte3, 0, 127, 0, 180);
myservo.write(val);
}
} while (rx.header != 0);
}
The Leonardo does NOT freeze up if I remove the Servo Library and control an LED. So perhaps there is a timer conflict between the MIDIUSB and SERVO libraries?
I have an I2C servo shield that I could use as a workaround. Will do more tests.
I am powering the steppers and servos using an ATX supply. I got it working just fine by not using the Arduino Servo library. I have tested servos + steppers + neopixels simultaneously without any problems using some Adafruit PWM and Motors shields:
My initial code was just a Leonardo using the Arduino Servo library. The Leonardo seizes up after a few seconds. I figured there is a conflict with the libraries so I tried with i2c interfaces and later with Neopixels. They work just fine.
I went back to the beginning and tested with the Arduino Servo library again and it does work. As you say, it was probably a power issue. The servo I was using was pulling far too much current than normal. So now all works just fine with the Arduino servo library and the i2c shields.