sparkfun/pxt-moto-bit

can't control motors independently

Closed this issue · 2 comments

shawt commented

The code below causes BOTH left and right motors to spin. Switching to LEFT produces the same result. It seems that whichever motor I select, both motors spin.

`input.onButtonPressed(Button.A, function () {
motobit.enable(MotorPower.On)
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 50)
basic.pause(2000)
motobit.enable(MotorPower.Off)
})
basic.forever(function () {

})`

shawt commented

Update...
The code works as you would expect it to after I removed all power from the moto:bit hardware and reconnected power.
But... it only works once after power-up.
Once I have turned one motor on, if I try to turn on the other motor, the first motor also comes on. It is not clear how the i2c commands are working to control the H-Bridge, but it seems like something gets "stuck."

shawt commented

Update #2...
disabling the motors is not the correct way to turn them off. You need to send the command to set the speed to 0. Once this is done, the motor stops turning and stays stopped until it is given a new speed and direction command over i2C.

Seems to be functioning as expected now, so I will close the issue.