Articles Hierarchy

Articles Home » Arduino Projects » ESP / 8266 / 32 as WIFI Arduino

ESP / 8266 / 32 as WIFI Arduino

connect ESP8266
connect ESP32
PINOUT
flash tool
Arduino IDE ESP8266
Arduino IDE ESP32
all in one

haha, my desk

intro:
i had a small ESP8266 here, still packed,
but now ordered a ESP32
with the idea that i can use it as cheaper wifi arduino

so for the order i tested ( new account / first order ) LAZADA because there was
+ free delivery and
+ ( free ) cash on delivery
and all worked well ( delivery time 4.7 .. 13.7) for about 10 EURO.
see side by side:
old ESP-8266
new ESP-WROOM-32 ( no idea whats the difference to ESP 32S also the boards have that label too)
both with print: NODE MCU

NodeMcu, Wiki ESP12 Wiki ESP32


ESP8266 info and versions
ESP32 spec is old? for my SoC, a other good info is at esp32.net


so even i see some video instructions about using arduino IDE only i want to understand that new world better, what is the default operation.
possibly uploading by Arduino IDE erases default functionality and i would not know what/how to load default again!

the boards have a USB port ( like the arduinos ) to power the board and
there should run a default program where you can configure its functions by AT commands.
ESP8266 from espressif
ESP32 from espressif
The default baud rate of AT command is 115200
AT commands are ended with a new-line (CR-LF)
, so the serial tool should be set into "New Line Mode"


basic AT commands:
AT __ to check communication
AT+GMR __ to check version
AT+RST __ to reset and see boot info
AT+SYSRAM __ to check RAM

so all i need is a PC ( start with win7 PC ( later RPI )) and a terminal emulator ( start with Arduino IDE or HTerm ) and a USB cable.
for the USB port might need to take a look at
win7 / computer management / device manager / ports (com&lpt) /


connect ESP8266
at first connect ESP8266 a blue LED near wifi antenna blinks 2 times.
first there is no USB response, try again? USB connector..


USB chip? 340 (G or C )
download driver: WCH run CH341SER.EXE

replug ESP8266 and see


OK
AT+GMR

AT version:0.21.0.0
SDK version:0.9.5

OK
AT+RST


OK

ets Jan 8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x40100000, len 816, room 16
tail 0
chksum 0x8d
load 0x3ffe8000, len 788, room 8
tail 12
chksum 0xcf
ho 0 tail 12 room 4
load 0x3ffe8314, len 288, room 12
tail 4
chksum 0xcf
csum 0xcf

2nd boot version : 1.2
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size : 4Mbit
jump to run user1

;l⸮C⸮
Ai-Thinker Technology Co. Ltd.

invalid


i press the buttons but can not force a reboot?

try tablet WIFI

check IP with FING

try browser



connect ESP32
at first connect ESP32 a red LED ?pwr? is ON
i see after some seconds a device driver install error? and a
"Other devices" CP2102 USB to UART Bridge Controller but no port??

from silabs i download a zip file ( for my win7 ) CP210x_VCP_Windows.zip 3.8MB and find a CP210x_VCP_Windows\CP210xVCPInstaller_x86.exe for my win7 32bit OS

and now after replug the ESP32 i see com25

with HTerm COM25 connect 115200 / 8 / 1 / n/ send CR LF see
AT
:>what?
AT+GMR
:>what?

ok, the "what" seems to be related to "NL", so "CR" is ok and on "?"
get ( this time using Arduino monitor )

now i type "op -Q"
:>op -Q
+CURMODE:2
+MODE:OK
:>sta -Q
+JAP:DISCONNECTED
:>sta -S
+SCAN:ERROR,1

so what did i do? here i found a
SSC Command Reference Parameter Description
-Q Query Wi-Fi mode.
-S Set Wi-Fi mode.

There are 3 Wi-Fi modes:
mode = 1: STA mode
mode = 2: AP mode
mode = 3: STA+AP mode

that is something, so here is not the AT command set loaded,
instead ( RTOS with ) a SSC set
with a missing documentation on "?" or "help"
LOL "rudi" had the same problems here
i have no idea, who loaded that SoC ?espressif" default ESP-32-wroom-32 setup?
or the unknown board producer?
also try from RPI3, this time no driver problems,


now i try use HTERM and press the down left ( of usb port ) button and see that boot msg with very cryptic version system.


a other basic thing ( besides the USB port AT operation "menu" ) is:
the boards should start already as kind of webserver ( or it could be configured and enabled by AT commands ) and then operated via WIFI, the LUA world!

yes, as i now find ( above linked boot log ) and modeinfo AP
there should be a AP: Access Point ( in the air ) i see ESP_81C0A0 from my tablet.
but HOW TO USE?
here i see that with a ESP8266 ( what software loaded?) you can connect a phone to the AP ( in that version was a password? i did not need )

