WiFi Car with NodeMCU

By chance I saw at http://www.banggood.com an interesting WiFi controlled toy car (order number SKU256467) for about $22. Normally such a toy is closed source, but not in this case. After some digging in the Internet, I found an enormous amount of open source documentation and an active community, starting with the ESP8266 System on Chip (SoC). There is also an Arduino plugin available Links #17, to make programming in C easy . So, in summary a lot of ingredients for a nice low cost maker project (buzzword: Internet of Things, IoT). Lets start the description from the core, the ESP8266.

Since end of 2014 there is a very interesting WiFi module with application processor (32 bit) on the market, called ESP8266, at a price of about 3 EUR. The main application is a Serial to WiFi Bridge, named AT. But it can do a lot more.

Look at http://www.ebay.de for ESP8266 Serial WIFI Wireless Transceive Modul LWIP AP+STA. In early 2015 the EPS8266 module ESP-12E started on the market. It has 18 active pins, see Links #4.

attachment:Doit_Car_DSC06296.jpg

Short thereafter a 30 pin Dual-Inline (2.54 mm spacing) module named NodeMCU (Version 0.9, later 1.0) appeared on the market, which carries an ESP-12 module and a Serial to USB converter with micro USB socket. The pinout and schematic can be found at Links #5. The firmware API description you can find at Links #6. This module is similar to the Arduino Nano 3 module.

For the NodeMCU you can get a motor shield for either 2 DC motors, or 1 stepper motor, see at Links #7.

That motor shield placed on a car chassis with 2 driven DC motors will give a WiFi-car, that can be radio controlled (WiFi) via smart phone, see at Links #1, and the picture on the right.

On the following pages I describe, how to program such a nice System on Chip (SoC), containing a lot of debug assistance and HowTo about the software routines.

/!\ I made all programming with the Arduino IDE version 1.6.5.

/!\ A big Thank You for all the genius programmers, who created that.

Click on the pictures to enlarge them.

WiFiCar setup

It is not easy to setup the WiFiCar with the provided software. You should have good knowledge of network handling, and Arduino and C programming. Following the steps you need to do:

  1. Install the Arduino IDE (Integrated Development Environment) and the ESP8266 plugin Links #17 for programming the NodeMCU.

  2. With Arduino IDE upload my program wifi-car-AP.ino (Access Point mode) to the NodeMCU of the car.

  3. Power Up the NodeMCU, and try to find the WiFi hotspot (name: wifi-car) on IP address 192.168.4.1.

  4. Upload the provided JavaSript program wifi-carAP.js to the NodeMCU, with the URL http://192.168.4.1/upload (you will be asked for the File name/path).

  5. With an Android Smartphone connect with WLAN to the WiFicar Hotspot (name: wifi-car).

  6. Enter in your Web browser the URL http://192.168.4.1 . A HTML file is loaded (embedded in the C program) and the Java script file is loaded and executed.

  7. As soon, as you tilt the smartphone, the WiFicar will move in that direction.

All the needed details you will find in the following documentation.

attachment:DoitCar_Android.jpg

Doit WiFi car

It was developed from http://www.doit.am/ (Shenzhen Doctors of Intelligence & Technology). An introduction can be found at Links #9.

The chassis plate is made of transparent plexiglass. The brown color you see on many photos derives from the protection film covering the plexiglass. Once you peel it off, you will see the transparent plexiglass.

The assembly of the Do-It-Yourself kit is quick and easy, but it needs soldering the connecting wires from the power supply (4 x AA batteries, or rechargeables), power switch and the 2 motors.

A simple control program can be installed from the Android Play Store (App: Car(AP Mode)). The Access Point (AP) mode is the default of the delivered controller. Yes, the Android app works, but the control is really difficult, see the picture on the right. The kit accompanied ESP8266 is already programmed with the proper program to make an WiFi Access Point.

Fortunately I found another Android program, which controls the motion of the WiFi-Car via the orientation of a smart phone, keep reading.

/!\ For changing the forward/backward direction of the car, it helps to put a few drops of thin oil in the ball bearing of the back wheel.

ESP8266 module

Features:

For more details please see at WiFi2AT-ESP8266.

attachment:ESP-12E_DSC06304.jpg

ESP-12E module

The most versatile module with printed PCB antenna, see also Links #10/11:

