Giter Club home page Giter Club logo

dfrobot_raspberrypi_motor's Introduction

DFRobot DC Motor Driver HAT

This RaspberryPi motor-driving board can communicate with RaspberryPi via IIC.
It can control the motor to rotate forward and reserve, and rotation speed.
The control command is IIC command and the drive command is PWM signal.
The single-channel maximum operate current is 1.2A. The input port is compatible with GPIO port.
With 2 independent output channels and 2 encoder ports, it can control 2 DC-motors or 2 motors with encoder.
Application: RaspberryPi smart car, DIY tank, DIY micro-fish...

DFRobot DC Motor Driver HAT Library for RaspberryPi

Provide a Raspberry Pi library for the DC Motor Driver HAT modules.

Table of Contents

Summary

DC Motors driver.

Feature

  1. Two DC motors with encoder control or normal DC motors.
  2. Get motors speed form encoder.
  3. PWM frequency set.
  4. PWM duty set.

Installation

This Sensor should work with DFRobot_RaspberryPi_DC_Motor on RaspberryPi.
Run the program:

$> python2 DC_Motor_Demo.py

Methods

class DFRobot_DC_Motor:

  ''' Enum motor ID '''
  M1 = 0x01
  M2 = 0x02
  
  ''' Board status '''
  STA_OK = 0x00
  STA_ERR = 0x01
  STA_ERR_DEVICE_NOT_DETECTED = 0x02
  STA_ERR_SOFT_VERSION = 0x03
  STA_ERR_PARAMETER = 0x04

  ''' last operate status, users can use this variable to determine the result of a function call. '''
  last_operate_status = STA_OK

  ''' Orientation and global variables '''
  CW = 0x01     # clockwise
  CCW = 0x02    # countclockwise
  STOP = 0x05
  ALL = 0xffffffff

  def begin(self):
    '''
      @brief    Board begin
      @return   Board status
    '''

  def set_addr(self, addr):
    '''
      @brief    Set board controler address, reboot module to make it effective
      @param address: int    Address to set, range in 1 to 127
    '''

  def set_encoder_enable(self, id):
    '''
      @brief    Set dc motor encoder enable
      @param id: list   Encoder list, items in range 1 to 2, or id = self.ALL
    '''
  
  def set_encoder_disable(self, id):
    '''
      @brief    Set dc motor encoder disable

      @param id: list   Encoder list, items in range 1 to 2, or id = self.ALL
    '''

  def set_encoder_reduction_ratio(self, id, reduction_ratio):
    '''
      @brief    Set dc motor encoder reduction ratio
      @param id: list                 Encoder list, items in range 1 to 2, or id = self.ALL
      @param reduction_ratio: int     Set dc motor encoder reduction ratio, range in 1 to 2000, (pulse per circle) = 16 * reduction_ratio * 2
    '''

  def get_encoder_speed(self, id):
    '''
      @brief    Get dc motor encoder speed, unit rpm
      @param id: list   Encoder list, items in range 1 to 2, or id = self.ALL
      @return :list     List of encoders speed
    '''

  def set_moter_pwm_frequency(self, frequency):
    '''
      @brief    Set dc motor pwm frequency
      @param frequency: int    Frequency to set, in range 100HZ to 12750HZ, otherwise no effective (actual frequency) = frequency - (frequency % 50)
    '''

  def motor_movement(self, id, orientation, speed):
    '''
      @brief    Motor movement
      @param id: list             Motor list, items in range 1 to 2, or id = self.ALL
      @param orientation: int     Motor orientation, self.CW (clockwise) or self.CCW (counterclockwise)
      @param speed: float         Motor pwm duty cycle, in range 0 to 100, otherwise no effective
    '''

  def motor_stop(self, id):
    '''
      @brief    Motor stop
      @param id: list   Motor list, items in range 1 to 2, or id = self.ALL
    '''

  def detecte(self):
    '''
      @brief    If you forget address you had set, use this to detecte them, must have class instance
      @return   Board list conformed
    '''

class DFRobot_DC_Motor_IIC(DFRobot_DC_Motor):

  def __init__(self, bus_id, addr):
    '''
      @param bus_id: int   Which bus to operate
      @oaram addr: int     Board controler address
    '''

Credits

·author [Frank [email protected]]

dfrobot_raspberrypi_motor's People

Contributors

forknowyou avatar luoyufenglalala avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.