Arduino to ESP8266 Data With Serial Communication Using Arduino IDE (Mac OSX and Windows)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

But what about voltage levels in the serial line? Isn't the arduino 5V?

👍︎︎ 3 👤︎︎ u/JudgeBigFudge 📅︎︎ Jun 26 2019 🗫︎ replies

I tried this (for bi-directional comm uno<->8266) and experienced issues after a while (i.e. starting losing bytes for some reason)... so I decided to go with I2C instead and it's been reliable.

👍︎︎ 1 👤︎︎ u/can_dry 📅︎︎ Jun 26 2019 🗫︎ replies
Captions
in this video we're going to see how to communicate between an esp8266 Development Board and an Arduino Uno we're going to use the Arduino to collect data from a couple of sensors to measure carbon monoxide and distance we're going to send the collected data upon request of the esp8266 which upon receiving the data is going to display it on a very simple website as usual we'll tinker around with the sensors to see changes and understand how things are working properly alright let's do this [Music] this video is sponsored by jl CPCB they're currently offering a great deal just two dollars for ten prototype PCBs with fast turnaround time they offer a variety of options and the resulting PCBs were great they also offer stencils have great facilities and wonderful people so I encourage you to give them a try for this video we're going to be using an Arduino Uno clone and an esp8266 node MCU deaf kid 1.0 we're going to be using a distant sensor and a carbon monoxide sensor all of which you can find in my little Amazon shop after installing the USB drivers were going to connect both boards onto my computer using different USB ports then I'm going to open an Arduino IDE instance and verify that both USB ports are available because I need to work with two boards at once and to make things easier I'm going to open up the terminal and use the command open to open a separate arduino ide instance that can program the second board in this second instance i will select the board for the node MCU 1.0 and its corresponding port if you're not sure how to do this please go ahead and visit my previous videos i'm going to save this sketch as esp8266 firmware then on the previous instance of the ide i'll go ahead and select the board for the arduino uno and it's corresponding USB port I will save the sketch as pseudo firmware just to test that things are working as expected I'll go ahead and upload this empty sketch onto my Arduino Uno when I do that I should see the Uno's TX and rx LEDs light up if I try the same thing with a sketch for the ESP 82 66 I should see the LEDs for that board light up when it's uploading if everything is working correctly we can move on to the Arduino Uno side of things we'll start by installing the arduino json library and for this video I'll use its latest version which is six-point 10.1 in the sketch I'll start by including the hello file of the library then I'll define a couple of variables that I'll use to transmit the data to the esp8266 in the setup function I'll initialize the serial communication and in the loop function I will monitor the activity on the serial port of the uno if there is a message coming through I will read it into one of my variables and I will try to process it using the arduino json library to make things easier we're going to format the messages using jason so using a dynamic JSON document i will do some basic error checking to make sure that the data is indeed formatted in jason and if it is i'm going to expect it to have a field with the key type and because that message is going to be sent from the esp8266 on to the arduino uno it's going to have a value of requests that means that the esp8266 whenever it requires data it's going to send a message with that key value pair if we find that as part of the message we can construct the response for that purpose I'm going to switch the value of the key type to be response then I'm going to add two more fields one with the key distance and the value corresponding to the distance measurement and another with the key gasps with the value corresponding to that particular measurement I can go ahead and upload the code and if I open up the serial monitor I can mimic the message that eventually will be sent by the esp8266 formatted in Jason with the key value pair type request in the response message we find a key value pair of type response and the two measurements with the key value pairs distance and a random number as well as gas with another random number the random because we haven't connected the sensors just yet now we can move on to the esp8266 side of things to make things easier I'm going to go to our repository for the series and use the simple webserver sketch as a starting point I'll leave a link in the description of the video I'll get rid of things that I want to use fill in my network ID and password and use a user-defined function that I'll name handle index to display the data that's collected from the you know I'll get rid of the total led function which we won't use and because we want the data to also be formatted in Jason will include the header file in our sketch in the handle index function will send first a request for the data the dynamic Jason document as we saw before will need a key type and a value of request in order to get a response from the Arduino Uno we'll need to make sure that the bot rates used by both ports match once that message is sent over serial we'll get a response in a similar way that we did on the Arduino Uno we're going to monitor the serial port for any activity notice that this piece of code will block that means that this while loop will execute while there is data being sent on the serial monitor the response from the web server will take a little bit of time but that's okay once all the serial data is bread we're going to attempt to deserialize it assuming that's formatted in JSON as we did before we'll do some very basic error checking and if everything goes well we should be able to pull the two values that are transmitted from the Arduino Uno namely the distance and the gas levels we can then display this data however we want for this tutorial I will choose a very simple web page that contains plain text I will simply use a string variable with the two measurements and the server dots and method to display it to the client with this done we can move to connecting everything together the RX pin on the esp8266 will be connected to the TX pin on the Arduino Uno and vice versa for the RX pin on the esp8266 before connecting the sensors we can upload the sketch onto the esp8266 to test the serial communication if I reset the esp8266 node MCU born it'll connect to my local Wi-Fi network if I access their root path directory then the esp8266 will send a JSON formatted message via the serial port to the Arduino Uno as well as the USB to serial port so now we're ready to actually hook up the sensors and have some fun the distance sensor just requires power and the data will be connected to a zero similarly for the carbon monoxide sensor will connect data pin to a 1 and power and Brown to 5 volts and ground respectively on the Arduino Uno you seem pretty much any object you think appropriate you can test out the changes on the distance recorded by the analog sensor for this quick example we'll need to refresh the page any time we want to make a new measurement as you've seen in my other videos you can use things like WebSockets Ajax to make these measurements a little bit more dynamic for testing carbon monoxide levels I'll burn a little bit of wood and use just a simple glass vase to contain it around the sensor if i refresh the page I also see changes on the carbon monoxide levels that are read by the Arduino Uno and then transmitted to the esp8266 and there you have it very quickly we were able to use the serial port of an arduino uno development board as well as an esp8266 nor MCU board to send data that's collected by the arduino uno to the esp8266 which once receiving the data is able to display to a client over a webserver if you like my videos I invite you to my patreon page where you can chip in a buck or two that really helps me put in more time into the videos and release them quicker but whatever you do don't forget to Like subscribe or leave me a comment you can also interact with me on social media I'm on Instagram Twitter and Facebook and you can even use the community tab of the channel thank you for watching my videos and I will see you next time
Info
Channel: ACROBOTIC
Views: 34,215
Rating: undefined out of 5
Keywords: ESP32, ESP8266, Arduino, IDE, NodeMcu, Tutorials, Makers, Learn, Guide, IoT, Internet Of Things, Raspberry Pi, Wireless, Communication, Weather, Creative, Sensor, Python, Programming, C++, Beginner, Electronics, DIY, MicroPython, 3d Printing, CAD, Fusion 360, Education, Tutorial, Intro, Introduction, Web, Developer, HTML, Datalogger, Project, Sensors, Data, Visualization, Webserver, Server, Client, App, WebApp, Wemos, Robot, Robotics, Robots, Easy, Adafruit, Sparkfun, OS X, Windows, Linux, Embedded, Kickstarter, RC, Fun, Build, Engineering
Id: 6-RXqFS_UtU
Channel Id: undefined
Length: 11min 25sec (685 seconds)
Published: Wed Jun 26 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.