The WiFi-car signals are also mentioned.
Pinout:           Antenna
Signal Name      pin   pin Signal Name
RST    Reset     1     22  TXD0   Serial 0 TXD WARNING: 3.3V adapter ONLY
ADC    Analog IN 2     21  RXD0   Serial 0 RXD WARNING: 3.3V adapter ONLY
EN               3     20  GPIO5  Motor PWMA
GPIO16           4     19  GPIO4  Motor PWMB
GPIO14           5     18  GPIO0  Button Flash, Motor DirA
GPIO12 EncA D6   6     17  GPIO2  LED, blue, Motor DirB
GPIO13 EncB D7   7     16  GPIO15
VCC   3.3V ONLY  8     15  GND

pin, Signal
9 CS0, 10 MISO, 11 GPIO09*, 12 GPIO10*, 13 MOSI, 14 SCLK
Note: The pins 9 to 14 are exclusively used for Quad-SPI communication
      with flash memory. They can't be used for application!

attachment:ESP_NodeMCU_DSC06305.jpg

NodeMCU

NodeMCU is an ESP-12E module mounted on a carrier board, together with an USB to serial converter. Have a look to the user manual, see Links #12. In short some details:

Wikipedia has some information, at Links #13.

The official user manual is at Links #12.

/!\ USB interface: I have seen that you can have a SiLabs CP2102 or WCH CH340G (Winchiphead) chip on the board. In case of MacOS Sierra 10.12.1 you need for the CH340G a new driver version 1.3, otherwise you get a kernel panic when pluggin in the module. I got the information from here.

/!\ Since 2015-09-30 a SPIFFS (Serial Peripheral Interface Flash File System) software was included in the Arduino plug-in. Now you can upload and download files by name, which are store in the SPI Flash ROM. For initialization you need to format the SPIFFS. This can be done in the Arduino (version 1.6.5) software, with the menu Tools/ESP8266 Sketch Data Upload. Beforehand you must place your file(s) in a data folder in your project folder. This will format and overwrite the complete SPIFFD area. Another possibility to format provides the Flash test program Arduino/hardware/esp8266com/esp8266/tests/FSWrapper.ino, you just upload it into the ESP8266 and let it run.

attachment:ESP-NodeMCU_motor_DSC06309.jpg

Motor shield

At http://www.banggood.com you can get a motor shield (part number: SKU256454) for about $5. The NodeMCU module fits in the dual inline socket. Some short data to the shield:

For the user manual see at Links #14.

/!\ Note: the motor shield won't fit for a NodeMCU V0.9!

/!\ With an on board jumper behind the screw terminal you can connect the two voltage inputs together.

/!\ Make sure to plug in the NodeMCU module in the orientation, that the WiFi antenna fits the sign on the board.

attachment:wifi-car_encoder_DSC06314.jpg

Wheel Encoder

