micro:bit Kitronik Motor Driver 5698

Issue #476 resolved
Ludo Joris created an issue

micro:bit + Kitronik Motor Driver Board 5698 - pin 0 problem

Comments (18)

  1. Ludo Joris reporter

    micro:bit V1 + Kitronik Motor Driver Board 5698 + 2 cheap dc motors + MicroBlocks v1.2.46 (Firmware v210) on Fedora Linux 38.

    See page 2 of the Kitronik Motor Driver datasheet. The board has an DRV8833 driver chip. Simple to program.

    pin 8 and pin 12 do work - can spin motor in two directions

    pin 0 and pin 16 does not work - can spin motor only in one direction (is pin 0 the problem?)

    Oh, it works with MicroPython, MakeCode.

    I’ll be helping out with the MicroBlocks workshop at Fosdem 2024 Sunday morining.

    Ludo (CoderDojo Coach)

  2. John Maloney repo owner

    Thanks for the details. Could you try this script:

    scriptImage98167.png

    It should spin the motor for 1.5 seconds in one direction, wait 1.5 seconds, then spin it in the other direction for 1.5 seconds.

    If the motor only works in one direction, which pin settings are the one that make it do that?

    Does power-cycling the micro:bit change the behavior?

    Looking forward to meeting you at FOSDEM!

  3. Ludo Joris reporter

    My reply from 3 hours ago seems lost.

    Ran yor script: both motors roate full speed in both directions.

    But I wanted to use PWM to regulate the motor speed. Set pin block does PWM.

    Button B works: motor has 2.08 V (via pin 0), and 0.18 V (via pin 16)

    Button A does not work: both are 0.16 V to the motor

    micro;bit technical reference says you can do PWM on pin 16.

  4. John Maloney repo owner

    Yep, you should be able to do PWM on pin 16. But it may help to set pin 0 to low with the "set digital" block:

    allScripts2767550.png

    Not sure if it will help, but worth a try.

    There is a potential interaction between motor control and the Tone library for music output -- which defaults to outputting to pin 0 on the micro:bit V1. If you've done any sound output on pin 0, power cycle the board and test these blocks in a new project without having run any Tone blocks. (There is a similar potential interaction with servo blocks on pin 0, so avoid that library, too, until we get this issue figured out.)

  5. Ludo Joris reporter

    I should reply here, not to the email.

    With the set digital blocks both motors now spin at reduced speed in both directions.

    Thank you for providing a solution.

  6. John Maloney repo owner

    Glad that worked!

    Hardware can be surprising. One would think a 0 PWM signal would be the same a digital output of LOW but apparently not in this case. It may be that the voltage is not quite zero with a 0 PWM output (in fact, you measured 0.16v) and that small difference may matter to the transistors in the motor controller. Pin 0 on the micro:bit has what is called a "weak pullup" resistor so that it can be used as a touch sensor, whereas the other motor control pins on your board do not, so that could also explain the different behavior for that pin.

    In any case, great that there is an easy solution!

    Although people get emails about any issues they are tracking, as far as I can tell, any replies those emails are silently deleted. They don't appear here and I never see them. Thus, as you discovered, you need to post any responses or comments here, on the issue tracker.

  7. Ludo Joris reporter

    Sorry, new test code:

    Reset micro:bit (press micro:bit reset button),

    press button A : motor A spins in both directions,

    then presss button B, motor B spins in only one direction.

    Reset micro:bit (press micro:bit reset button),

    press button B : motor B spins in both directions,

    then presss button A, motor A spins in only one direction.

  8. Ludo Joris reporter

    It gets more weird.

    This also happens when I go all digital (no more set pin, but set digital pin everywhere).

    And this really confuses me:

    Press buttons A and B at the same time: both motors do not spin, nothing happens.

    And even more weird, press A first or B first:

    Now, both motors spin in both directions, every time.

  9. John Maloney repo owner

    Press buttons A and B at the same time: both motors do not spin, nothing happens.

    That's because pressing A and B at the same time runs the A+B button script if there is one; it does not run the A script or the B script.

    But your other experiment with PWM surprises me. It is behaving as though it can only run PWM on three pins, even if you stop PWM on one of those pins and try to start it on another. I will need to dig into the code for the Arduino library that we use for PWM to figure out why that is happening.

    If you have (or can borrow) a micro:bit v2, I'd be curious to know if it behaves the same way.

    Here's another thing to try:

    scriptImage110868.png

    Does the motor spin in both directions? Are the speeds slighly different?

    The idea is to always use pin 8 for PWM speed control but change the polarity of pin 12 to change the direction. When pin 12 is low, the positive part of the PWM signal will determine the power (larger numbers give more power). When pin 12 is high, the negative part of the PWM signal will determine power (lower numbers give more power: 0 is max power, 1023 is zero power). To make the motor stop you would set the PWM to 0 and pin 12 to low.

    If this works you will only need two PWM channels to control the speed of both motors.

  10. Ludo Joris reporter

    Sorry about the A+B. MicroPython can’t do that, so I assumed wrong.

    Ok, replaced the set pin blocks by set digital pin blocks.

    Replaced the V1 by a V2.

    Started MicroBlocks, Connect, open ubp program: one rotates in both directions, the other in only one. No matter which one goes first.

    Press reset button. Now it works: press A than B or B then A, both motors run in both directions. Keeps working from now on.

    Until :

    Copied the micro:bit vm file to the micro:bit: $ cp vm_microbit-universal.hex /run/media/lujo/MICROBIT/

    Started MicroBlocks, Connect, open ubp program: the problem is back.

    Seems to fail after copying the VM.

    Until I press the reset button and everything works again.

  11. John Maloney repo owner

    Very good detective work on your part.

    Had you run MicroPython or MakeCode in between the two tests with MicroBlocks?

    I once had an issue involving the accelerometer with similar symptoms. It turned out to that MakeCode had changed some settings on the accelerometer chip, even when the MakeCode program did not actually use the accelerometer. Resetting (or maybe power-cycling) would reset the accelerometer and make it work again.

    For a long time I thought the firmware install process was messing up the accelerometer because the problem always showed up right after re-installing the MicroBlocks firmware. But that was just coincidence; the firmware installs were always done after having just run MakeCode. (This was in a workshop where participants were trying both systems to compare them.)

    So, just wondering if this might be a similar issue.

    Does the micro:bit v1 ever run both motors to run in both directions with PWM under MicroBlocks? It sounds as though the motors work as expects with a micro:bit v2 (after you've reset it).

    Maybe we can look at this together during one of the MicroBlocks workshops at FOSDEM.

  12. Ludo Joris reporter

    In short: MicroPython and MakeCode on V1 and V2 no problem, MicroBlocks fails after uploading VM works after reset button.

    OK, hope to be there on Sunday.

    I’m going to do something else now: exploring MicroBlocks on RPi Pico and Pico W for a demo this Saturday in our local dojo.

    Thank you

  13. Ludo Joris reporter

    I’m giving up. Now found that running tests in different order do not always give the same result.

    Sorry, but for me it stops here.

  14. John Maloney repo owner

    Sorry we did not get it to work for you. I think we might be close to a solution, but I understand your need to move on.

    I'll mark this as resolved, but feel free to add additional comments.

  15. Log in to comment