Tags:
create new tag
view all tags

Motor exercises

Introduction

We have 3 types of motors that are used for different purposes and controlled in different ways:

  • DC motor used in continuous movement e.g. a propeller, motor to move a robot car etc.

  • Servo motor: A motor that allows to go to a precises angle used e.g. to steer the car, model airplane or

  • Stepping motor: Move to a precise position or angle. In contrast to the servo motor the angle is not limited and can make several full turns
DC motor Servo Motor Stepping motor
dcMotorProp.png servo.png stepping.png
Before starting with the exercises please read the TWiki page on motors: Motors

Exercise 1: The DC Motor

Make sure the solder jumpers are correctly inserted on the motor shield. Check with i2c_scan from the exercise on the SHT30 that you can reliably see the motor shield on address 0x30 of the I2C bus. Run I2C_scan several times and make sure the motor shield does not disappear from the bus.

If this happens you will have to upgrade the firmware for the STM32F030 micro-controller providing the I2C interface to the motor shield. Read the section “Reprogramming without soldering” very carefully and follow the steps. If something is not clear, please don’t hesitate to ask!

https://hackaday.io/project/18439-motor-shield-reprogramming

Download the motor shield driver from https://github.com/mcauser/deshipu-micropython-d1motor/blob/master/d1motor.py and make sure you understand every detail. Make a list with all methods and their parameters.

Finally connect the DC motor to the shield and make the motor move at different speeds and in forward and backward direction.

Attention: The motor draws ~ 350 mA, which is too much for the USB interface of the micro-controller delivering a maximum of ~ 200mA. You need an external power supply! The motor works on voltages between 3V and 6V.

Exercise 2: The servo motor

Connect the servo motor as described on the TWiki page. For the hobby servo motor the power delivered through the USB bus is sufficient. Check out the description of PWM in the MicroPython manual: https://docs.micropython.org/en/latest/esp8266/tutorial/pwm.html.

Download my simplistic servo driver from the TWiki page on motors.

Write a program to move the servo motor to a given angle.

Exercise 3: The stepping motor

If you do not know in detail how stepping motors work, please have a look at chapter Lecture 9 of the course on embedded systems: https://afnog.iotworkshop.africa/do/view/Embedded_Systems/Lecture9:SteppingMotors

Stepping motors can run in different modes:

  • Single phase forward and backward

  • Double phase forward and backward

  • Half step forward and backward.

Write a stepping motor class implementing these 6 stepping modes. The class should have the methods:
  • __init__(self,p1=_PHASE1,p2=_PHASE2,p3=_PHASE3,p4=_PHASE4) : creating a motor instance. You may pass the coil pins as keyword parameters

  • clrAll(self) : sets all coils off

  • stepMode(self,mode=None): Sets the stepping mode
    The available stepping modes are declared as Class variables as follows:

    SINGLE_PHASE_FORWARD = 0
    SINGLE_PHASE_BACKWARD = 1
    DOUBLE_PHASE_FORWARD = 2
    DOUBLE_PHASE_BACKWARD = 3
    HALF_STEP_FORWARD = 4
    HALF_STEP_BACKWARD = 5

  • move(self,noOfSteps): Moves the motor by the number of steps given in the currently set mode.

Write a script stepperTest.py exercising all 6 stepping modes

-- Uli Raich - 2022-03-05

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng dcMotorProp.png r1 manage 51.4 K 2022-03-05 - 19:51 UliRaich  
PNGpng servo.png r1 manage 143.0 K 2022-03-05 - 19:51 UliRaich  
PNGpng stepping.png r1 manage 152.3 K 2022-03-05 - 19:51 UliRaich  
Topic revision: r1 - 2022-03-05 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback