Reference

API Description

/**
   * @fn DFRobot_N20SerialMotor
   * @brief Constructor.
   * @param addr Modbus slave address, range: 1~247.
   * @param s Stream pointer used for Modbus-RTU communication.
   */
  DFRobot_N20SerialMotor(uint8_t addr, Stream *s);

  /**
   * @fn begin
   * @brief Verify device at current address.
   * @n     Initialize the serial port in user sketch before calling this function.
   * @return int8_t
   * @retval 0 success
   * @retval -1 failed
   */
  int8_t begin(void);

  /**
   * @fn setSpeed
   * @brief Set motor speed.
   * @param speed Range: -255~255. 0 stops the motor.
   * @return int8_t
   * @retval 0 success
   * @retval -1 failed
   */
  int8_t setSpeed(int16_t speed);

  /**
   * @fn setDeviceAddr
   * @brief Set module device address.
   * @param addr Address range: 1~247.
   * @n     The new address takes effect after the module is powered on again.
   * @n     This function does not update the internal communication address;
   * @n     recreate the object with the new address after the module restarts.
   * @return int8_t
   * @retval 0 success
   * @retval -1 failed
   */
  int8_t setDeviceAddr(uint8_t addr);

  /**
   * @fn setBaudrate
   * @brief Configure baudrate, Only the baud rate can be modified, and the stop bit and check bit cannot be modified.
   * @param baud Baudrate code.
   * @n     eBaud2400
   * @n     eBaud4800
   * @n     eBaud9600
   * @n     eBaud14400
   * @n     eBaud19200
   * @n     eBaud38400
   * @n     eBaud57600
   * @n     eBaud115200
   * @n     The new baudrate takes effect after the module is powered on again.
   * @n     This function does not update the host serial baudrate;
   * @n     reinitialize the serial port with the new baudrate after the module restarts.
   * @return int8_t
   * @retval 0 success
   * @retval -1 failed
   */
  int8_t setBaudrate(eBaudrate_t baud);

  /**
   * @fn restoreFactory
   * @brief Restoring factory Settings mainly involves setting the uart and device addresses back to their default values
   * @n     Factory settings take effect after the module is powered on again.
   * @return int8_t
   * @retval 0 success
   * @retval -1 failed
   */
  int8_t restoreFactory(void);

  /**
   * @fn getDeviceInfo
   * @brief Read VID/PID/version.
   * @return sDeviceInfo_t
   * @n       VID           The vendor ID of the device.
   * @n       PID           The product ID of the device.
   * @n       version       The version of the device.
   */
  sDeviceInfo_t getDeviceInfo(void);

  /**
   * @fn scanAddress
   * @brief Scan slave addresses on current bus.
   * @param addrBuf Output address array.
   * @param bufLen Max items that can be stored in addrBuf.
   * @param startAddr Start address of scan range, clamped to 1 if lower.
   * @param endAddr End address of scan range, clamped to 247 if higher.
   * @return uint8_t Number of discovered devices.
   */
  uint8_t scanAddress(uint8_t *addrBuf, uint8_t bufLen, uint8_t startAddr = 1, uint8_t endAddr = 247);

Was this article helpful?

ON THIS PAGE

TOP