and start browser to http://192.168.4.1 or http://192.168.4.1/read
that did not work for me.


so, in both cases my tablet browser could not get a webpage from the AP, i might have a different problem, should try a other device and browser, well also not lucky, laptop see the AP, can connect
( and see in link details that bytes are flowing both directions? )
but 2 browser can not connect to 192.168.4.1


PINOUT
ESP8266

ESP32
so still i not find documentation of the board, maker ...
and esp. PINOUT.
compared to many boards with good documentation online,
they have that stupid form factor like the ESP8266 board, 2 pin wider so fit exactly on a breadboard ( means no empty rows left for cable outside the board ( only under the board cables possible )
but the small board also has a disadvantage, there is no space on top for a pin labeling, but i see backside:

so i can search for a fitting pinout. I see that board also at aliexpress where it is indicated as Brand Name: ROBOTLINKING ( wholesale?)
i try my own PINOUT because the front/back thinking is difficult, even on breadboard.
pls see also / copy from / my google sheets updated version!



flash tool
but already at the beginning of ESP i read some story that there where boards without firmware, that for loading a capacitor was missing...
and pressing ( and its timing ) of the "flash" button on the board... not jet find info.

there is a (windows) tool you can download to flash the boards,
espressif git download area or
website



so now i would need something to UPLOAD.


( this BLOG is not following always the timeline / my working style is chaotic )
as i still miss the LUA world i follow Peter Jennings
and download ESP8266Flasher.exe for Win32 and NodeMcu firmware or newer?
but i understand the flasher comes with a default ( possibly older as the new firmware )
i try a flash and it looks ok, connected a terminal and see no response ( at 9600 or any other db rate ).

Selecting the new firmware not possible as there is no .bin file in the zips,
first need a compilation?
or find the newest AT bin files from espressif

but i could try anyhow the LUA LOADER (what can also call the ESP8266Flasher after you show him the path )




a more complex new environment should be platformio.org also find a ref. here.
i got confused by all that options, looks like there is a LOGIN ( only possible / needed )
when you buy the PRO version? but also there is a register/login at the community forum what is not connected with the login in the IDE.
also i selected/followed the ATOM editor ( its the main part ) and very big download.






later more...


Arduino IDE & ESP8266 ESP and Arduino IDE
for ESP8266 i follow here what points to using IDE board manager
-1- change preferences

-2- get the tools

-3- select board in IDE

-4- does board info work?

-5- make a info sketch and upload

did you see, the upload was 228kB big??
-6- start the monitor

ahm that works only one time after upload, reload monitor and press down left button "user" ( blue led goes ON now) or down right button "flash" not reboot board / with this not print that info again.
-7- a check with wifi tablet now show new AP, still no webpage.

so i was right, a upload of a empty sketch by arduino IDE change the whole thing, the Ai-Thinker thing is gone, the AT menu lost, the AP config changed but still not work for me.


next step: i see here a arduino sketch for use ESP8266 IO and webserver.
i not like he connect a LED without resistor? to ESP8266 P7 aka arduino pin13 / default blink program/
but i try his webserver / remote led operation program.
- arduino IDE ( i needed to rename path and ino file / kill the spaces )

- browser, firefox give me some IP search B.S.,
IE9 and google chrome (Version 59.0.3071.115 (Official Build) (32-bit)) ok

- and the log in the arduino IDE monitor

no hardware led connected, not check on the GPIO output for real operation, but its ONLINE.
with small beauty work

looks like

code: git


Arduino IDE & ESP32
for ESP32 see Installation and here and win10 and here
looks like the installation is more difficult, as no board-manager support ready up to now.

-1- newest arduino ( i have already )

-2- install git tool
from git download Git-2.13.3-32-bit.exe ( and test for old win7 32bit ) found a git-bash icon and found git-gui ( and make also a link to desktop ) and start.




-3- according manual i created subdirs:
X:\...\arduino-1.8.3\hardware\espressif\esp32\
and i noticed that there is no esp8266 ? where that boardmanager installation ended up?
c:\Users\...\Documents\Arduino\libraries\ also nothing

anyhow i try and got a error "target directory already exists" so deleted the /esp32/ path and now it worked and it is been created again...
finding the second step with the double click on git.exe to get the "tools"
again not that easy, a start by command line ended in a error.


-4- start arduino IDE, board select ( section: ESP32 Arduno ) i select "NodeMCU-32S" ( a strange upload speed is preselected?? )
plug in the board find COM25 and try "get board info" for com test.
start monitor and see the boot msg.


-5- i selected the WIFI scan example, the first upload failed, the second
ended with a msg "hard resetting" and i was (wrong) thinking that i need to play with that 2 buttons but nothing show up.
anyhow i restart usb connection and IDE and got the same msg. And when i opened the monitor i see the wifi scan results ( my wifi neighborhood )
OK i am in the game.
also run the simplewifiserver example with some changes.
But with this example and with my modified server from ESP8266 i got many upload fails, but no idea if that's (board or USB ) hardware or software related.


now i work on the webserver with IO operation but run into serveral problems:
-- i need up to 5 uploads until lucky finish,
-- the logic in the simplewebserver example is strange / possibly wrong
while the old ESP8266 webserver i used finally runs here also.

BUT i must check if there ever is a change on the output pin!
OK OFF is 0V, ON is 2.8 ..3.2 V

code: git


all in one
coming next? ESP32 Din Ain Aout test via webserver
also check on these AP examples here and here if i can ever call AP in a browser ( as for STA ( by above arduino IDE examples) it works very good.)

First i start with a version where i can select the board type by compiler switch:
#define useESP32 // or disable with // for ESP8266

#if defined useESP32
#include < WiFi.h >
const int DoutPin = 5; // P5
const int DinPin = 12; // Digital pin to be read
#else
#include < ESP8266WiFi.h >
const int DoutPin = 13; // GPIO13
const int DinPin = 12; // Digital pin to be read
#endif


Now while the Ain "A0" for ESP8266 is a 1V 1024 : 10bit ADC
is for the ESP32 adjustable resolution
The full-scale voltage is the voltage corresponding to a maximum reading (depending on ADC1 configured bit width, this value is: 4095 for 12-bits, 2047 for 11-bits, 1023 for 10-bits, 511 for 9 bits.)
ESP32 ADC
DAC1 ADC18 P25 Aout1
DAC2 ADC19 P26 Aout2
a 2.6V 255 : 8bit DAC
ESP32 DAC
and the first test of it:
#if defined useESP32
dacWrite(25,127); // 50% output
s += ("AoutPin "); s += ("DAC1"); //DAC1 ADC18 P25
s += (" : 127"); s += ("
");
#endif


i also changed the Arduino IDE ESP32 Upload speed down to 115200 and it works much better.

so for ESP8266 now with Din, Dout, Ain:

and for ESP32 with Din, Dout, Ain, Aout:


i tried a version with FIX IP in STA MODE but failed.
and try to make it compiler switchable between STA and AP MODE also failed,
if ever the original unusable AP was created.
but i know there are #include errors inside #if defined from history
( i had to disable the unwanted libs manually by // )
so i take a step back and used that only, and see that the AP with SSID ( and login) worked, but the site was on 192.168.4.1 / called WIFI and browser open not possible, so the "WiFi.config(ip,gateway,subnet);" did not work with current arduino ide ESP8266WiFi.h.


let's dig into that libraries,
-a- while esp8266wifi.h is a good name wifi.h ( from ESP32 ) is bad, because there are other libraries with that name ( and the compiler needs to choose! (one time, at a error condition i see info print that he choose the correct one) )
-b- remember we install esp8266 lib with the boardmanager so i find that lib at
c:\Users\myuser\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src\
and for ESP32 we made the subdir \espressif\ inside the IDE
mydrive:\mypathto\arduino-1.8.3\hardware\espressif\esp32\libraries\WiFi\src\
now i try again using info from example
c:\Users\myuser\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\examples\WiFiAccessPoint\WiFiAccessPoint.ino
and the AP webserver / open by mobile browser / worked first time:

now try to find the correct way to config AP fix IP ( other than the default 192.168.4.1 )
// WiFi.mode(WIFI_AP); //switching to AP mode ? why not need?
WiFi.softAP(ssid, password);
WiFi.softAPConfig(APip,APgateway,APsubnet); // tricky: config should be after begin
// WiFi.begin();
// WiFi.config(ip,gateway,subnet); // tricky: config should be after begin


code: git
start to combine it into one tool,
i already see the webpage with fix ip in AP mode on the mobile, but not the picture?

test for ESP32 AP mode fails at ( after )
WiFi.softAPConfig(APip,APgateway,APsubnet);
even it makes that IP, but server can not start. so a small delay between
WiFi.softAP and WiFi.softAPConfig ( for ESP32 only ) helped.


also make a small Analog function test:
ESP32
P25 DAC1 and P36 ADC0 connected (and also multimeter )
and operated via [up][down] web page buttons
output 255 (max) give 2.8 .. 3.2 VDC and indicated 2800 .. 4095 on ADC0
output 126 (50%) give 1.6 .. VDC and about 1200 .. 1800 on ADC0
possibly ADC0 ( SVP) not the best channel if ADC3 (SVN) is floating?
i also jumper Din and Dout ( here P5 and P17 ) to see response on web operation



i used RPI3 and install boardmanager ESP8266 get code from my github
upload ok, start NOT.




code: git


and this is what i am up to in the long run: MQTT