Within the kit, two 20 slot encoder wheels are supplied, which are mounted on the axis of the motors. I mounted two sets of fork light barrier modules (Ebay #351291975401) above the encoder wheels, see the picture on the right.

Every slot of the encoder wheel gives 18° turn of the motor wheel.

Lets calculate the distance:

Next step in the development is to drive distances, with the help of the encoders.

Motor data

In order to know how fast the car can run, it is important to know the motor data. By chance I found the motor specification for the DC Motor, listed in the table on the right.

Working Voltage

DC 3V

DC 5V

DC 6V

Working Current

100mA

100mA

120mA

Reduction Ratio

48:1

No load (with wheel)

100 RpM

190 RpM

240 RpM

Wheel diamter

6.6 cm

Speed (no load)

20 m/min

39 m/min

48 m/min

Weight

50 g

Size

70x22x18 mm

Noise

< 65 db

Please consider, that the motor needs a minimum voltage to start running.

Community Forum and Wiki

There is a ESP8266 Community Forum and wiki at Links #22.

I will mention important postings.

attachment:wifi-car_software.jpg

WiFi Car control

/!\ In Access Point mode you connect your smart phone direct to WLAN hotspot wifi-car. You need no password. To find out the IP-Address, connect the NodeMCU to your PC via USB, start the Arduino IDE and the Serial Monitor. After pushing the Reset button the Serial Monitor will show you the IP-Address. Enter in the URL field of your web browser that IP-address.

/!\ In Station Access mode either have a look in the administration page of your WiFi router, or use the Arduino Serial Monitor as mentioned before.

At Links #15 you will find a description and the source code to control your WiFi-car with the orientation of your smart phone acceleration sensor. Unfortunately this design has a few drawbacks:

With the Arduino plug-in examples and the help of the ESP8266 community I managed it to rewrite and extend the software to an Stand alone Access Point, which can be used without Internet access.

WiFi Mode

In WiFi Access Point mode, if not otherwise specified in the program, the IP Address for the wifi-car (Access Point, hotspot) is set to 192.168.4.1 and the connected client will get via DHCP the IP-Address 192.168.4.2.

In WiFi Station mode, you must define SSID and password of the WiFi Router in the program (wifi-car-AP.ino). When connecting to the WiFi Router the wifi-car will get via DHCP the IP Address. You can find the IP Address in the Smartphone, or via web interface from the WiFi Router.

Program wifi-car-AP.ino

Let me describe the program from top to bottom. The functions for file handling are copied from program example FSBrowser.ino. The ESP8266 Arduino Core Reference API is described in Links #17.

The const char* serverIndex is a HTML form to access the filename for upload to the SPIFFS.

With #define ACCESSPOINT you decide if the ESP8266 will run as WiFi Access Point with the Javascript program in SPIFFS (for car use), or if commented out, as Station Access to a WiFi router, with the Javascript program on a web server, for easier software development. Please adopt SSID and password according to your WiFi router.

The new ESP8266WebServer is used, instead of the Arduino like web server.

Show/Download wifi-car-AP.c, after download please rename the extension from .c to .ino for the Arduino IDE. I had to rename it to .c, in order to get the lexer to work (color printing).

Javascript wifi-carAP.js

Let me describe the program from top to bottom.

The orientation of the smart phone is send every 200 ms via AJAX (Asynchronous JavaScript And XML) to the ESP8266 (function move_car(left, right)), see also Links #16. The update rate of the accelerator sensor is about 20 ms, see also Links #19/20/21.

If you tap on the smart phone display on one of the direction buttons, a maximum drive signal is send for 200 ms duration (function move(dir)).

Then it is checked, if an accelerator sensor is on board of the smart phone. If yes, the trap handler deviceMotionHandler is setup.

In function deviceMotionHandler the smart phone orientation (x, y, z; -10.0 .. +10.0) is converted to a motor drive value 0..1023, and shown on the display (left, right). As a debug help, the program version number is also shown on the display.

Show/Download wifi-carAP.js

Feedback

For any questions please use the KontaktEmail.

  1. 2WD L293D WiFi RC Smart Car with NodeMCU + Shield for ESP-12E based on ESP8266

  2. wikipedia.de - ESP8266 (German)

  3. www.mikrocontroller.net - ESP8266 Info (German)

  4. wikipedia.org - ESP8266 modules

  5. NodeMCU, pinout, schematic

  6. NodeMCU firmware API 0.95

  7. Motor Shield Board (L293DD) for NodeMCU from ESP8266 ESP-12E

  8. Shenzhen Doctors of Intelligence & Technology

  9. Doit WiFi car manual

  10. ESP-12E module documentation

  11. Adafruit.com, ESP-12E specification

  12. NodeMCU manual (ESP-12E)

  13. wikipedia.com, NodeMCU

  14. ESP-12E motor shield, user manual

  15. WiFi-Car control with smart phone orientation

  16. AJAX programming

  17. Arduino ESP8266 plugin

  18. ESP8266 Arduino Core Reference API

  19. Mozilla Developer Network, DeviceMotionEvent.acceleration

  20. W3C, DeviceOrientation Event Specification

  21. html5rocks.com, This End Up: Using Device Orientation

  22. ESP8266 Community Forum and wiki

  23. hackaday.io ESP8266 WiFi Module Library

  24. 2. Get ESP8266 source code

  25. ESP8266 Documents, Firmware

  26. Forum of company espressif for ESP8266

  27. ESP8266 WiFi Module Quick Start Guide

  28. electrodragon, ESP8266 wiki, ESP8266 IC pinout

  29. ESP8266 flashing LUA firmware

  30. LUA nodemcu ESP8266 firmware

  31. Wlan2Serial Modul für 5 euro (German Forum

  32. msxfaq.de, many Links for NodeMCU and LUA (German)

List of pages in this category:

-- RudolfReuter 2015-11-15 17:50:55


Go back to CategoryAVR or StartSeite ; KontaktEmail (ContactEmail)

WiFiCar-NodeMCU (last edited 2016-11-04 18:15:21 by RudolfReuter)