Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,77 @@
# WEMOS_Motor_Shield_Arduino_Library
Arduino library for the WEMOS Motor Shiled - a shield for D1 mini, i2c interface, based TB6612
# Wemos_D1_Motor_Shield
Arduino library for the Wemos D1 mini Motor Shield (i2c interface, TB6612 based).

## Firmware Warning

WARNING: The shipped firmware with the Motor Shield is bugged. You need to update it. You can update it from Windows with a D1 Mini. You can find the update instructions below.

### Sources

* https://www.letscontrolit.com/wiki/index.php/WemosMotorshield
* https://github.com/pbugalski/wemos_motor_shield
* https://hackaday.io/project/18439-motor-shield-reprogramming

## Update the Firmware (from Windows)

### Step 1

Upload an empty sketch to you D1 Mini. This will allow serial data to pass from the USB port to the Motor Shield. Basically, we are telling the D1 Mini to ignore all serial data that will pass through to the Motor Shield.

Sketch:
```
void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}
```

### Step 2

Solder RTS and 3V on the Motor Shield. This activates the reprogramming mode of the Motor Shield. Then build this circuit:
![Image of circuit to update the firmware](https://github.com/thomasfredericks/wemos_motor_shield/blob/master/doc/wemos_motor_update_firmware.png?raw=true)

### Step 3

Download STM32Flash from here https://sourceforge.net/projects/stm32flash/files/

Extract in a directory.

### Step 4

Download the motor_shield.bin: https://cdn.hackaday.io/files/18439788894176/motor_shield.bin

Extract and put in the same directory as ```stm32flash.exe``` downloaded in the step above.

### Step 5

Execute the following three commands. IMPORTANT: Replace COM8 with the port of your Wemos D1 Mini.


1) ```stm32flash.exe COM8```

Replace COM8 with the port of your Wemos D1 Mini.

![image of stm32flash.exe result](https://github.com/thomasfredericks/wemos_motor_shield/blob/master/doc/update_command_a.png?raw=true)

2) ```stm32flash.exe -k COM8```

This will unlock your shield, replace COM8 with the port of your Wemos D1 Mini

![image of stm32flash.exe -k result](https://github.com/thomasfredericks/wemos_motor_shield/blob/master/doc/update_command_b.png?raw=true)

3) ```stm32flash.exe -f -v -w motor_shield.bin COM8```

This will flash the bin and re-lock the shield, replace COM8 with the port of your Wemos D1 Mini.

![image of stm32flash.exe -f -v -w motor_shield.bin result](https://github.com/thomasfredericks/wemos_motor_shield/blob/master/doc/update_command_c.png?raw=true)

### Step 6

Disconnect everything and unsolder RTS and 3V on the Wemos Motor Shield.


Binary file added doc/update_command_a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/update_command_b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/update_command_c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/wemos_motor_update_firmware.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 0 additions & 52 deletions examples/motor_base/motor_base.ino

This file was deleted.

59 changes: 59 additions & 0 deletions examples/wemos_motor_shield_demo/wemos_motor_shield_demo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <Wire.h>


#include "WEMOS_Motor.h"



//Motor shield default I2C Address: 0x30
//PWM frequency: 1000Hz(1kHz)
Motor M1(0x30, _MOTOR_A, 1000); //Motor A
Motor M2(0x30, _MOTOR_B, 1000); //Motor B


void setup() {


Serial.begin(57600);
Serial.println("Starting demo");


}

void loop() {

int pwm;

for (pwm = 0; pwm <= 100; pwm++)
{
M1.setmotor( _CW, pwm);
M2.setmotor(_CW, pwm);
Serial.print("Clockwise PWM: ");
Serial.println(pwm);
delay(100);
}

Serial.println("Motor STOP");
M1.setmotor(_STOP);
M2.setmotor( _STOP);

delay(1000);


for (pwm = 0; pwm <= 100; pwm++)
{
M1.setmotor(_CCW, pwm);
//delay(1);
M2.setmotor(_CCW, pwm);
Serial.print("Counterclockwise PWM: ");
Serial.println(pwm);
delay(100);

}

Serial.println("Motor A&B STANDBY");
M1.setmotor(_STANDBY);
M2.setmotor( _STANDBY);
delay(1000);

}
15 changes: 8 additions & 7 deletions src/WEMOS_Motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
*/
Motor::Motor(uint8_t address, uint8_t motor, uint32_t freq)
{

Wire.begin();

_use_STBY_IO=false;

if(motor==_MOTOR_A)
_motor=_MOTOR_A;
else
_motor=_MOTOR_B;

Wire.begin();


_address=address;

Expand Down Expand Up @@ -57,12 +60,12 @@ Motor::Motor(uint8_t address, uint8_t motor, uint32_t freq, uint8_t STBY_IO)
void Motor::setfreq(uint32_t freq)
{
Wire.beginTransmission(_address);
Wire.write(((byte)(freq >> 16)) & (byte)0x0f);
Wire.write(((byte)(freq >> 24)) & (byte)0x0f);
Wire.write((byte)(freq >> 16));
Wire.write((byte)(freq >> 8));
Wire.write((byte)freq);
Wire.endTransmission(); // stop transmitting
delay(100);
//delay(100);
}

/* setmotor() -- set motor
Expand Down Expand Up @@ -109,12 +112,10 @@ void Motor::setmotor(uint8_t dir, float pwm_val)
Wire.write((byte)(_pwm_val >> 8));
Wire.write((byte)_pwm_val);
Wire.endTransmission(); // stop transmitting


delay(100);
//delay(1);
}

void Motor::setmotor(uint8_t dir)
{
setmotor(dir,100);
}
}