Programming




Once I had the PCB milled and soldered I pluged it into the computer. I have to say I was a bit sceptical that it could work at first time, but at least the red light turned on (that means the board has power but it's not ready to be programmed). So far, that was what was supposed to happen as it had to be booted before it's first used.
With ATMEGAU32U that can be done directly with the USB (D+ & D-), there's no need to do it with MISO - MOSI as with ATtiny, for instance.

fabmodules

Thanks again to Nicolas Saugnier and its USB2AX, I followed all the instructions in his website, to program the firmware. All the process is explainedhere .
First the computer basically recognizes the device as an ATMEGA32U2, and put it in DFU mode. That's what happens when you connect any microncotroller like this to a PC

fabmodules

Here we can see how after installing the driver, the microcontroller was well recognized.

fabmodules

After this, you should run the USB2AX_updater tool available here and flash the microcontroller with the new firmware. Once this is done the computer will recognize the device as an USB2AX, although it will still keep the red light on. I have to say I was a bit struggled with this until I figured out the next step.

fabmodules

As per Nicolas' website, before the first use, you need to install the USB2AX.inf driver file available here.

fabmodules

To install it just plug the device in the computer, open the Device Manager and update the driver software with this file.

fabmodules

Once done it the computer will recognize the device and its port, ready to read and write information

fabmodules

If everything went well you should be able to see a green light on now, instead of the red one we had before.

fabmodules

This is the how the final wiring should look like, from one side the PCB is connected to the PC trough serial port. On the other side it is connected to a powered bus, that sends the information to the motors connected.

fabmodules

Here you can see the first trials I did with the Robotis software, controlling the motors with FAB-USB2AX. I was really happy I have to say :)


pass: fab

It was time to see some action and make my objects move. I did a lot of research and finally knew about Pypot, which as Open Source project to control robots activated with Dynamixels through Python. It seemed perfect to me. Herethere is their main website with all the information

To install Pypot on Mac it's better you install first HomeBrew, with the following code.
    
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
And then
                   
brew install python
And after that, install Pypot
  
pip install pypot
I used the following functions in PyPot to move my objects through Python and serial port.

Function 1 (download here):

import itertools
import numpy
import time

import pypot.dynamixel


if __name__ == '__main__':
    ports = pypot.dynamixel.get_available_ports()
    print('available ports:', ports)

    if not ports:
        raise IOError('No port available.')

    port = ports[0]
    print('Using the first on the list', port)

    dxl_io = pypot.dynamixel.DxlIO(port)
    print('Connected :)')

    found_ids = dxl_io.scan(range(12))
    print('Found ids:', found_ids)

    ids = found_ids
    dxl_io.enable_torque(ids)

    #move all the motors to 0 position at 50 speed
    dxl_io.set_moving_speed({2: 50})
    dxl_io.set_moving_speed({3: 50})
    dxl_io.set_moving_speed({4: 50})
    dxl_io.set_moving_speed({5: 50})
    dxl_io.set_moving_speed({6: 50})
    dxl_io.set_moving_speed({7: 50})
    dxl_io.set_moving_speed({8: 50})
    dxl_io.set_moving_speed({9: 50})
    dxl_io.set_moving_speed({10: 50})
    dxl_io.set_moving_speed({11: 50})

    dxl_io.set_goal_position({2: 150})
    dxl_io.set_goal_position({3: 150})
    dxl_io.set_goal_position({4: 150})
    dxl_io.set_goal_position({5: 150})
    dxl_io.set_goal_position({6: 150})
    dxl_io.set_goal_position({7: 150})
    dxl_io.set_goal_position({8: 150})
    dxl_io.set_goal_position({9: 150})
    dxl_io.set_goal_position({10: 150})
    dxl_io.set_goal_position({11: 150})
    time.sleep(11)

    # move all the motors to it's function position at 50 speed
    dxl_io.set_moving_speed({2: 50})
    dxl_io.set_moving_speed({3: 50})
    dxl_io.set_moving_speed({4: 50})
    dxl_io.set_moving_speed({5: 50})
    dxl_io.set_moving_speed({6: 50})
    dxl_io.set_moving_speed({7: 50})
    dxl_io.set_moving_speed({8: 50})
    dxl_io.set_moving_speed({9: 50})
    dxl_io.set_moving_speed({10: 50})
    dxl_io.set_moving_speed({11: 50})

    dxl_io.set_goal_position({2: 50})
    dxl_io.set_goal_position({3: 103.5})
    dxl_io.set_goal_position({4: 120})
    dxl_io.set_goal_position({5: 104})
    dxl_io.set_goal_position({6: 47.5})
    dxl_io.set_goal_position({7: -21.5})
    dxl_io.set_goal_position({8: -63.5})
    dxl_io.set_goal_position({9: -92})
    dxl_io.set_goal_position({10: -113.75})
    dxl_io.set_goal_position({11: -121.5})
    time.sleep(5)

    # move all the motors to it's contrary position
    dxl_io.set_goal_position({2: -121.5})
    dxl_io.set_goal_position({3: -113.75})
    dxl_io.set_goal_position({4: -92})
    dxl_io.set_goal_position({5: -63.5})
    dxl_io.set_goal_position({6: -21.5})
    dxl_io.set_goal_position({7: 67.5})
    dxl_io.set_goal_position({8: 104})
    dxl_io.set_goal_position({9: 120})
    dxl_io.set_goal_position({10: 103.5})
    dxl_io.set_goal_position({11: 50})
    time.sleep(5)

    # move all the motors back to 0 position 
    dxl_io.set_goal_position({2: 150})
    dxl_io.set_goal_position({3: 150})
    dxl_io.set_goal_position({4: 150})
    dxl_io.set_goal_position({5: 150})
    dxl_io.set_goal_position({6: 150})
    dxl_io.set_goal_position({7: 150})
    dxl_io.set_goal_position({8: 150})
    dxl_io.set_goal_position({9: 150})
    dxl_io.set_goal_position({10: 150})
    dxl_io.set_goal_position({11: 150})
    time.sleep(11)

