Use free pins with only one motor

Hi,
i use a G2 18v22 Shield with only one motor. How can i use the M2 pins for other uses? I tried to remap all M2 pins to NaN. M1 still works normally, but makes funny noises when moving so something is different.

DualG2HighPowerMotorShield18v22 md(2,7,9,6,A0,NAN,NAN,NAN,NAN,NAN);

Or can i just create with default mapping and use the pins normally for other uses if i never call M2 through the library?

Hello.

Using NAN will likely be interpreted as 0 (so you will be setting all of those pin assignments to 0). Unfortunately, with how the library is currently written, there’s no way to tell it not to use some of the pins.

It might be fine to just not calling the M2 functions as you suggested; however, you should consider that when it’s initialized, some of those pins will still be set to outputs, which might be problematic depending on what you’re using them for.

As for the noise you’re hearing, I suspect it is the PWM frequency. The library only uses 20kHz (which is above the audible range) if both PWM pins are left to the default values.

You might try using the same pins for M1 and M2 except leaving the default M2PWM pin (which means not being able to use that pin in your application). Otherwise, you will probably have to modify the library.

Please note that if you’re mounting the driver on an Arduino as a shield, those pins will still be physically connected to the driver. So in that case, you should also cut the traces as described in the “Remapping the Arduino connections” section of the Dual G2 High-Power Motor Driver Shield user’s guide so you can use them freely for other purposes.

Brandon

Brilliant!

I just tested it and you were 100% correct. By using

DualG2HighPowerMotorShield18v22 md(2,7,9,6,A0, 2,7,10,6,A0);

i can use A1 normally after cutting the trace. The pwm noise is gone. Thank you very much!

Hannes

1 Like