Alternate Firmware for the Motor Shield



  • I asked around a little, and one of my friends wrote an alternate implementation of the firmware for the motor shield for the D1 Mini. It's written by hand, without using auto-generated code, and in my experience it works much better -- in particular, it doesn't crash when it receives a wrong command or when it times out. I still need to do some more testing, and I'm sure we will find some bugs, but at least the worst bugs from the original firmware are fixed.
    The firmware is backward-compatible with the original, in the sense that you can use the same libraries and the same code with it.
    I wrote the instructions for flashing it on the original WeMos shields here: https://hackaday.io/project/18439-motor-shield-reprogramming/log/57852-we-have-a-fixed-firmware

    Unfortunately, since the boards are locked, you will need an ST-Link programmer and you will need to solder two wires directly to one of the chips on the shield. Perhaps @wemos could break those (and all other unused pins too) out in the next version of the shield, that would make it much easier.

    I have heard that there are also some clone shields that are sold by other manufacturers than WeMos, and that those come un-programmed. If that is true, you should be able to flash them over the serial pins that are broken out, without a special programmer and without soldering, using the stm32flash utility. I have never had such a shield in my hands, though, so I can't confirm this.



  • Update: I have now figured out how to reprogram the shields without the need of any soldering or a programmer. All you need is a serial to usb adapter: https://hackaday.io/project/18439-motor-shield-reprogramming/log/57855-reprogramming-without-soldering



  • @deshipu ,
    unfortunately I can only upvote once !

    Thanks man for this effort
    7th Dwarf



  • Hello @deshipu ,

    I followed your explanation this morning and re-programmed successfully one of my motor shields. Haven't tested it with real software, yet. But the I2C scanner runs without problems, which is at least a very good indicator. Thanks again for your help!

    One comment: Wemos offers this breakout board for the CH340, which is sold here.

    If you set this board to work with 3.3V and RTS on the R/C pin you would expect that it works immediately as programming adapter for the motor shield. Under Linux this is not the case! Very likely there is an issue with the parity support in the Linux driver for CH340/CH341. Finally I used a FTDI adapter. I have not tested it under windows or on a mac.
    7th Dwarf



  • Yes, I used that USB2TTL board initially too, as it had exactly the right pinout, and I did assume that it sets the RTS pin high -- that's what made me think that locked chips can't be programmed over serial, and made me go this whole roundabout route with soldering the wires and using an ST-Link programmer. In the end, it made me waste a few weeks, but I did learn a bit about programming STM32 chips.

    Then I tried with a different usb2ttl and with the RTS pin held high with a wire -- just because I was too lazy to search for this particular usb2ttl in my drawer -- and it suddenly just worked.



  • I wonder if someone got this shield working with nodemcu? I've tried for some hours now, but had no louck to get it work.
    Does someone know how to really use the shield directly using i2c? Even in the new Firmware I don't see any documentation about that and this makes it hard to understand how it works.

    Maybe someone already did this, I'd be really happy to know how to.

    --wolfgang



  • @1mannlan ,

    if you're talking about nodemcu, do you mean implementation for lua?

    7th Dwarf



  • I wrote a library for MicroPython, it's a bit easier to read that code than the original Arduino library: https://bitbucket.org/thesheep/micropython-d1motor/src/tip/d1motor.py



  • @Seventh-Dwarf
    Yes, I tried to do it on a d1 mini.
    I just wanted to set the motor to 100% for a starting point, but even that did not work. Maybe I just need more experience for that, but from what i've read the chip is not really handy to communicate with :).

    What i tried so far was:

    *id = 0
    sda = 2
    scl = 1

    -- initialize i2c, set pin1 as sda, set pin2 as scl
    i2c.setup(id, sda, scl, i2c.SLOW)
    i2c.start(id)
    i2c.address(id, 0x30, i2c.TRANSMITTER)
    i2c.write(0,16) --16 dec 0x10 hex
    i2c.write(0,2) --2 dec 0x02 hex
    i2c.write(0,39) --39 dec 0x27 hex
    i2c.write(0,10000) --10000 dec 0x27, 0x10 hex
    i2c.stop(id)*

    --wolfgang



  • @1mannlan ,

    if your are using the standard configuration for the i2c pins try using the following:

    id =0 ;
    sda = 4;
    scl = 5 ;
    

    Why don't you use the Wemos motor shield library?
    7Th Dwarf



  • @1mannlan said in Alternate Firmware for the Motor Shield:

    i2c.write(0,2) --2 dec 0x02 hex

    I think this line is spurious. The motor ID should be or-ed with the 0x10 in the previous line, so that you get 0x10 for the first motor, and 0x11 for the second.



  • @Seventh-Dwarf NodeMCU uses the "digital pin" numbers (same as printed on the board), not the GPIO numbers like all the rest of the world. In fact, that's where the whole renumbering kerfuffle originated.



  • @deshipu .

    yeah, you're right. Just forgot that's nodemcu and not arduino. Thanks for your correction.
    7th Dwarf



  • @deshipu
    I flashed the cusotm motor shield firmware, but I still fell like it has some bugs.
    It is crashing no longer, but sometimes, if I only send one PWM Command, nothing happens. If I send it a second time it works as expected.

    Did also experienced such effects?



  • @1mannlan I didn't have such problems, but I'm not using it in anything serious yet. Too many projects.

    If you have an example minimal program that demonstrates the issue, that would be helpful.


Log in to reply
 

Looks like your connection to WEMOS Forum was lost, please wait while we try to reconnect.