Differences between revisions 1 and 2
Revision 1 as of 2015-12-06 21:20:11
Size: 22461
Editor: RudolfReuter
Comment: new
Revision 2 as of 2015-12-15 20:09:13
Size: 0
Editor: RudolfReuter
Comment: ready to publish
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
##master-page:DockStarTemplate
#format wiki
#language en
||<tablestyle="float:right;margin:0px;"style="padding:0.5em;border:0px none;font-size:100%;"><<TableOfContents>> ||


== WiFi Logger OneWire ==

Since May 2015

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|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|Links #4]].
||<tablestyle="float:right;">[[attachment:Doit_Car_DSC06296.jpg|{{attachment:Doit_Car_DSC06296.jpg|attachment:Doit_Car_DSC06296.jpg|width="320"}}]] ||




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|Links #5]]. The '''firmware API''' description you can find at [[#Links|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|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|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.
||<tablestyle="float:right;">[[attachment:DoitCar_Android.jpg|{{attachment:DoitCar_Android.jpg|attachment:DoitCar_Android.jpg|width="180"}}]] ||


=== Doit WiFi car ===
It was developed from http://www.doit.am/ (Shenzhen Doctors of Intelligence & Technology). An introduction can be found at [[#Links|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''':

 * SDIO 2.0, SPI, UART
 * 32-pin QFN package
 * Integrated RF switch, balun, 24dBm PA, DCXO, and PMU
 * Integrated RISC processor, on-chip memory and external memory interfaces
 * Integrated MAC/baseband processors
 * Quality of Service management
 * I2S interface for high fidelity audio applications
 * On-chip low-dropout linear regulators for all internal supplies
 * Proprietary spurious-free clock generation architecture
 * Integrated WEP, TKIP, AES, and WAPI engines

For more details please see at [[WiFi2AT-ESP8266]].
||<tablestyle="float:right;">[[attachment:ESP-12E_DSC06304.jpg|{{attachment:ESP-12E_DSC06304.jpg|attachment:ESP-12E_DSC06304.jpg|width="320"}}]] ||




