firmata / protocol

Documentation of the Firmata protocol.
995 stars 151 forks source link

Q: AccelStepperFirmata - not completely clear from available docs #120

Closed LinuksGuru closed 4 years ago

LinuksGuru commented 4 years ago

Hi !

Thanks for creating so great and useful piece of software! Python-related documentation is quite short, and I encountered some issues because something is not completely clear for me (controlling AccelStepperFirmata from Raspberry Pi + Python). Generated by configurable firmata sketch was uploaded to Arduino Due, and communication seems to be ok.

1) Simplest command - zero.

def accStepFmt_Zero(brd, dev_no):
    cmd = bytearray([acc.ACCELSTEPPER_ZERO, dev_no])
    brd.send_sysex(sysex_cmd, cmd) #  which sysex_cmd from contants in "FirmataConstants.h"?

Is the whole concept OK? sysex_cmd = ACCELSTEPPER_DATA, SYSEX_NON_REALTIME, STEPPER_DATA (0x72) or anything else? PyFirmata function "send_sysex" seems like automatically appends START_SYSEX and END_SYSEX, so they don't need in cmd.

2) Is that the correct way to form a command?

def accStepFmt_Config(brd, dev_no, wire_count, step_type, has_ena_pin,
                      mp1_step_pin, mp2_dir_pin, mp3, mp4):

    cmd = bytearray([acc.ACCELSTEPPER_CONFIG, dev_no])

    # wire_count == 1 EQ driver mode
    if wire_count == 1:
        intf = '001'
    elif wire_count == 2:
        intf = '010'
    elif wire_count == 3:
        intf = '011'
    elif wire_count == 4:
        intf = '100'
    else:
        intf = '001'

    if step_type == 0:
        intf = intf + '000'
    elif step_type == 2:
        intf = intf + '001'
    elif step_type == 4:
        intf = intf + '010'
    else:
        intf = intf + '000'

    if has_ena_pin:
        intf = intf + '1'
    else:
        intf = intf + '0'

    x = int(intf, 2)
    cmd.append(x)
    brd.send_sysex(???, cmd)

X is a 7-bit in to be sent within a byte array. Thanks in advance.

LinuksGuru commented 4 years ago

Another moment which is not clear: Look at item No 7 - when interface >= 0x011] motorPin3 (0-127) When interface >= 0x011, its clear, motorPin3 for example = 10. But what if interface < 0x011? Should I set motorPin3 = 0 or just omit it from sysex command sequence?

# 5  motorPin1 or stepPin number                (0-127)
# 6  motorPin2 or directionPin number           (0-127)
# 7  [when interface >= 0x011] motorPin3        (0-127)
# 8  [when interface >= 0x100] motorPin4        (0-127)
# 9  [when interface && 0x0000001] enablePin    (0-127)
# 10 [optional] pins to invert                  (lower 5 bits = pins:
#                                                XXXXXX1 = invert motorPin1
#                                                XXXXX1X = invert motorPin2
#                                                XXXX1XX = invert motorPin3
#                                                XXX1XXX = invert motorPin4
#                                                XX1XXXX = invert enablePin)
# 11 END_SYSEX                                  (0xF7)