This is a very old question, ever since Espressif removed the 5V tolerant statement from their datasheet no one felt safe connecting 5V directly to the digital input pins, but the news is out now, according to the CEO of Espressif himself, their boards are indeed 5V tolerant ON THE DIGITAL INPUT PINS
What pins are 5V tolerant exactly?
The IO pins in input state (sink) are 5V tolerant, Yet the power supply to the chip must be 3.3V (Most boards come with a regulator for this so it should not be a problem). other models do not come with a regulator, and in such a case, you will need to add the regulator, but even then you do not need a level shifter for the digital inputs. for the ESP32, The ones without an onboard regulator usually go for as little as $2.5 (5 boards for $12) , while the ones that come with a voltage regulator and a serial to USB adapter will set you back around $4.6 (3 for $14)
When pins on the Espressif microcontroller are set as output, they will use 3.3V logic, whether or not the difference in voltage between high and low will register on the other microcontroller/device is an issue related to the other microcontroller, from my experience, Arduino Uno works just fine.
Also note that analogue pins are a different story, the ADC pins use the power provided to the chip as a reference voltage. so a voltage divider is still required.
so in short, if you connect the 5V supply to the VIN pin (going through the onboard regulator), and use 5V logic on the digital pins while they are in input mode (Sink) you should good, and this is not just me, this is an official statement.
You may be wondering why is it not the in datasheet then ? The answer is, it used to be in the datasheet, but the company faced problems with people powering the chip itself with 5V so they omitted it to avoid confusion,
This is excellent news for someone like me who has to go through the hassle of logic level converters whenever coupling Arduino with ESP chips.
Before the CEO of the company made those statements, many people did their own experiments and found those results, but there were still doubts as to whether the results were conclusive or whether there was more to the story, a convincing experiment by ba0sh1.com did demonstrate that it was indeed 5 Volt tolerant on the input pins,
Where did i get this from
Swee-Ann Teo, who after my research seems to be from Espressif made the following statements
On whether ESP8266 is 5V tolerant, he had this to say on a facebook post by hackaday
“i can reply officially here: it is 5V tolerant at the IO. while the supply voltage is at 3.3V.”
On whether ESP32 and ESP8285 are also 5V tolerant
“ESP32 and ESP8285 are both 5V tolerant as well. but for ESP32, it is a very complicated matter. it supports 1.8V operations too… i don’t know where to start…”
When asked why this information is not in the datasheet, he responded
“the reason is too many users took it to mean that the chip is 5 V tolerant. When we say 5 V tolerant, we are only referring to the IOs. So some users mistook this to make that they can power the chip entirely off the 5 V supply. The correct usage is to use 5 V open for these 5 V tolerant pins, and only via only drain configuration.” And then elaborated on the matter with “I understand, but the time needed to do the iterations when mistakes were made, was too long. when the product was launched 5 V WiFi modules (with DCDC) were the norm. Many users saw “5 V” written in the specs and thought it could be a 1-1 replacement for such modules.”
One user asked if the tolerance towards 1.8 volts of the ESP32 was relevant to enabling battery operation, the response was no, specifically, Teo responded with
“actually not. but many memory devices are moving towards 1.8V operations, and we would be compatible with them as well.”
Even though this looks like a long post, I have composed it for a friend and unlike mostly everything else on this blog, this is not just for my own reference, so it should be easy to follow and understand (I hope).
What for ?
This is a very valid question, Why would i use a slower Arduino and connect it to WiFi using an ESP8266 you ask, why not just use the ESP8266 or even ESP32 as both the WIFI and the microcontroller to run our code? There are many situations where you would want to, the most common of which is the analogue and digital pins on an Arduino board, the friend I am writing this tutorial for is looking to use the 50 digital pins on an Arduino Mega Pro Embed as select lines for 50 Arduino pro mini boards, another might be the analogue pins on an Arduino (8 or 16 depending on the board), so digital and ADC pins on an Arduino might be needed.
You might ask why not an ESP32, it has a bunch of digital and analogue pins, the answer is that sometimes they are not enough, especially when you find out that the analogue pins on the ESP32 are divided into 2 groups, one of them is not usable if you enable WiFi.
Another valid reason is all the shields that have Arduino libraries but those libraries do not function with ESP, which is probably even more common of a problem than the pins problem.
So in short, even though the need might not arise very often, it does exist.
The ESP8266 as an Arduino WIFI shield
Arduino does not come with WiFi, there are shields from Arduino that provide WiFi, and those shields are based on ESP8266 which is a very cheap WiFi enabled microcontroller. but there is nothing stopping you from using any ESP8266 board and connecting it to your Arduino,
Which one: They should all work, and you probably already have one since you are here, I am personally using the slightly more expensive $4.6 boards that come with a USB-TTL chip and power regulator built in, if you want to use the cheaper boards (esp8266-01), you might want to connect it to the 3.3V output of your Arduino, but you will still need a level shifter, I would expect you also have a UART USB to serial board.
Price: models from the 01 ($2.5 each when you get 5 boards for $12 ) up to the 12E or 12F ($4.6 each when you buy them as 3 for $14). not bad for a WiFi enabled microcontroller !
Communication between Arduino and ESP8266
Arduino can talk to the shield either via UART or via SPI (Given the libraries written for this), SPI is up to three times faster than UART, but most of the time your application, be it sensor data or the like, will not be able to flood any of those 2 buses, In this post, I will cover both, SPI first then serial.
The components (hardware)
1- ESP8266 (Any variant should do) 2- Logic level shifter, since Arduino is 5V and ESPs are 3.3, I have been told that the ESP 12E and 12F are 5 volt logic tolerant, but I would think going with a logic shifter might save me something down the road, hours of debugging, or a new board, or something i fail to foresee 3- An Arduino, I am using a mega, but an UNO should do just fine (I will cover it) 4- Wires to connect all the above, and probably a breadboard (I like to solder things to a universal PCB board, but not everyone likes to do this) 5- A power supply, in my case a couple of micro USB cables and a 5V source that is my a power supply.
Software on the ESP8266
1:SPI: If you are going with SPI, you will need to flash JiriBilek / WiFiSpiESP onto your ESP8266, fortunately, this comes with an ino file that you can use your Arduino software to flash directly
2:UART-Serial: If you are going with serial, you might want to go with jeelabs / esp-link, mind you, Arduino themselves forked this before for their own WiFi shields, but since then, the jeelabs esp-link has added many features, so i would recommend you go with the original jeelabs.
Software on Arduino
1:SPI: if you have installed the SPI software from above on your ESP8266, the accompanying Arduino software would be JiriBilek / WiFiSpi, The library implements almost the same functions as the Arduino WiFi library.
2:UART-Serial: there is no library to go with this case that is beyond your regular serial bus if you want to exchange serial info, so if this is a 3D printer, software on your PC should be able to translate the data into serial, and it would be transparent, but what if you want to use WiFi from within Arduino, like a client that downloads pages or sends post data to pages,
Choice of UART-Serial vs SPI
UART-SERIAL, has certain advantages and disadvantages, with serial, i can simply update the software on the Arduino over the air over WiFi, I can get serial messages and use WiFi at the same time both as client and server, SPI on the other hand is faster, but it is not out of the box compatible with serial messages. Another disadvantage of SPI is that it needs a bit of extra code to allow the board to boot
Implementing WIFI over SPI
SPI – The hardware, how to connect
The H.SPI (On the ESP8266) is connected to the SPI on the Arduino like you would connect any SPI bus, with the addition of a logic level shifter (Red part in the photo), We connect Clock to clock, Slave select to select line, MOSI to MOSI and MISO to MISO, there is nothing to it. I have added a table for the Uno (Same for Arduino Pro Mini) and the Mega for your convenience
Now assuming you are done with the connection above, it is time to load some software.
SPI: Installing the WiFiSpiESP on the ESP8266
First, we need to load the software to ESP8266, the JiriBilek / WiFiSpiESP comes with a .ino file, so all you need to do is load that into Arduino studio, connect your esp8266, compile and upload, now this part is done, no modifications are needed to this code since all the control is passed on to the Arduino, compile and upload.
If you are having trouble uploading the code or selecting the board, my 12E board works in Arduino studio as NODEMCU V1.0, if you don’t have any ESP8266 boards in your boards list, you will need to add it, there are many tutorials on using Arduino with esp8266.
SPI: software on the Arduino
On the Arduino side, you will have to include the library (WiFiESP), then include it in your code, the library should be readily available in your libraries menu of your Arduino Studio.
NOTE: Both the library and the software you installed on your ESP need to have the same release number (0.2.5 at the time of writing) or it would not work, the software is hard coded not to work if they don’t match, you will be presented with the error (Protocol version mismatch. Please upgrade the firmware) in your serial console during runtime, I know this because a couple of weeks ago, I contacted the author (Jiri) through GitHub, and he brought both versions of the software and the library current so that they would match, it was a small thing but if you ever get this error in the future, you know where to go, he was quick to fix it within hours.
Now to the Arduino code, inside the library, there are examples, all you need to do is upload one of those examples, most likely, you would want to start off with the WiFiWebClient, this example that comes with the library needs to be modified in two locations, the first is the credentials to your WiFi, and the other is to change the server you are connecting to from www.example.com to wherever that web server is. this should get you started on most projects.
In my case, I have had to modify a few things in the script to make it work, first of all, a short delay needs to be inserted before we check if the WiFi is connected, the other is to not have it die but rather try again if it is not for a set number of times
WiFi using UART-Serial
UART-SERIAL should be the as easy, I should be back here
The ESP8266 has a TX and RX pin that should be connected in reverse to the ones on the Arduino, RX (Receive) should be connected to send, and send to receive, both boards need to share a common ground (reference voltage), and an Arduino mega should be able to provide 3.3 volts with sufficient current for the ESP8266 if you plan to power the ESP from the MEGA, if you have an ESP8266 with an onboard voltage regulator, you can simply add it to the power supply directly through the VIN pin (rather than the 3.3V pin)
Simple IOT project of the day, a super simple IOT home electric meter / record keeper, without a need to modify anything at home.
Before you Start – This is very simple hands on
What is it – It’s a home electric meter that counts in both directions
What is it for – Keeping track of power consumption
How it is done – A clamp meter and a microcontroller board
Show me before i begin – A photo gallery
Components – What you need
Steps – steps to making the device
Before you start, you only need the first few paragraphs to construct this device, the rest of the blog post is simply an explanation of why we did things this way, the whole tutorial should be very simple to follow step by step. Photos of everything you need are also provided 😉 If you know how to solder, you can get through this. if you don’t, find a tutorial on YouTube on how to solder.
What is it
It is a simple always on clamp meter that keeps track of power consumption on a small server (Online, or at home), added in the same cabinet as the utility meter installed by the power company.
What is it for
Since this device allows me to continuously keep track of power consumption, and graph it, I can track down things that are not functioning as they should and drawing much more electricity than they should.
The idea was inspired by the fact that my water cooler was drawing way too much power, and it turned out that it was heating the water it cooled and cooling the water it heated ! so it was basically “on” for far longer periods than it should, the fault turned out to be a loose plastic piece in the cooler’s water tank.
How is it done
A cheap current transformer (Clamp) is attached to a microcontroller that is WIFI enabled, the microcontroller sends the readings to a server in the basement (That server is used for 1001 other things too).
Show me before i dig in
Here is a small gallery of everything you might want to see before you even begin !
NOTE: This tutorial will show you how to do this with an ESP32 board as well as my own setup which is a combination of ESP8266 and Arduino pro mini
The components I chose here are mostly because i already have them lying around, if you are going the ESP32 route, I will cover it too.
2 current transformers to take readings for 2 electric meters, in this example, they are the sct013 100A / 50mA
2 Microcontroller boards, an esp8266 (esp8266MOF-12E) and an Arduino pro mini 3.3V (8MHz) (ESP32 is also covered as a single board)
A lousy 5V phone charger that is not capable of providing enough current to charge a modern phone in a timely fashion, but should do for this as long as we have a voltage of above 4.1V.
An LD33CV voltage regulator combined with 2 capacitors (10V – 680uF) each.
1 x 10uF capacitor
An 23.34ohm resistor (Either series resistors or step down) as a burden resistor if you are using 3.3V board such as ESP8266 or ESP32, or a 35.36 ohm resistor if you are using a 5V board. if the values can’t be made with resistors in series, you need to go DOWN with the value to the next resistance value
2 SCT013 – 100A – 50mA current transformers
A pair of equal resistance resistors as a voltage divider, the values are anything between 10 kΩ and 400 kΩ (The smaller is more precise, the larger resistance consumes less battery)
A 5CM x 7CM Universal PCB Board
And obviously you need to use a soldering iron unless you wish to use a breadboard.
IMPORTANT: I recommend you use 1 ESP32 board instead of my setup, and use the analogue inputs on that, AND SKIP MUCH OF THIS BUSINESS, one thing to note though is that the ESP32 has one of it’s 2 ADC channels disabled when WiFi is enabled (A channel with X Analogue pins), I will cover this so don’t worry.
So why did i make it with an Arduino pro mini (3.3V) and an ESP8266 connected together in SPI (Against my own recommendation) ? that is because i got those current transformers and went to sleep, by the time i woke up, it was 12:43AM, I woke up and decided on the project, and those are the parts that were at hand that very minute, the Arduino has 8 usable analogue inputs (for sensing the current passing through the current transformer) , The ESP8266 on the other hand has 1 analogue pin and i wish to connect 2 clamp meters to this board
The Arduino pro mini (or any other using the ATmega328 micro controller) only has 6 ADC pins available instead of 8 if you use I2C as 2 are for I2C
Now, let us get to making it, this project takes a few hours to make, and you might want to change some things as i don’t think you need to have 2 microcontrollers connected together in SPI (I don’t remember why i chose that over I2C).
I won’t get too much into why I am using these resistor values, Just use them. Hint: the reason for the choice is obviously ohm’s law, once for telling the current from the voltage drop using the burden resistor, the other two are a simple voltage divider (use an online voltage divider calculator if you need something different)
Step 1: Cut the endings of the SCT013current transformers to expose the wires, in my case, he SCT013-50mA came with a audio stereo jack, the tip (usually left speaker) was connected to the white wire, the sleeve (usually ground) was connected to the red wire, and the ring (middle usually right speaker) was not connected to anything, the shield on the wire exists but is not connected to any pins on the jack side.
What we need to connect in this case above is the white wire (tip) to the center of the voltage divider, and the red wire to the analogue input pin of the Arduino, the sleeve of the cable which is not connected to anything on any side should be connected directly to the ground pin of the Arduino .
Now, to see the connections, you might want to inspect this photo, I have used Photoshop to make it clearer and to point out where components are connected.