Need some help getting a DC Motorized Fader to be more responsive with MIDI

It still has a tendency to lose the incoming signal from my DAW, which causes the fader to jump down.

If there's some way to get the motorized fader up to full speed (right now it's at less than half) that would be really great too. The problem is that when I set it to 255, it tends to jump around whatever position it's supposed to be in.

I added a 100pf Capacitor between the "Touch" pin (A0) and ground, as recommended in the capacitiveSensor library manual

It might be a bit more stable, but it doesn't seem too noticeable. I didn't have any lower values to test with, so I left this one in

Hoping that someone with some experience with MIDI and motorized faders can chime in.

Perhaps @PieterP?

I'm afraid I can't help with this right now, I'll see what I can do in ~3 weeks.

What is the motor power supply? Details please. The L298 has very high voltage drop and you may not be providing enough voltage at the motor.

I'm using a 9v right now - From what I read the L298N has a 2 volts dropped from the power supply source, so that means that I'm sending 7v into it.

I'll look for a 12v power supply, that way I'm sending the full voltage (10v) to the motor

If I was writing this code…
I’d be using the concept of ‘where am I now’ (currentPosition), and ‘where do I want to be’ (targetPosition)…

Then using millis() timing in loop(), I’d let the code run as fast as it wants to bring those two numbers together without any ‘thinking’.

It’s also easy to modify your target on the fly, the motor control function will chase the new value.

As you understand this, you can tweak the timing of the motor calls to reduce the speed when needed.

A 9V what? Power supply? Battery? Motor has a stall rating of 800ma. What can your source provide?

Details, please. We're not clairvoyant.

Hi,

I'm using a 9v 'negative tip' power supply with a 1700mA rating.

I just tried switching to a 12v power supply with 1000mA, but I found that my motor acted quite a bit more erratically (jumping around values and sometimes it would shoot all the way up or all the way down).

There are quite a few more bugs to work out as well, but for this thread I'll stick to trying to get that motor to work out smoothly.

Here's the latest version of the code - Not much has changed. I'm really stumped as to why my motor is acting so crazy with the MIDI data that is coming in from Ableton. I'm wanting to see my motor respond to the track volume in Ableton. It does respond, but isn't stable at all, jumping all around and sometimes losing the value set by 'sensorValue'. Sometimes I have to completely reset my Arduino in order to get it to function again. Any ideas? Maybe I just need to upgrade to shielded wires, rather than the basic jumper wires?

#include <AltSoftSerial.h>
#include <CapacitiveSensor.h>
#include <MIDI.h>
AltSoftSerial midiSerial;

#define RXPIN 8
#define TXPIN 1
const int dir1PinA = 5;
const int dir2PinA = 6;
int faderValue = analogRead(A0);
int velocityIn;
byte motorSpeed = 100; // Raise if the fader is too slow (0-255)
byte minimumCp = 200; // Raise if the fader is too sensitive (0-1023)
byte tolerance = 10; // Raise if the fader is too shaky (0-1023)

CapacitiveSensor cs_7_2 = CapacitiveSensor(7, 2);
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  cs_7_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
  midiSerial.begin(31250);
  while (!Serial);
  pinMode(dir1PinA, OUTPUT);
  pinMode(dir2PinA, OUTPUT);
  analogRead(faderValue);
  analogWrite(3, motorSpeed);
  MIDI.begin(MIDI_CHANNEL_OMNI); }

void loop() {
  int faderPos = analogRead(A0);
  int faderMIDI = faderPos / 8;
  while ( midiSerial.available() > 0 ) {
    int commandByte = midiSerial.read();
    int noteByte = midiSerial.read();
    int velocityByte = midiSerial.read();
    midiSerial.write( commandByte);
    midiSerial.write( noteByte);
    midiSerial.write( velocityByte);
    velocityIn = velocityByte * 8; }

  { long totalCp =  cs_7_2.capacitiveSensor(30);
    if (totalCp <= minimumCp) { // Not Touching Fader
      motorControl(); }
    else {
      MIDI.sendControlChange(36, faderMIDI, 16); // Pitch: 36, Data: Controlled by fader Channel: 16)
      stopMotor();} } }

void motorControl() {
  int sensorValue = analogRead(A0);
  
  if (sensorValue <= velocityIn - tolerance) {
    moveMotorUp(); }
  if (sensorValue >= velocityIn + tolerance) {
    moveMotorDown(); }
  if (sensorValue == velocityIn) {
    stopMotor(); } }

void moveMotorUp() {
  digitalWrite(dir1PinA, LOW);
  digitalWrite(dir2PinA, HIGH); }

void moveMotorDown() {
  digitalWrite(dir1PinA, HIGH);
  digitalWrite(dir2PinA, LOW); }

void stopMotor() {
  digitalWrite(dir1PinA, LOW);
  digitalWrite(dir2PinA, LOW); }

Edit 1: Forgot to add the code to my initial post.

I'll try rewriting the program with this in mind.

I think that adding some kind of motor acceleration is going to be necessary with this.

I appreciate everyone's responses. I'll try to direct some users that have posted videos of their successful motorized fader arduino projects (there aren't many of them out there). Hopefully they can lend some extra experience/examples.

I've looked at this code for hours, and I can't intuitively think of any way to make it respond better.

Edit 1: Added quote to text

It's also worth mentioning that in Ableton Live 9, I've got my latency set to 256mS.

Digital tracks/plugins typically run pretty smoothly at this rate, so I don't think that the issue is with my communication with Ableton being slow, but I'll experiment with this value as well, and post if I find anything good.

For reference, here's a video of someone who has done an incredible job making this project work.

They aren't using an arduino, but the concept is identical.

After taking another close look at the video above, I see that he's using 2 decoupling capacitors in front of his IC chips.

I didn't do this to my circuit, but I will try adding a .1uF ceramic capacitor between the ground and vcc pins (I believe those are pins 5 and 8 on the 6N138).

Here's a datasheet for this IC chip:

Also, I just saw that I had the regulated 5v power coming from the L298N plugged into my arduino's 5v pin, rather than Vin... Whoops.

Added a .1uF Polypropylene capacitor (400v) right next to the 6N138 chip between pins 5 and 8, as well as a 4.7k resistor between pin 7 and ground.

I might try adding a 10uF 25v electrolytic into the circuit to act as a coupling capacitor, though I'm not entirely sure where I'm supposed to add this in the circuit (does it just go to ground and positive like the decoupling capacitor?)

It's working better now, though it still has a seemingly intermittent input connection. It's definitely not from a loose wire or jumper, so I expect that the jumpiness might be coming from electrical noise or maybe something I'm missing in my code.

Hoping someone can chime in with an idea as to why this might be happening (or if I can better describe the situation, if it seems confusing as is).

Thanks again for the help,

  • Zach

Found a couple of interesting articles regarding this project:

Some suggestions that I found from some older motorized fader users are to use PID instead of PWM for motor control. The L298N uses PWM (though I didn't have any speed adjustments in my code)

I think I'll try replacing the L298N with a PID driver. Might make a difference

Another suggestion by one of the pros (I think he works at Abbey Road?) that I'd be interested in trying:

"Very easy in analog, with an opamp comparing the voltage from the servo track with the control voltage. The opamp needs be buffered for driving the motor.
When I did that for the BVE option on the Soundcraft 200B, I thought it would be tough to nail it, but it turned to be a piece of cake, worked right out. You just have to adjust the closed-loop gain to optimize the hysteresis, then there is no stability issue. Taking advantage of mechanical friction is key."

Hi,

PID is a process of speed control, you will find that there are PID libraries for Arduino, you will still need the motor driver to control the current to the motor.
Although I would be changing the dinosaur 298 for a more efficient MOSFET motor driver.

Tom... :smiley: :+1: :coffee: :australia:

I'll check out the PID libraries and Mosfet drivers. Any suggestions?

I'm still getting so much bugginess from this project, mostly from the MIDI data that is coming in from Ableton. The biggest issue right now (other than the complete inability to get my motor to respond properly to incoming MIDI data) is that when I select a different track in Ableton, my fader jumps down in small intervals as I scroll through my tracks.

Really, anytime I click anything in my DAW, the motor reacts to it in some way, which makes it impossible to do anything productive.

I'll keep working at it. Once I figure it out, I'll try to build a "Motorized Fader" library that other people can use in the future.

Hi,
Just to be sure, have you got some code that JUST controls the fader motors with PID, using a potentiometer as the position command and not any MIDI data.

Just a simple bit of code to prove you have PID control over the motors.

Lets see if the problem is there or closer to the input.
You are in troubleshooting mode now and need to check each of the input and output functions.

How did you tune your PID parameters in the first place?

Tom... :smiley: :+1: :coffee: :australia: