Tags:
create new tag
view all tags

Motors

Introduction

We have 3 different types of motors in our kit:

  • DC motor: Used for continuous movement in either forward or backward direction and at different speeds
  • Servo motor: Allows to move to a precise angle. Used e.g. for steering the direction of a robot car, RC controlled model air planes or ships. Allowed angles are usually 0..180 degrees
  • Stepping motors: Move in steps and therefore allow to move forward or backward to a precise position of any distance.

The DC motor

The DC motor we use needs ~ 350 mA of power and can therefore not be run when the ESP32 power is coming from the USB connector, delivering a maximum ~200mA. We will need an external power supply!

dcMotorProp.png

The motor is controlled by a motor control shield:

Motor Control Shield
Front view
Motor Controller Shield
Back side
motorShieldFront.png motorShieldBack.png
As shown in the photo on the right 2 solder bridges must be installed to
  • tie the reset pin to the reset signal of the system
  • to allow access to motor standby through an I2C command
The motor control shield is accessed as an I2C device on address 0x30. I2C access is managed by an STM32F030 micro controller, which unfortunately is delivered with buggy firmware. When trying, I saw the device on the I2C bus immediately after reset but when trying a second time it had disappeared from the bus.

Fortunately for us other people have noticed this before and Piotr Bugalski has written replacement firmware which works reliably. Have a look at https://hackaday.io/project/18439-motor-shield-reprogramming to find out how this is done.

A MicroPython driver for exactly this motor controller can be found on https://bitbucket.org/thesheep/micropython-d1motor/src/default. I integrated this driver into the MicroPython binary. It provides a class Motor with the following methods:

  • A Motor instance must be created with the parameters
    • index: 0 or 1 which corresponds to either motor 1 or motor 1 (2 DC motors can be controlled be the shield)
    • ic2: an I2C object, which must be created before (we did this in the exercise on the SHT30)
  • frequency(freq): if freq == None this method returns the PWM frequency used to control motor speed otherwise its sets the frequency
  • speed(motor_speed): if motor_speed == None: returns the current speed,otherwise it sets the speed.
    motor_speed values can be 1..10000 to move clockwise or -1..-10000 to move counterclockwise.
    I found that for values below 1500 the current is too low to make the motor move
  • brake: stop the motor
  • sleep: put the motor into standby mode to save power

The Servo Motor

The servo motor we use is of type SG90. It is a cheap hobbyist servo which can be run directly off the ESP32 power supply even it that board is powered through an USB connector. For connections and technical details pleas consult the SG90 data sheet.

servo.png

The servo motor is connected to the WeMos D1 as follows

Cable from Servo Motor Cable color Pin on ESP32
Gnd brown Gnd
Power red 5V
Signal orange any GPIO pin, default: D0, on ESP32: GPIO 26

I wrote and integrated into the MicroPython binary a simple servo driver which makes it extremely simple to control the servo motor:

from servo import Servo 
servo = Servo() 
servo.angle(90)  

will move the servo to 90 degrees.

Stepping Motor

In order to learn about how stepping motors work please refer to the 2017 course on embedded systems lecture 9: Embedded_Systems/Lecture9:SteppingMotors. We will use a 27BJY-48 stepper motor with its associated ULN-2803 driver module. http://robocraft.ru/files/datasheet/28BYJ-48.pdf is the data sheet of the motor and https://www.sparkfun.com/datasheets/IC/uln2803a.pdf is the datasheet of the ULN-2803 Darlington Transistor array.

The stepping Motor class included in the MicroPython binary uses the following default connections

Pin on the driver module pin on the ESP32
5-12V 5V
Gnd Gnd
In1 D0: GPIO 26
In2 D5: GPIO 18
In3 D6: GPIO 19
In4 D7: GPIO 23
A stepper object is created with:

from stepper import steppingMotor 
stepper = steppingMotor() # the parameters p1,p2,p3,p4 are optional and allow to connect the stepping motor to different GPIO lines  

The steppingMotor class uses different modes for stepping:

  • SINGLE_PHASE_FORWARD (default)
  • SINGLE_PHASE_BACKWARD
  • DOUBLE_PHASE_FORWARD
  • DOUBLE_PHASE_BACKWARD
  • HALF_STEP-FORWARD
  • HALF_STEP_BACKWARD
You can set the mode with the method stepMode():
stepper.stepMode(stepper.DOUBLE_PHASE_FORWARD)

You can change the movement speed with the method waitAfterSteps() which defines how long to wait after each step in ms. Valid values are 2..1000. Again the method returns the value currently in use if called without a parameter.

The method clrAll() set all coils (IN1..IN4) to zero.

Finally the method move(noOfSteps) moves the stepping motor noOfSteps in the mode and with the speed currently selected.

The exercise sheet in odt format:

https://iotworkshop.africa/pub/IoT_Course_English/Motors/exercise_7.odt

-- Uli Raich - 2020-06-25

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng dcMotorProp.png r1 manage 51.4 K 2020-06-25 - 08:42 UliRaich  
Unknown file formatodt exercise_7.odt r1 manage 374.2 K 2020-08-09 - 08:59 UliRaich  
PNGpng motorShieldBack.png r1 manage 192.2 K 2020-06-25 - 08:43 UliRaich  
PNGpng motorShieldFront.png r1 manage 170.7 K 2020-06-25 - 08:43 UliRaich  
PNGpng servo.png r1 manage 143.0 K 2020-06-25 - 11:55 UliRaich  
PNGpng stepping.png r1 manage 152.3 K 2022-03-05 - 19:40 UliRaich  
Edit | Attach | Watch | Print version | History: r12 < r11 < r10 < r9 < r8 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r12 - 2022-09-23 - 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