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 \x93Reprogramming without soldering\x94 very carefully and follow the steps. If something is not clear, please don\x92t 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

-- %USERSIG{UliRaich - 2022-03-05}%

Comments

 

I Attachment Action Size Date Who Comment
dcMotorProp.pngpng dcMotorProp.png manage 51 K 05 Mar 2022 - 19:51 UnknownUser  
servo.pngpng servo.png manage 142 K 05 Mar 2022 - 19:51 UnknownUser  
stepping.pngpng stepping.png manage 152 K 05 Mar 2022 - 19:51 UnknownUser  
This topic: IoT_Course_English > WebHome > Exercises > MotorExercises
Topic revision: 05 Mar 2022, UliRaich