How to use a VNH2SP30 DC motor shield with MobiFlight - MobiFlight/MobiFlight-Connector GitHub Wiki

This is a "Monster Moto Shield" by Sparkfun

The board has since been discontinued by Sparkfun, but as it was originally open source hardware design, there are clones around, and I got one from Aliexpress to play with some ideas. You can find plenty ones (also with information about low quality clones that do not work or fail, as usual with these kinds of modules). Search for "VNH2SP30 motor shield for arduino". It mounts as a shield on top of an Arduino Leonardo here without wires, which works with Mobiflight as a Pro Micro, they are essentially the same with just a different board form factor.

image

The board has the ability to run DC motors with pretty high currents, and you can control it with PWM and some data pins to set desired operation (clockwise, counterclockwise, brake, and speed). There are arduino sketches around with test code, but I wanted to just hook the pins into Mobiflight, and possibly control it with data coming from the simulator, because it works with two control pins and PWM for speed control, and one pin to enable/disable the motor altogether.

image

So I flashed the Leonardo with Mobiflight and configured the pins that the shield uses. There are two "direction" pins, one speed control pin, and one enable/disable pin for each motor. You can also read the current sense pin as an analog input to get a reading of the relative current being used by the motor.

Motor 1

Configure these as "Led Output" in Mobiflight:

  • Clockwise signal: 7
  • Counter-clockwise signal: 8
  • PWM speed control: 5
  • Enable: A0

Optionally you can configure this as Analog input:

  • Current sense: A2

Motor 2

Configure these as "Led Output" in Mobiflight:

  • Clockwise input: 4
  • Counter-clockwise input: 9
  • PWM speed control: 6
  • Enable: A1

Optionally you can configure this as Analog input:

  • Current sense: A3

Mobiflight pin configuration

This was easy, I just added each pin into Mobiflight as "Led Output" (except the current sense pin that is analog input, if you want to use that) - and uploaded the configuration.

image

As I was just playing with this, and figured I'd write a wiki page to share the findings until I forget, I didn't do anything fancy with the simulator yet, I simply just used the Mobiflight Transform field to hardcode values to the pins to make the motor run, and used a potentiometer in my existing sim panel to control the motor speed in the 0-255 range.

image

To make a motor run in clockwise direction, set "enable" pin to 1, clockwise pin to 1, counter-clockwise pin to 0, and adjust speed with PWM. To run the motor counter-clockwise, set the CW and CCW pins the other way around.

For some reason my shield only lets me run the motor counter-clockwise, which might be a fault in the shield, but in any case, hopefully this information is useful for someone. I will need to test the other motor output and see what the problem is. In any case, have fun.

image

Some ideas

Naturally DC motors turn quite fast, but if you have some geared motors, or some belt wheel reduction for speed, you could think of some way to do a limit switch that sets the enable pin to 0 if tripped, and then connect a potentiometer to the movement, and see if you can build an autothrottle, or even control centering with braking and careful adjustment of direction and force, though it might require a bit faster control loop than what Mobiflight is designed for. Maybe worth a shot anyway.