Function 2 (download here): :

import itertools
import numpy
import time

import pypot.dynamixel


if __name__ == '__main__':
    ports = pypot.dynamixel.get_available_ports()
    print('available ports:', ports)

    if not ports:
        raise IOError('No port available.')

    port = ports[0]
    print('Using the first on the list', port)

    dxl_io = pypot.dynamixel.DxlIO(port)
    print('Connected :)')

    found_ids = dxl_io.scan(range(12))
    print('Found ids:', found_ids)

    ids = found_ids
    dxl_io.enable_torque(ids)

    #move all the motors to 0 position at 50 speed
    dxl_io.set_moving_speed({2: 50})
    dxl_io.set_moving_speed({3: 50})
    dxl_io.set_moving_speed({4: 50})
    dxl_io.set_moving_speed({5: 50})
    dxl_io.set_moving_speed({6: 50})
    dxl_io.set_moving_speed({7: 50})
    dxl_io.set_moving_speed({8: 50})
    dxl_io.set_moving_speed({9: 50})
    dxl_io.set_moving_speed({10: 50})
    dxl_io.set_moving_speed({11: 50})

    dxl_io.set_goal_position({2: 150})
    dxl_io.set_goal_position({3: 150})
    dxl_io.set_goal_position({4: 150})
    dxl_io.set_goal_position({5: 150})
    dxl_io.set_goal_position({6: 150})
    dxl_io.set_goal_position({7: 150})
    dxl_io.set_goal_position({8: 150})
    dxl_io.set_goal_position({9: 150})
    dxl_io.set_goal_position({10: 150})
    dxl_io.set_goal_position({11: 150})
    time.sleep(11)

    # move all the motors to it's function position at 50 speed
    dxl_io.set_moving_speed({2: 50})
    dxl_io.set_moving_speed({3: 50})
    dxl_io.set_moving_speed({4: 50})
    dxl_io.set_moving_speed({5: 50})
    dxl_io.set_moving_speed({6: 50})
    dxl_io.set_moving_speed({7: 50})
    dxl_io.set_moving_speed({8: 50})
    dxl_io.set_moving_speed({9: 50})
    dxl_io.set_moving_speed({10: 50})
    dxl_io.set_moving_speed({11: 50})

    dxl_io.set_goal_position({2: -79})
    dxl_io.set_goal_position({3: -10})
    dxl_io.set_goal_position({4: 42})
    dxl_io.set_goal_position({5: 75})
    dxl_io.set_goal_position({6: 87.5})
    dxl_io.set_goal_position({7: 87.5})
    dxl_io.set_goal_position({8: 75})
    dxl_io.set_goal_position({9: 42})
    dxl_io.set_goal_position({10: -10})
    dxl_io.set_goal_position({11: -79})
    time.sleep(5)

    # move all the motors to it's contrary position
    dxl_io.set_goal_position({2: 62.5})
    dxl_io.set_goal_position({3: -1.5})
    dxl_io.set_goal_position({4: -49})
    dxl_io.set_goal_position({5: -75})
    dxl_io.set_goal_position({6: -86})
    dxl_io.set_goal_position({7: -86})
    dxl_io.set_goal_position({8: -75})
    dxl_io.set_goal_position({9: -49})
    dxl_io.set_goal_position({10: -1.5})
    dxl_io.set_goal_position({11: 62.5})
    time.sleep(5)

    dxl_io.set_goal_position({2: 150})
    dxl_io.set_goal_position({3: 150})
    dxl_io.set_goal_position({4: 150})
    dxl_io.set_goal_position({5: 150})
    dxl_io.set_goal_position({6: 150})
    dxl_io.set_goal_position({7: 150})
    dxl_io.set_goal_position({8: 150})
    dxl_io.set_goal_position({9: 150})
    dxl_io.set_goal_position({10: 150})
    dxl_io.set_goal_position({11: 150})
    time.sleep(11)