=== ESP-12E module ===
The most versatile module with printed PCB antenna, see also [[#Links|Links #10/11]]:

 * 22 x 2.54 mm pitch header
 * built-in PCB-printed antenna
 * 18 IOs
 * 4 MByte Flash ROM
 * LED, blue on GPIO2
 * VCC/GND 3.3 V
 * Dimensions: 24mm x16mm x 3mm

{{{
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!
}}}
||<tablestyle="float:right;">[[attachment:ESP_NodeMCU_DSC06305.jpg|{{attachment:ESP_NodeMCU_DSC06305.jpg|attachment:ESP_NodeMCU_DSC06305.jpg|width="320"}}]] ||




=== 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|Links #12]]. In short some details:

 * NodeMCU = '''ESP-12E !DevKit'''
 * Support STA/AP/STA+AP 3 working modes
 * 0~D8, SD1~SD3: used for GPIO, PWM, IIC, ect; the driven ability can be arrived at 15mA
 * LED, blue on GPIO16, for debug purpose
 * AD0: one-way ADC, 0 to 1.0 V, 10 bit = 0..1023
 * Power input: 4.5V~9V(10VMAX), support USB powered and USB debug
 * Working current: ≈70mA(200mA MAX, continue), standby<200uA
 * Support update firmware remotely (OTA)
 * Size: 25.4 x 48.3 mm
 * Firmware supports LUA programming language

Wikipedia has some information, at [[#Links|Links #13]].

The official '''user manual''' is at [[#Links|Links #12]].
||<tablestyle="float:right;">[[attachment:ESP-NodeMCU_motor_DSC06309.jpg|{{attachment:ESP-NodeMCU_motor_DSC06309.jpg|attachment:ESP-NodeMCU_motor_DSC06309.jpg|width="320"}}]] ||




=== 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:

 * Motor power supply (VM): 4.5V ~ 36V, can be powered separately
 * Control power (VIN): 4.5V ~ 9V (10VMAX), can be powered separately
 * Logic Operating current Iss: ≤60mA (Vi = L), ≤22mA (Vi = H)
 * Driver IC: L293, drive = PWM (Pulse Wide Modulation)
 * Drive part of the work current Io: ≤1.2A
 * Maximum power dissipation: 4W (T = 90 ℃)
 * Control signal input level: High: 2.3V≤VIH≤VIN; Low: -0.3V≤VIL≤1.5V
 * ESP12E Dev Kit Control Port:
  * GPIO0: Motor DirA, Button FLASH; GPIO5: Motor PWMA
  * GPIO2: Motor DirB; GPIO4: Motor PWMB
 * The '''screw terminal''' is labeled with the signal names.
 * The '''push button switch''' connects '''VIN''' to the board.

For the '''user manual''' see at [[#Links|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.


||<tablestyle="float:right;">[[attachment:wifi-car_encoder_DSC06314.jpg|{{attachment:wifi-car_encoder_DSC06314.jpg|attachment:wifi-car_encoder_DSC06314.jpg|width="320"}}]] ||
=== 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''':
 * Motor wheel diameter: about 70 mm
 * Motor wheel circumference: 70 mm x 3.1414 = 200 mm
 * Encoder step distance: 200 mm / 20 = 10 mm
 * Signal to ESP-12E: EncA - GPIO12, EncB - GPIO13
Next step in the development is to '''drive distances''', with the help of the encoders.

=== Community Forum and Wiki ===
There is a ESP8266 Community Forum and wiki at [[WiFi2AT-ESP8266#Links|Links #22]]. I will mention important postings.

 * [[http://www.esp8266.com/viewtopic.php?f=5&t=7|What we know so far]]
  * how is the code in the spi flash executed? is it memory mapped? or copied to (D)RAM?
   * Copied to DRAM on reset
  * The SoC is built around the Tensilica Xtensa LX3 processor (see the compiler info in the library binaries)
  * The CPU is clocked at 80 MHz (esp_iot_sdk_v0.6/include/eagle_soc.h, line 58)
  * hackaday.io info, see [[WiFi2AT-ESP8266#Links|Links #23]]
 * [[http://www.esp8266.com/viewtopic.php?f=9&t=430&sid=2b837f9334ff3110d77718cac81cb7b6&start=30|Official GCC compiler VM from Espressif]]
  * Alternative: [[https://github.com/pfalcon/esp-open-sdk|github esp-open-sdk]]
  * [[https://github.com/themadinventor/esptool|esptool.py for flashing ESP8266]]
 * [[http://www.esp8266.com/viewtopic.php?f=5&t=245|Wireless Througput Tests with netio]], about 20 KB/s RX.
 * [[http://www.esp8266.com/viewtopic.php?f=5&t=28|ESP8266 WiFi Module Pinouts]]
 * [[http://www.esp8266.com/viewtopic.php?f=5&t=744|Video Guide for compiling your own programs on the ESP8266!]]
  * [[https://www.youtube.com/watch?v=pWo-ErpVZC4|Youtube video, and useful links]]
 * [[http://www.esp8266.com/wiki/doku.php?id=connect_to_esp8266_only_using_arduino_uno|ESP8266 connect to Arduino]]
 * [[http://www.esp8266.com/wiki/doku.php?id=getting-started-with-the-esp8266|getting-started-with-the-esp8266]]
 * [[https://www.youtube.com/watch?v=tGsYwtpgETY|Youtube, LUA firmware einrichten (German, 31 min, 2015-01-17)]]

||<tablestyle="float:right;">[[attachment:wifi-car_software.jpg|{{attachment:wifi-car_software.jpg|attachment:wifi-car_software.jpg|width="540"}}]] ||


=== 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|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:

 * The '''Javascript program''' needs to be downloaded from a web server, in the run. That means, you must have an '''online connection''' to the Internet. For development purpose that is welcome, but for normal operation it is cumbersome.
 * The !WiFi-car control is difficult, because the motors starts turning from above 600 (control range 0..1023) on, and stop at below 300. This was not taken into consideration.
 * In the speed calculation I found a bug (Math.min).
 * The call of the Javascript program must be at the end of the HTML statements.

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.

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.

=== 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 '''ESP8299 Arduino Core Reference API''' is described in [[#Links|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.

 * Function '''handleFileCreate()''' - will create an empty file in SPIFFS for later editing, but is not used here. See for more details `Arduino/hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino`.

 * Function '''handleFileDelete()''' - will delete a file in SPIFFS. If a leading "/" is missing, it will be added.
  * call syntax: http://<URL>/delete?filename=<filename>

 * Function '''handleFileList()''' - list the files in SPIFFS, and send them back to the web browser as JSON array.
  * call syntax: http://<URL>/list?dir=/
  * Example output: [{"type":"file","name":"wifi-car.js"},{"type":"file","name":"data/wifi-carAP.js"},{"type":"file","name":"data/edit.htm.gz"},{"type":"file","name":"data/graphs.js.gz"},{"type":"file","name":"data/index.htm"},{"type":"file","name":"data/favicon.ico"}]

 * Function '''handleFileRead(String path)''' - Read (shown in web browser) the specified file from SPIFFS.
  * call syntax example: http://<URL>/wifi-carAP.js

 * Function '''handleRoot()''' - This loads (web browser) the file '''index.html''' for the car application.
  * call syntax: http://<URL>/

 * Function '''handleMotor()''' - This function decodes the '''motor drive data''' (XML) from the Javascript program (running in web browser), and feeds the data to the '''IO ports'''.

 * Function '''setup()''' - Initialization
  * The blue LED is flashed for 100 ms, to show the start of the program.
  * The '''!WiFi Access Point''' is started, or in '''Station Access''' mode the '''!WiFi router''' is connected.
  * The '''function handles''' for the web access are setup.
  * The GPIOs are initialized.
  * The SPIFFS content is listed on Arduino Serial Monitor.
  * The SPIFSS info is shown on Arduino Serial Monitor.
  * Next, the '''upload command''' is handeled:
   * The handler for the command '''http://<URL>/upload''' sends to the web browser a HTML form '''serverIndex''', to select the filename for upload. This is usually done from a '''PC''', not from a smart phone.
   * ESP8266WebServer function '''onFileUpload()''' - When you click in the HTML form '''serverIndex''' on the button '''Update''' this function is started, and writes the file to SPIFFS, in peaces of 2048 bytes. An already existing file with the same name will be overwritten.
   * After finishing the file write the handler '''server.on("/update", HTTP_POST''' is called to report '''success or Fail''' to the client. Then a SPIFFS file list is shown on Arduino Serial Monitor.
  * The blue LED is flashed for 300 ms, to show the end of initialization.

 * Function '''loop()''' - That is the main loop of the program, it just takes care of the '''HTTP traffic'''. All other functions are '''event''' driven.

Show/Download [[attachment: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|Links #16]]. The update rate of the accelerator sensor is about 20 ms, see also [[#Links|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 [[attachment:wifi-carAP.js]]

=== Links ===
 1. [[http://www.smartarduino.com/2wd-wifi-rc-smart-car-with-nodemcu-shield-for-esp-12e_p94572.html|2WD L293D WiFi RC Smart Car with NodeMCU + Shield for ESP-12E based on ESP8266]]
 1. [[https://de.wikipedia.org/wiki/ESP8266|wikipedia.de - ESP8266 (German)]]
 1. [[https://www.mikrocontroller.net/articles/ESP8266|www.mikrocontroller.net - ESP8266 Info (German)]]
 1. [[https://en.wikipedia.org/wiki/ESP8266|wikipedia.org - ESP8266 modules]]
 1. [[https://github.com/nodemcu/nodemcu-devkit|NodeMCU, pinout, schematic]]
 1. [[https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en|NodeMCU firmware API 0.95]]
 1. [[http://www.smartarduino.com/nodemcu-motor-l293d-shield-board-for-esp-12e_p94570.html|Motor Shield Board (L293DD) for NodeMCU from ESP8266 ESP-12E]]
 1. [[http://www.doit.am/|Shenzhen Doctors of Intelligence & Technology]]
 1. [[https://smartarduino.gitbooks.io/user-manual-for-wifi-car-by-nodemcu-doitcar-/content/|Doit WiFi car manual]]
 1. [[http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family#esp-12-e|ESP-12E module documentation]]
 1. [[https://www.adafruit.com/products/2491|Adafruit.com, ESP-12E specification]]
 1. [[https://smartarduino.gitbooks.io/user-manual-for-esp-12e-devkit/content/schematics_for_esp-12e_devkit.html|NodeMCU manual (ESP-12E)]]
 1. [[https://en.wikipedia.org/wiki/NodeMCU|wikipedia.com, NodeMCU]]
 1. [[https://smartarduino.gitbooks.io/user-mannual-for-esp-12e-motor-shield/content/|ESP-12E motor shield, user manual]]
 1. [[http://blog.squix.ch/2015/09/esp8266-nodemcu-motor-shield-review.html|WiFi-Car control with smart phone orientation]]
 1. [[https://en.wikipedia.org/wiki/Ajax_(programming)|AJAX programming]]
 1. [[https://github.com/esp8266/Arduino|Arduino ESP8266 plugin]]
 1. [[http://arduino.esp8266.com/versions/1.6.5-947-g39819f0/doc/reference.html|ESP8266 Arduino Core Reference API]]
 1. [[https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/acceleration|Mozilla Developer Network, DeviceMotionEvent.acceleration]]
 1. [[http://w3c.github.io/deviceorientation/spec-source-orientation.html|W3C, DeviceOrientation Event Specification]]
 1. [[http://www.html5rocks.com/en/tutorials/device/orientation/?redirect_from_locale=de|html5rocks.com, This End Up: Using Device Orientation]]

 1. [[http://www.esp8266.com/|ESP8266 Community Forum and wiki]]
 1. [[http://hackaday.io/project/2879-esp8266-wifi-module-library/discussion-8592|hackaday.io ESP8266 WiFi Module Library]]
 1. [[http://bbs.espressif.com/viewtopic.php?f=21&t=87|2. Get ESP8266 source code]]
 1. [[http://bbs.espressif.com/viewforum.php?f=21|ESP8266 Documents, Firmware]]
 1. [[http://bbs.espressif.com/index.php|Forum of company espressif for ESP8266]]
 1. [[http://www.labradoc.com/i/follower/p/notes-esp8266|ESP8266 WiFi Module Quick Start Guide]]
 1. [[http://www.electrodragon.com/w/Wi07c#Firmware|electrodragon, ESP8266 wiki, ESP8266 IC pinout]]
 1. [[http://blog.squix.ch/2014/12/esp8266-flashing-lua-firmware-and.html|ESP8266 flashing LUA firmware]]
 1. [[https://github.com/nodemcu/nodemcu-firmware|LUA nodemcu ESP8266 firmware]]
 1. [[http://www.mikrocontroller.net/topic/342240#new|Wlan2Serial Modul für 5 euro (German Forum]]
 1. [[http://www.msxfaq.de/verschiedenes/bastelbude/nodemcu.htm|msxfaq.de, many Links for NodeMCU and LUA (German)]]

=== List of pages in this category: ===
<<FullSearch(category:CategoryAVR)>>

-- RudolfReuter <<DateTime(2015-12-06T21:20:11Z)>>

----
Go back to [[CategoryAVR]] or StartSeite ; KontaktEmail (ContactEmail)

WiFiLoggerOneWire (last edited 2016-10-11 13:57:40 by RudolfReuter)