"Adafruit Motor Shield v2"

From Let's Control It
Jump to: navigation, search


This Plugin in currently only available in the latest mega build github

This Plugin is for the Adafruit Motor Shield v2 which is controlled over the I2C protocol. To connect it to ESP8266 devices (e.g. Wemos D1 R2) you have to set it to 3.3 V, see adafruit documentation for that.


This Plugin works with the v2 version of the Adafruit Motor Shield v2: Support the great developer of this board with buying it from them! (you will also find cheaper clones on Aliexpress, which also work with this plugin)

Adafruit motorshield v2.jpg

This Picture shows a clone board.


The Plugin is heavily based on Adafruits own Library

ESP Easy

Use the device tab on the ESP Easy webinterface and create a new task by editing one of the available tasks. Select "Adafruit Motor Shield v2" from the dropdown box.

Enter the i2c address of you sensor, default value 0x60

Motor shield settings.jpg

Controlling the Motor Shield via HTTP commands

You can control the Motorshield by remote http commands send from your Home Automation Controller or any other device that can send http get requests.

Command format:

For DC Motors:

 http://<ESP IP address>/control?cmd=MotorShieldCMD,DCMotor,<Motornumber>,<Forward/Backward/Release>,<Speed>

For Steppers:

 http://<ESP IP address>/control?cmd=MotorShieldCMD,Stepper,<Motornumber>,<Forward/Backward/Release>,<Steps>,<SINGLE/DOUBLE/INTERLEAVE/MICROSTEP>

Examples: Turn on DC Motor, Direction: Forward. Speed is a value from 0-255

 http://<ESP IP address>/control?cmd=MotorShieldCMD,DCMotor,1,Forward,255

Stopping the DC Motor:

 http://<ESP IP address>/control?cmd=MotorShieldCMD,DCMotor,1,Release

control a Servo Motor

Support for Servo Motors is available via the buildtin functionality of ESPEasy (not part of this plugin) and can be done this way:

 http://<ESP IP address>/control?cmd=Servo,<servo nr>,<pin>,<position>

We currently support a maximum of two servo motors so you can build a pan & tilt device if you like.

Example to set servo 1 on gpio-0 to a 90 degree position and servo 2 on gpio-2 to a 45 degree position:

 http://<ESP IP address>/control?cmd=Servo,1,0,90
 http://<ESP IP address>/control?cmd=Servo,2,2,45

Beware: The Servo Pins on the Motor Shield (next to the reset button) do not work if you put the motor shield directly on the "wemos d1 r2"

Rules Example

 On Clock#Time=All,21:22 do // every day at 21.22 hours do ...
 on startwater do
   MotorShieldCMD,DCMotor,1,Forward,215  // open valve
   timerSet 2,1 // 1 sec timer
 On Rules#Timer=2 do  //When Timer2 expires, do
 on stopwater do
   MotorShieldCMD,DCMotor,1,Backward,69  // close valve
   timerSet 3,1 // 1 sec timer
 On Rules#Timer=3 do  //When Timer3 expires, do