ESP8266: NodeMCU Motor Shield Review

If you want to engage with your ESP8266 into robotics there is now an almost ready-to-go solution: the NodeMCU Motor Shield. If my research is correct then it was the Doctors of Intelligence & Technology (http://doit.am/) who created it and also are offering some LUA code to get started. This post shares my experience with the motorshield and also with a two engine “Smart Car” kit that nicely combines with the motorshield.

Motorshield

If you want to drive motors with your ESP8266 you have to be careful. The General Purpose Input/Output (GPIO) pins of the ESP8266 (as well as the similar Arduinos) don’t allow you to draw the amount of current required for a motor. But how to do that? You could build something on your own by using a few electronic components (transistor, capacitor, etc) or you could just pick something off the shelf that does exactly that for you. That’s where the Doctors of Intelligence & Technology and their motor shield comes in. It is designed to carry a NodeMCU V1.0 on its back. Note: the motor shield won’t fit for a NodeMCU V0.9! It has convenient terminals to attach two two-ways motors (or according to some source one stepper motor). It also has terminals to attach the power source that drives the motors and the NodeMCU. And as a clever addition you can decide to have just one power source for both motors and NodeMCU by setting a jumper accordingly.
One of the two terminals (Vin for NodeMCU) can be cut off with a power switch which saves you from taking out the batteries.
Besides the terminals there are also male pins which lead out GPIO 0-8 (in NodeMCU terminology), the reset pin, the analog/digital converter, the UART pins and the SPI pins.
NodeMCU V1.0 Powershield
A sign on the PCB makes it easy enough to plugin the NodeMCU the correct way: just make sure that the antenna of the ESP8266 and the antenna symbol on the motor shield are on the same side.

Smart Car Kit

The Smart Car Kit is the ideal companion for the NodeMCU if you want to get started into WiFi controlled cars or robotics. Some vendors even sell it in one big package for about USD $22 (see here). It comes with 2 two-ways motors with reduction gear, two main wheels and one support wheel, a chassis, a battery pack for 4 AA cells and additional screw driver. 
You can put everything to getter within just about 15 minutes once you have figured out where the parts have to go. I only had two issues with the kit: while you might be able to attach the wires to the engine without soldering I would recommend that you do this with a soldering iron. The other (bigger) problem was the supporting wheel. It turns easy enough around the axis of the wheel itself but the z-axis which should adjust when the car makes a turn is not working so smoothly. This can have the effect that even if both motors go at the same speed the supporting wheel is stuck in a weird position and keeps your car to pull to one side. I solved this by using some duct tape and fixing the wheel at the “forward” position. This might be suboptimal for turning but works good enough on smooth floors. It might be a problem though on soft carpets but I haven’t tried that.
The Smart Car Kit

Bringing it together: the WiFi Car

The next step was to put all the pieces (Smart Car, battery pack, NodeMCU V1.0 and Motor Shield) together. The holes of the motor shield fit perfectly into the holes of the acrylic chassis and the kit comes with enough screws and nuts to attach it. Also the battery pack can be screwed easily onto the chassis. The way I placed the components onto the chassis left only little space between the motor shield and the battery pack which made it hard to attach the wires with the terminals.

Programming the Car from the Arduino Environment

The inventors of the kit have sample code for LUA on their website. But I decided to try to program the car with the Arduino IDE. And that is really easy: 4 pins control the engines. Pins 4 and 5 (Arduino Terminology) control the speed of the engines with PWM in a default range of 0..1023 while pins 0 and 2 define the direction the engines will turn. 0 is backwards and 1 is forward but this might depend on who you wired the engines up to the shield. In my case I had to swap the wires of one of the two engines so a “1” would symbolise the same direction for both engines.
First I wrote a little Arduino sketch to test if everything was working alright and if I understood the interface correctly. From there I incrementally improved the code and I’m now able to steer it with any device with a modern browser, a built in accelerometer by just balancing the device in the direction I want to car to move. While it is still far from perfect it works surprisingly well: a javascript program reads out the accelerometer of the controlling device (e.g. an iPhone) and sends AJAX requests to the WiFi connected Smart Car. These commands are then taken to steer the motors.
In this scenario a big part of the logic is in the javascript code. While this could be hosted on the ESP8266 EEPROM I decided to load it from an external server which makes it really easy to program: I only have to change the file on the remote server. The ESP8266 firmware remains unchanged for most of the time. 
To connect to the device you only have to find out the IP that has been assigned to the NodeMCU. Then open that IP in your Smart Phone browser and move level your device to steer the car.
Here is a little video of that setup:

Source Code:

Related:  ESP8266 Feature Preview: More Fonts for the Weather Station!

Shopping List:

Now a beer! Did you like this post? It often takes me several hours of my free time to write one. If I was your neighbour would you offer me a beer for the hard work I did for you? The beauty is: beers can be teletransported with a painless donation using Paypal. A beer in a Swiss bar costs about USD $4.80. Or use this affiliate link if you order something on Banggood and I'll get a small kickback. Thank you!