Function 3 (download here):

import itertools
import numpy
import time

import pypot.dynamixel


if __name__ == '__main__':
    ports = pypot.dynamixel.get_available_ports()
    print('available ports:', ports)

    if not ports:
        raise IOError('No port available.')

    port = ports[0]
    print('Using the first on the list', port)

    dxl_io = pypot.dynamixel.DxlIO(port)
    print('Connected :)')

    found_ids = dxl_io.scan(range(12))
    print('Found ids:', found_ids)

    ids = found_ids
    dxl_io.enable_torque(ids)

    #move all the motors to 0 position at 50 speed
    dxl_io.set_moving_speed({2: 50})
    dxl_io.set_moving_speed({3: 50})
    dxl_io.set_moving_speed({4: 50})
    dxl_io.set_moving_speed({5: 50})
    dxl_io.set_moving_speed({6: 50})
    dxl_io.set_moving_speed({7: 50})
    dxl_io.set_moving_speed({8: 50})
    dxl_io.set_moving_speed({9: 50})
    dxl_io.set_moving_speed({10: 50})
    dxl_io.set_moving_speed({11: 50})

    dxl_io.set_goal_position({2: 150})
    dxl_io.set_goal_position({3: 150})
    dxl_io.set_goal_position({4: 150})
    dxl_io.set_goal_position({5: 150})
    dxl_io.set_goal_position({6: 150})
    dxl_io.set_goal_position({7: 150})
    dxl_io.set_goal_position({8: 150})
    dxl_io.set_goal_position({9: 150})
    dxl_io.set_goal_position({10: 150})
    dxl_io.set_goal_position({11: 150})
    time.sleep(11)

    # move all the motors to it's function position at 50 speed
    dxl_io.set_moving_speed({2: 50})
    dxl_io.set_moving_speed({3: 50})
    dxl_io.set_moving_speed({4: 50})
    dxl_io.set_moving_speed({5: 50})
    dxl_io.set_moving_speed({6: 50})
    dxl_io.set_moving_speed({7: 50})
    dxl_io.set_moving_speed({8: 50})
    dxl_io.set_moving_speed({9: 50})
    dxl_io.set_moving_speed({10: 50})
    dxl_io.set_moving_speed({11: 50})

    dxl_io.set_goal_position({2: 112.5})
    dxl_io.set_goal_position({3: 111.5})
    dxl_io.set_goal_position({4: 102.5})
    dxl_io.set_goal_position({5: 87})
    dxl_io.set_goal_position({6: 67.5})
    dxl_io.set_goal_position({7: 53.25})
    dxl_io.set_goal_position({8: 47.75})
    dxl_io.set_goal_position({9: 54.50})
    dxl_io.set_goal_position({10: 77})
    dxl_io.set_goal_position({11: 96.5})
    time.sleep(5)

    # move all the motors to next position
    dxl_io.set_goal_position({2: 112.5})
    dxl_io.set_goal_position({3: 111.5})
    dxl_io.set_goal_position({4: 83.25})
    dxl_io.set_goal_position({5: 65})
    dxl_io.set_goal_position({6: 3})
    dxl_io.set_goal_position({7: -65})
    dxl_io.set_goal_position({8: -105})
    dxl_io.set_goal_position({9: -87})
    dxl_io.set_goal_position({10: -19.5})
    dxl_io.set_goal_position({11: 55.5})
    time.sleep(5)

    # move all the motors to next position
    dxl_io.set_goal_position({2: -33.75})
    dxl_io.set_goal_position({3: -21})
    dxl_io.set_goal_position({4: -22})
    dxl_io.set_goal_position({5: -37.75})
    dxl_io.set_goal_position({6: -65.85})
    dxl_io.set_goal_position({7: -90.5})
    dxl_io.set_goal_position({8: -105})
    dxl_io.set_goal_position({9: -92.75})
    dxl_io.set_goal_position({10: -61.75})
    dxl_io.set_goal_position({11: 27})
    time.sleep(5)

    # move all the motors to next position
    dxl_io.set_goal_position({2: 112.5})
    dxl_io.set_goal_position({3: 111.5})
    dxl_io.set_goal_position({4: 102.5})
    dxl_io.set_goal_position({5: 87})
    dxl_io.set_goal_position({6: 67.5})
    dxl_io.set_goal_position({7: 53.25})
    dxl_io.set_goal_position({8: 47.75})
    dxl_io.set_goal_position({9: 54.50})
    dxl_io.set_goal_position({10: 77})
    dxl_io.set_goal_position({11: 96.5})
    time.sleep(5)

    # move all the motors to next position
    dxl_io.set_goal_position({2: 112.5})
    dxl_io.set_goal_position({3: 111.5})
    dxl_io.set_goal_position({4: 83.25})
    dxl_io.set_goal_position({5: 65})
    dxl_io.set_goal_position({6: 3})
    dxl_io.set_goal_position({7: -65})
    dxl_io.set_goal_position({8: -105})
    dxl_io.set_goal_position({9: -87})
    dxl_io.set_goal_position({10: -19.5})
    dxl_io.set_goal_position({11: 55.5})
    time.sleep(5)

    # move all the motors to next position
    dxl_io.set_goal_position({2: -33.75})
    dxl_io.set_goal_position({3: -21})
    dxl_io.set_goal_position({4: -22})
    dxl_io.set_goal_position({5: -37.75})
    dxl_io.set_goal_position({6: -65.85})
    dxl_io.set_goal_position({7: -90.5})
    dxl_io.set_goal_position({8: -105})
    dxl_io.set_goal_position({9: -92.75})
    dxl_io.set_goal_position({10: -61.75})
    dxl_io.set_goal_position({11: 27})
    time.sleep(5)

    # move all the motors back to 0 position
    dxl_io.set_moving_speed({2: 50})
    dxl_io.set_moving_speed({3: 50})
    dxl_io.set_moving_speed({4: 50})
    dxl_io.set_moving_speed({5: 50})
    dxl_io.set_moving_speed({6: 50})
    dxl_io.set_moving_speed({7: 50})
    dxl_io.set_moving_speed({8: 50})
    dxl_io.set_moving_speed({9: 50})
    dxl_io.set_moving_speed({10: 50})
    dxl_io.set_moving_speed({11: 50})

    dxl_io.set_goal_position({2: 150})
    dxl_io.set_goal_position({3: 150})
    dxl_io.set_goal_position({4: 150})
    dxl_io.set_goal_position({5: 150})
    dxl_io.set_goal_position({6: 150})
    dxl_io.set_goal_position({7: 150})
    dxl_io.set_goal_position({8: 150})
    dxl_io.set_goal_position({9: 150})
    dxl_io.set_goal_position({10: 150})
    dxl_io.set_goal_position({11: 150})
    time.sleep(8)


fablab bcn iacc

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.