usbmot


This device connects to a computer’s usb port and controls two small electric motors using the L293D. The atmega microcontroller uses the firmware-only USB driver from objective development.

Device description

The usbmot device controls up to two small motors, 600 mA current each, 1.2 A peak each, with an atmel atmega microcontroller connected to some host device via USB. The speed of the motors can be controlled with PWM.

Compiling

Both firmware and host software are in the software package at the end of this page. In order to recompile the firmware, you will need an avr build chain (for example avr-gcc and avrdude), which you probably have if you found this page. To compile the host software, you will need a c++-compiler and the qt development package.

To compile the firmware, change into the firmware folder. Then edit the makefile and adjust device type and programmer. In order to remake the hex file, type “make hex”, and to transfer it to the device, type “make flash” (jumper 1-1 needs to be set).

To compile the host software, change into the qusbmot folder. You will need qt and libusb with their respective tools and header files to successfully compile. If both are properly installed, typing “qmake && make” should compile the program, which can then be executed by typing “./qusbmot”.

Usable AVR Microcontrollers

So far I’ve used this board only with an atmega 168. Due to pin compatibility, it should work with at least an atmega 8, 48, 88, 168. Since 12 MHz speed are needed, the low-voltage versions will not work. The firmware size is about 2 kiB, so all are a bit oversized, but in low quantities this is no problem.

USBAsp roots

The PCB is based on the USBAsp Layout. It can still be used as a programmer, however the USBAsp Firmware has to be modified since I changed the USB port and pins to use the output compare pins for PWM.

Jumper description

  • JP 1-1: Self programming: Needs to be set in order to program the device, and must not be set if the device is operating. Sorry, this is a bit inconvenient, a residue of the usbasp roots.
  • JP 1-2: Programmer Power: Powers the device logic from the Programmers power source.
  • JP 5: coupled power: Connects the motor and logic voltages. Might work for really small motors(take care that the current of the motor is much higher when under heavy load) or strong USB power sources.

Two red LEDs hack

When all that separated my board from completion were the two 3V6 Z-diodes, I asked for help in the mikrocontroller.net – chat, and Loetmichel told me the 3.6 V Zener diodes can be replaced by 2 red LEDs each. If incorporated into the PCB, this might even look really nice, and add some information.

Free pins

in the pcb, some of the atmega’s pins are connected to pinheads, so the board can be extended. I’ve tested a rather crude servo control for PC2…PC5, but unfortunately, if there is activity on the usb bus, the timing will get disturbed and the servos will move without being told so. I guess one could use the two 8-bit timers with their pwm pins to avoid being disturbed by the high-level usb interrupt, maybe in the next version. If however you can live with a bad servo control, try the “trunk” package.

Board problems

  • JP 5 is too close to the power connector.
  • The L293D is a bit old and can only power rather small motors. There are some nice automotive ICs, but unfortunately, those chips aren’t that easily available. Another Problem of the L293D is the low allowed pwm frequency – with 5 kHz in a region that is acoustically displeasing.
  • The holes for screws are placed randomly.
  • Setting the jumpers for programming is not that comfortable. I guess I will use a USB bootloader for the next version, saves some wires, too
  • Probably a lot more.

License and warnings

The software for both the microcontroller and the host is available under the terms of the GPL, in the hope that it might be useful for someone out there. In Addition to the terms of the GPL, obdev, who provide the firmware-only usb driver, kindly ask and require additional terms that especially apply as long as the shared obdev vid/pid pair is used.

The atmega, especially if powered by 5 Volts as in this device, cannot comply to the electrical part of the USB standard. Nevertheless, it works well with a large range of computers. However, there is no guarantee that it will not destroy your USB controller or your entire computer, so keep in mind the last sentence of the GPL: This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.


filetype usbmot_software.tar.bz2 (723.15 kiB, 2008-11-03)
filetype usbmot_trunk.tar.bz2 (759.19 kiB, 2008-11-21)
filetype usbmot_schematic.pdf (93.99 kiB, 2008-10-29)
filetype usbmot_pcb.pdf (194.58 kiB, 2008-10-29)
filetype usbmot_eagle_pcb.tar.bz2 (73.22 kiB, 2008-11-21)

This entry was posted in Electronics and tagged , , . Bookmark the permalink.

4 Responses to usbmot

  1. paryl says:

    Andreas, this is awesome stuff. Exactly what I’ve been looking for! I’ve got it working using your example programs, but what I really need is a python version.

    Have you managed to control it using python? I’ve been trying for a few weeks now using pyusb, but nothing I do lets me communicate. I suspect it’s an issue with not knowing the proper endpoints, or something to do with the data I’m sending. I consistently get “error submitting URB: No such file or directory”.

    I’d love some hints if you have any to give…

  2. Andreas Goelzer says:

    Thanks a lot, nice to hear it helps you :)

    I don’t know how pyusb works, and this control-endpoint stuff is not exactly comfortable. But with vusb, options are limited. I’m planning to redo this with an at90usb162, that could then have a nice serial interface and work in more environments.

    If you just want to control this device from python, you can have python call the commandline-program with os.system(“./usbmot-cmd write 1 2000″) or such stuff, but that’s more a hack than a real solution.

    I hope you somehow get it working, good luck :)

  3. Alex says:

    Nice job…

  4. laosoi says:

    Hello Andreas Goelzer,
    Thanks for your project!
    Please tell me how to control 25A, 12V, 3800rpm brushless motor using this project?
    Help me, i want to control high rpm motor using usb!
    Many thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">