Cheap and Easy WiFi (IoT) Tutorial Part 1 - ESP8266 Setup/Intro

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello hey what's up guys in this series of videos we're talking all about the Internet of Things which is kind of a buzzword lately but really Wi-Fi modules have been around for a long time in fact you might remember a video I did a while back on the NRF NRF 24 l01 plus which is a really cheap wireless transceiver and my plan was to have these little transceivers with sensors connected all around the house here that communicated back to a single base station with a Wi-Fi module that was going to actually pump the information up to the web but recently with the introduction of the esp8266 which is a little Wi-Fi module that you can buy for under $3 so now it no longer makes sense to have all these separate sensor nodes in the house that all communicate back now each sensor node can actually communicate directly to the web so again that's the esp8266 and you can buy these for under $3 I just bought five of them for $15 off eBay so before we get any further let me show you a project I've just completed with one of these to kind of get you pumped up for this series of videos alright so here is my super simple demo project where we have a board mounted to the ceiling of my garage with an ultrasonic rangefinder and Arduino and an esp8266 okay so the whole idea here is that I'm monitoring whether or not my garage door is open or closed and if it ever is opened and the system is armed I want to receive a text message and I want to be anywhere in the world and I want the interface to be accessible from anywhere in the world so we have full complete two-way communication from the internet and this board mounted in my garage so here's my super simple little web interface this is all done in PHP script using a sequel database and we will talk about this in insane detail later on so I'll make a separate video for creating this interface and how the PHP code were and will of course get into the Arduino code running on the board but in this video we're just talking about kind of getting started with the module hooking it up and configuring it and kind of getting it talking to the internet and by the way we're not just talking about communication between a this board and a web interface like this we're also talking about getting back information from the web like you know the weather stock prices the sports anything it doesn't matter any public data out there we're gonna be able to access from this module and get it into your project so anyway let me give you a quick demo of what we've got going on here so here's the web interface the board out in the garage is unit 2 it's currently connected and this is a little buggy it's not perfect quite yet but we can you know this is a input we're getting from the board it's just a random count and it's continuously counting up from the board this analog value here is coming from the board and that is the measured distance off of that ultrasonic rangefinder so it's measuring 10 feet and that's a total total distance so down and then back up because it does ping and then echo back so it's actually a measure distance of 5 feet the trigger value here is for five feet or two and a half feet and that's the distance that my garage door when opened is measured from the ultrasonic rangefinder it's actually more like four --is-- but it's a less than check so if this is ever less than that send me a text message so let's go ahead and arm this okay so right now it is armed and if the garage door is opened we will get a text message there's a few other things on here - we have disabled enabled net that changes the colors of the LED and the video I've got planned right now up there is not real time with this it's kind of I filmed that before I filmed this little web interface thing so we also have a D s 18 B 20 on the board which the one wire temperature sensor and that is feeding this real-time temperature back to this interface we have a brightness control here so we can change the brightness of the LED and that's just for demo purposes to kind of just test everything out so let's check this out and see if we got a text message back and sure enough yes we do so it does work and that's just a simple demo of what you can do with this module so now let's get into actually wiring it up setting it up and getting started with this whole thing so let's keep okay to get started using the esp8266 we first need to get it on a breadboard so that we can talk directly to it from a computer using a hyper terminal program or a serial monitor window in the the arduino ide so what we've got set up here is a USB to serial converter some level shifting the module itself and since it runs off of 3.3 volts i've got an external five to 3.3 volt converter over here what's pretty cool about this part is that it has an SOC on it meaning it's got a system-on-chip which is the Wi-Fi the Wi-Fi controller and a really really heavy-duty microcontroller so if you're if you're savvy enough you could actually download your own application program right into the module and have that be the entire system right and it's got a few GPIO pins off of it that you could tie in to whatever you want whatever you want to control or get data from so if you're savvy enough you could actually do that in my series of videos I'm just talking about having an external Arduino talk to the module using standard well not standard but the 80 commands and this has a command set that you talk to it through and by the way you talk to this module using a standard view our interface so hardware serial software serial and you can configure the blog rate and we'll get into that in a little bit but as far as setting this up it's pretty straightforward it's just a few pins tx/rx ground and 3.3 volts but again we do need to first set it up so that we can talk to it through the computer here and that'll allow us to update the firmware configure it and test it all out and then from there we'll move on to controlling it the in arduino so i actually have a little cheat sheet over here on how I have this thing wired up and hopefully you can see that but this is the the top view of the module and you might want to look online before trusting my video here because this is a new module and things are changing everyday with it so there may be a new module that's come out and maybe they change the pings around or who knows so make sure you check online before you hook anything up and apply power so basically what we've got here though is it's eight pins and I I'm connected to the breadboard here through a little adapter board I made so that it makes this breadboard friendly and it basically just spreads the pins apart and I'll have a link in the description where you can actually buy your own boards if you know if you don't want to do that there's other ways of doing it you can hook this into a Pirtle Pirtle board and then you know make little header stand out and you can plug it into the breadboard so there's there's a little workarounds okay so there's eight pins and basically what you do is you connect the top left to ground the bottom left is the TX pin out of the esp8266 which you can connect directly to the USB to serial converter ZAR X and since this is 5 volt a 5 volt interface it will recognize the three three coming out of this is a logic high the next pin over next to the TX pin on the bottom is connected directly to three point three the next one over again to three point three the bottom right is your source pin and you connect that to 3.3 volts top left I think I said already is ground the next one over is GPIO to which I connected directly to 3.3 volts and then the next one over is GPIO zero which is used to update the firmware and during normal use you connect this just to three point three while you're programming or uploading new firmware you tie that to ground and we'll talk about that in a second as well and then on a top right is the RX pin so that's the data receive pin into the esp8266 and for that pin we will need to level shift it if we're connecting from a 5 volt communication interface so what I've got here are two cd40 50s which are just logic buffers and I have them tied to 3.3 volts as from to their source pin and then through one of the buffers I'm connecting the TX pin and then it just buffers it to 3.3 volts and then that goes over to the RX pin that's one way of doing it and I I originally had this board hooked up to a little 3.3 volt actually I'll bring it down here a little 3.3 volt LCD screen so I needed a lot more pins and for that application it made more sense to use the CED 40 50 plus if you're gonna actually communicate at a higher baud rate like maybe 115 point 2 kilobits per second then it might make sense to use the 40 50 since it's fast if you're not really too concerned about speed and if you're just gonna communicate at 9600 bits per second like I am then you could just use a simple transistor level shifter on that on that rx pin to the esp8266 so here we have just a really simple level shifter using a transistor and two 1k ohm resistors these are both 1k actually no they're not 1k they're 10k to 10k ohm resistors okay so you have your your TX pin from your converter or from the Arduino connected to the emitter of a2 and 3904 NPN transistor the base connected to a 1k ohm resistor tied up to three three and then the collector tied to 3.3 as well through a 10k ohm resistor and then that heads over to the rx pin of the esp8266 and this is the same setup I have out in the garage and it runs perfectly fine at 9600 bits per second so that is the hardware setup really nothing to it and by the way there's a ton of ton of resources online too for all this so definitely check that out before applying power so now let's talk about uploading new firmware to the parts ok so i've connected the USB to serial converter up we do have power on the red LED on the Wi-Fi module should the solid red and we should be good to go so let's first just check to make sure that the connections are all good to go so I'm gonna launch the arduino ide here go in select the right comport we're good launch the serial monitor window make sure you've got both new line feed and carriage return selected down here this default baud rate is 9,600 bits per second I did get a few modules that out of the box were at 115 - so you may need to go down there and select that in case 9600 does not work so let's just go ahead and ping it real quick and do an 80 so the letter 80 letter T enter and you should get ok back so we're good to go on this so let's go ahead and unplug I'm going to unplug the USB to serial converter so I've removed power I'm going to switch GPIO 0 now to ground I'm just going to connect it directly to ground ok that's connected to ground I'm gonna power it back up ok so now we're gonna update the firmware so I'm gonna have a link to this little wiki here in the description this is from electro dragon and I think they've got the best documentation on this module out of out of everybody so far at least and it's just a good spot to go to for a quick reference or if you need to get somewhere else because they do have links to other other resources on here so let's go down to firmware here and go to where am I going here okay I just want to find where the firmware is firmware okay and I want to go find most updated firmware on this Google link okay this should take me to a Google Drive here we go official firmware I just want to show you where to get the firmware that I'm actually running with all right and this is what I'm running with here is the esp8266 flasher v zero zero one eight zero nine zero to underscore zero three dimes if okay that's what I'm using so download that and by the time you watch this video they'll probably be like ten more versions of this firmware but that's what I'm running with right now and it seems to be very stable and reliable okay so once you unzip that you can open it up I'm running a 64-bit windows here so I'm gonna launch this flasher utility and it opens up this this little window here you select the comport and hit this which I'm assuming means go or we're flash okay and you can see the progress bar is doing something okay so now the firmware has been updated let's unplug the USB to serial converter so we remove power and I'm going to move that wire connected from GPIO 0 from ground to 3.3 volts powered backup will launch the arduino ide and give it a quick test 80 and we're good alright so let's now go through and test it out and see well actually let's test one more thing et+ GMR will get the lit what firmware is actually on the board so that was 18 zero zero zero nine zero two which nine zero - but it's I guess it's underscore I guess they're not showing you the zero three there in the in that response so now let's uh let's dig into this a little further and I'll show you what this module can do okay so now we're ready for the fun stuff we've got the firmware updated we're all hooked up we're communicating now we can actually talk to the internet and sorry that was kind of rushed through this video I'm kind of trying to just get it all out there now so that we can actually get into some of the cooler stuff but I'm just kind of blasting through everything so let's just go through the commands so now we're connected to the module so we can just issue an 18 we get the okay back so that's good let's do a reset so that's 80 plus rst and that will reset the module you'll get it okay and then you'll get a little thing back a little kick back system ready so if in your Arduino code you needed to issue this reset you would wait for something like you know system ready or whatever and it's kind of funny from firmware version to firmware version this message changes and I noticed that when I change the firmware to the latest one that I that I showed you they actually made this our lower case so it screwed up my whole you know checking feature of the the code so anyway we'll get to that later on in a future video so okay 80-plus GMR let's check that firmware let's set the mode now CW mode and if you do equals question mark it'll tell you what it'll accept so if I were to change this CW mode which is actual mode of the Wi-Fi module so it could be a station which is basically like a device on your network it could be a it could be an access point so you can log into it or it could be both I haven't really played around with the access point function yet but that'll be coming up soon because I do want to make a web interface that you kind of log into and you can set up the SSID and password and everything then you know it's kind of just a completely standalone device all right so let's go ahead and do 80 plus CW mode and without the equal sign you can just do a question mark and that will tell you what it's currently set at so it's currently set to 1 which is fine which equals station and you can look up all these commands I'll have a link in the description you can look them all up and there's fully detailed explanations of all these different commands ok so now let's do 80 plus let's list all the the access points so see WLAP give it a few seconds and there we go so it's listing all the access points we're going to go ahead and connect to test there so CW 80 + CW j AP joint access point equals quotes test comma quote password and I type in your password mine's password enter up there what did I do wrong here CW showing what did I you up I forgot a quote that's right ok it's pretty easy to miss little easy things here so there we go now it should take it so give that a second we should get an ok back all right we got the ok back great alright so now we're connected double-check that we're connected to a cwj AP question mark and and yes indeed we are connected to tests now we're gonna do a t plus SIP MUX equals one so this is this is setting it to accept multiple connections which is required for the TCP connection we're about to do to the internet so you set that to one and this needs to be set every time on boot-up or power dial and power up reset you have to set this every time does not save this when power is removed okay I don't think it'll let me change sip mode but we want to keep sip mod 0 nope so let's issue a reset after all that all that configuration was to the reset there wait for the kick back there we go 80-plus sip mode now equal to zero we want to make sure that's zero so that it is set for I'm just looking for the definition of this so not data mode so I think if sip mode was set to 1 I haven't played around with that yet either but I think if it's set the one you can sort of do a streaming connection so 80-plus sip know what do I want to change sip MUX that's the one sip MUX equal to one okay all right now we're ready to start a connection with the internet so let me okay so I just wanted to change gears for a few seconds here now we're about to communicate with the internet and we're gonna try to retrieve the the weather for Cleveland Ohio and to do this there's there's a few different ways you could do this the way I do it is I use Yahoo's query language so I've used Wi-Fi modules in the past and usually what you do is you you access a web page and you read back the entire web page all of its HTML in text form so it basically just blasts it down the UART and you're eating out this entire webpage in text waiting for certain keywords and when those keywords hit then you know that your data you know is in between two keywords so you have to come up with this really complicated code to basically create like a buffer a rolling buffer and it can get kind of it can get kind of messy and the other thing too is you know when you're reading a giant webpage back in text you need a fast viewer because it could take like up to ten seconds to read it back an entire webpage you know using you know like a 9,600 bits per second you were so Yahoo query language you can ex you can actually put in different websites in here and you can query out different keywords things you actually want the data you want and then they give you a link here and then when you use that link it'll give you back just the parsed data you want so I'll probably make a separate video showing you a few different things you can pull out using this query language here but if there's plenty of examples here you can see all the things that they give you examples for but I'm just gonna kind of show you what I did here so I'm selecting you know item got forecast from the weather now forecast where blah blah blah and this sets up your where your the location you want to grab the weather from I'm getting it back in JSON format no diagnostics no debug and if I test this you can see here the what it kicks back here kicks back the results and you can see the forecast so date Monday high-low text is light rain so it's it's kind of cool and it gives you I don't know what it that is like them for a five-day forecast and then down here it gives you the link so I'm gonna copy that now and then just throw that into alright so now you can see when you just when you just use that link plane it just gives you this so that's much easier to work with than an entire webpage so let me show you an example like if I went here and I want to do love and I went I don't know where show page source just for this you see all this crap that's what I would normally get back from any webpage yeah I mean it all comes back as a giant block of text so I just wanted to show you that real quick now kind of the problem with the esp8266 is you can tell that this is a huge link down here it's massive so when you're sending that over to the esp8266 i found that it can be kind of finicky you know maybe there's a the buffer the serial buffer on the chip can't quite handle that entire giant link so then I use something called things speak okay so this is things speak here and this is like you know this interface you can use to to handle all of your data you can plot your data you can have this actually handle the Wow check this out let me just show you an example so if I go over to apps thing HTTP I can have it do I can have it call that link for me and it'll give me another link so it's kind of backwards but if I go in here and I just I already had this set up paste that link in here and then save this don't worry I'm gonna change the API key and then it'll give me this link so now I have a much shorter link that that I can call from the esp8266 to get that data back okay and now if I called that link pop that in I get the same data back okay but you know that sounds kind of crazy but you can use this thing speak to do all kinds of stuff and I haven't even tested this out yet but like now you can not only get public data but it looks like you can also get things like maybe things out of your Facebook maybe things you know out of your email you know private data things that you need to login for so I haven't tested that out yet but I'm going to the other thing you can do here I'm gonna go here and then go into this is you can actually plot data as well so I was plotting some data from a temperature logger and it's the same idea not temperature lager but I had the vs 18 B 20 temperature sensor and I was basically just pumping that up the only problem with things speed though is there are limits on how often you can update this this how often you can call this link that the API refresh rate but if I go here to data import experts so now for this channel here it gives me this link here so if I do a call on this I can change that field one to be something and I'll show you an example of that in a second but let's first get that weather down okay so now we're back and I just showed you you know the Yahoo query language and the things speak server so now we can actually grab the weather down so what we do is first we need to connect to the things speak server what's cool about this the the esp8266 is that it has it allows you to basically put in a domain name not the IP address so I can do an 86 tart equal the channel of the device I think you can go zero two three zero one two three I think that's got four channels that you can connect on four would be all channel I'm not sure exactly but I always use zero comma quote t TCP comma or quote and we're cuz we're gonna use a TCP I think you can this module supports UDP as well quote and then the API dot thing speak comm quote comma et so we're gonna connect on port 80 so we'll go ahead and do this now we're gonna be as soon as I do this hit enter we're gonna be on a countdown timer because the connection can close at any time so we're gonna go ahead and do this okay linked now the next thing we need to do is an 86 send on that same channel 0 and then the 110 is how many bytes I'm sending and I'm just I just chose a big number okay and we're gonna see if we can get the and then the this format is critical so we do a get and then the in that entire link and then a space HTTP forward slash 1.0 alright I'm gonna put that in and then I'm gonna start tapping the enter button because we need to get all those new line feed carriage returns in so okay so here's the data it's sent out you should get when you actually write this in your code you're not just gonna send you know some large number you'll actually create a string here for this entire thing and what I usually do is have in that string two for two new well it'll be a new line feed carriage return new line feed carriage return so you have that twice repeated twice and you read the whole thing into a string and then you do that string dot length in for this value here so that you're you're you're doing a sip send of the exact number of bytes you're gonna send okay and then you get a send okay and you will get these errors are just because I was tapping the Enter key and then here is everything it did send okay and then you get the query down here with the results and there's your forecast so now we were able to successfully get information from the internet now let's do the same thing but this time we'll use that link to send data and I'll show you that in a second let's reconnect let's do sips and of 110 you know I'm going to set the value let's set the value for a hundred I just changed that so right here to get and then that whole link they gave me and then when I go over here you can see and field one equals 200 let's let that go and then tap the hunter button and there goes all right so it looked like it took it let's go in now to the interface and I'm gonna go to the public view and there it is so that's pretty cool so this this is the little graph that they give you and you can actually take this I think and it'll give you the HTML yeah the iframe so you can embed this in your website or some you know webpage you created with a bunch of these charts and and do whatever you want there you can also get this data back from it so you could store your data there and you can also you can also store and view your data on other on other servers as all other data servers as well like Sparkfun has something going on and eat a fruit I think it's just about to launch their their data server so so anyway just a few there a few different places you can go and do the same sort of thing so that is kind of what I wanted to accomplish with this tutorial up next will be the full PHP script the whole PHP code side the Arduino code side the sequel database side so there's a lot coming in this series so hopefully that'll kind of kickstart you and get you running with this so I know it's a long video but thanks for watching
Info
Channel: Kevin Darrah
Views: 1,079,872
Rating: undefined out of 5
Keywords: arduino, ESP8266, wifi, tcp, thingspeak, yql, module, internet of things, Microcontroller (Computer Processor), tutorial
Id: qU76yWHeQuw
Channel Id: undefined
Length: 31min 28sec (1888 seconds)
Published: Tue Dec 16 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.