Skip to content

Motor Definition Quickstart

pootle edited this page Aug 21, 2020 · 5 revisions

For some very simple testing, a motor definition file can be amended to define the correct pins.

For all the gory details see The motor definition file

Start with a single motor; copy one of the sample json files and edit it to define the correct pins. The step timings can be temporarily adjusted through the web page. (to be made permanent, the file must be edited)

Each motor starts with a name and a motorclass. The name must match the relevant entry in the config python file. The motorclass can be "ULN" or "DRV8825". There are several sample json files, the two detailed examples below can be used to create modified versions of any of these files.

All the json files include a number of step driving modes - direct from software or dma based, as well as single speed and ramping variants.

motor8825.json
A single motor via a driver chip like A4988 or DRV8825.

motorpair8825.json
Two motors via driver chips like A4988 or DRV8825.

motorunipole.json
A single unipole stepper driven via a simple chip such as a ULN2003. The direct software mode allows smart use of PWM to allow microstepping, and DMA driven output (without PWM) for high speed movement.

motormixed.json
Two A4988 style chip driven motors and a single ULN2003 style chip driven motors

Once the appropriate json file has been amended, test run the web server with the app here Running the web app.

unipolar motor via a ULN2003 or similar chip

Start with the file motorunipole.json:

Edit the line

"drive_pins": "6 5 7 8",

and change (if necessary) the 4 pin numbers to the broadcom pin numbers you have connected in the order they appear on the chip - they order can be be reversed to make forward rotate in the correct direction, but if the order is not 1, 2, 3, 4 or 4, 3, 2, 1 the motor may behave erratically.

biploar motor via A4988, DRV8825 or similar chip

Note that only the step pin is mandatory, all other pins are optional, although a relevant entry must be provided in the json file (typically be setting pinno to -1, but see individual sections for details.

start with the file motor8825.json:

The broadcomm pins numbers for drive enable, direction, step and microstep level selection need to be changed (if neccessary). The json file also allows any of these pins to be setup as not connected (for example if they are hardwired).

The drive enable, direction and step pins are all defined in their own subsections.

Step pin

    "step": {
        "pinno": 27,
        "pulsetime": 2,
        "vlist": [0, 1]
    },

The fields in the step pin are:

pinno:
the broadcom pin number connected to step.

pulsetime:
the time in microseconds the pulse is "on"

vlist:
[0,1] for pulse high, [1,0] for pulse low

Direction pin

    "direction": {
        "pinno": 18,
        "vlist": [
            "F",
            "R"
        ]
    },

The fields in the direction pin are:

pinno:
the broadcom pin number connected to step. Use -1 if there is no gpio pin for direction.

vlist:
["F", "R"] if low is forward or ["R", "F"] if low is reverse. Use one or other setting to make forwards rotate in the correct direction. Note that the two values must be "F" and "R" as these are coded into the software

Drive enable pin

   "drive_enable": {
        "pinno": 25,
        "value": "disable",
        "closevalue": "disable",
        "vlist": [
            "enable",
            "disable"
        ]
    },

The fields in the drive_enable pin are:

pinno:
the broadcom pin number connected to step. Use -1 if there is no gpio pin for drive enable.

value:
the setting that will be setup when the app starts

closevalue:
If you want the pin to be left in output mode with the drive enable set a specific way when the app shuts down, put "enable" or "disable" here, To let the pin revert to input mode, remove this line.

vlist:
["enable", "disable"] for enable low, ["disable", "enable"] for enable high. The values "enable" and "disable" must be used as they are coded into the software

microstep level pins

    "usteppins": {
        "pins": [
            {"pinno": 24},
            {"pinno": 23},
            {"pinno": 22}
        ],
        "value": "half",
        "microsteps": {
            "single": {
                "factor": 1,
                "table": [0,0,0]},
            "half": {
                "factor": 2,
                "table": [1,0,0]},
            "1/4": {
                "factor": 4,
                "table": [0,1,0]},
            "1/8": {
                "factor": 8,
                "table": [1,1,0]},
            "1/16": {
                "factor": 16,
                "table": [1,1,1]}
        }
    },

The fields in usteppins are:

pins
a list of the pins used to control the microstep level, each entry is {"pinno": nn} where pinno is the broadcom pin number.

value
The initial value that will be setup when the app starts - must be one of the names used in the following microsteps section.

microsteps
Any number of named entries that define an available microstep level. Each entry contains 2 fields:

factor
The number of these microsteps required to make a full step. This is used to keep accurate track of the position when different microstep levels are used.

table
A list of 0's and 1's. The length MUST be the same as the number of entries in the pins list. The values define the high pr low setting for this microstep level

If there are no gpio pins to control the microstep level use: Note that if there are no pins to control the microstep level then use the following:

"microsteps": {
    "1": []
}