ESP32 with I2C OLED and Temperature Sensor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning all this is my sensor display the sensors are in the shed and it's got a radio in the shed to transmit the data to this receiver which has oleds and displays temperature and humidity and yes for those people that keep asking why these two data fields the same well they are they're the same it's the same data and if you're thinking why is it 90 humidity in the shed well we're having a horrible summer and it's raining all the time [Music] now i understand that the 80 mega 328p an 8-bit microcontroller is a bit old it's a bit clunky and it doesn't have wi-fi and therefore if i'm going down the iot route and i kind of am internet of things i should be thinking more about the esp32 so i dug this esp32 module out the other day it's actually a do it esp32 dev kit version one and i installed all the board manager stuff or the board descriptions into my arduino ide and i managed to get this to run the blink program should we have a look at that right so let's put some power on this from a power bank and watch it do its thing there it is blinking blue light so yeah blinky runs on the esp32 so that's a first step but what if i want to take this a bit further and kind of go down this route with displays and sensors my next step really would be to get an oled to run on the esp32 so here's an oled it's a 122 128 by 64 pixel oled so how do i connect that to the esp32 and make it do something well i went to google and i typed in esp32 i squared c and there was some useful information and probably the most useful piece of information that's come up even without going to a website is that sda is on gpio21 i believe it is and scl is on gpio22 well perhaps that's all i need to know now if i remember rightly these oleds work on both 5 volts and or 3.3 volts so if i if i connect this up onto pins on here um which will be 3.3 volts ground and these two gpios can i make the oled work well let's get some wires so here's a four-way dupont let's connect that onto here uh i'll make purple vcc because it's about the closest thing i've got to red so purple is vcc gray is ground white is scl black is sda so let's take a look at the pins on this esp32 and we have got right at the left hand side at the bottom 3v3 and ground and if we come over to the other side you can see that you've got d21 rx0 tx0 d22 so r21 and 22 the i squared c pins let's assume they are so let's connect vcc and ground onto these two end pins 3v3 in ground uh now what was white white was scl scl is 22. oh so white goes over to there and black crosses over and goes to there so that's it what happens if i plug this in will it explode uh well nothing happens doesn't explode but of course this just carries on running blinky so now i need to put together a sketch which drives an oled so let's do that let's go over to arduino ide now while i'm still here this is my search for esp32i squared c and the first one that comes up is random nerd tutorials and you can see here even without clicking on it i have clicked on it because it's purple uh sda is gpio21 scl default is gpio22. now if you go into this article there's another link to another article that tells you how to install all the board manager uh stuff for the esp32 i'll put links to both of these random nerd tutorials in the description below this video so this is my code for the display using the atmega328p the arduino nano and out of this what i need is this include for the u8 x8 lib uh this constructor calls for the uh ssd 1306 128 by 64 no name hardware i squared c and i give the object the name oled78 i don't need the 7a one because i've only got one oled i will need an oled 78 begin and a set font i'll use that font and i will need an oled 78 set cursor to zero zero that's the top left of the oled and print something so this is what i've come up with and it's this it's the include the eox8 sorry u8x8 lib that's the ollie klaus graphics library for lots of different displays constructor call oled 78 is my object in setup i begin that object that just initializes a whole load of stuff including the uh 78 address you don't need to specify that because it's the default and i set a font and then in loop i set the cursor to the top left hand side of the oled and i print millis which is just a counter i assume millies is implemented in the esp32 in much the same way as it is in the atmega so let's compile that and upload it to the esp32 and see what happens press the button compiling sketch takes an absolute age on this pc particularly when i'm running obs so i will come back when that's more further advanced and uh when i say more further advanced i suppose what i really mean is working so yeah that works that was pretty straightforward uh just connecting this to 3v3 ground scl sda stick a bit of copied code in and it's doing the count that second digit there is essentially one count per second because that's thousands on here and that's millies inside this no idea how millis is implemented i mean i know in the um 80 mega 328 it's on timer zero it's obviously on one of the timers in here but i don't know much about the hardware inside the esp32 but yeah that's working so where do we go next do we go to a sensor temperature and humidity which is my kind of thing so this is counting up how do you reset this thing there's two buttons on here boot and enable is it boot no it doesn't appear to be is it enable oh yes that's it that started back at zero let's try that again enable yeah that definitely works as a reset button um okay so let's find a sensor in fact i've got just the thing i believe do you remember this this is a little oled and si7021 temperature and humidity sensor munged together because the uh four pins happen to be in the same sequence v in ground scl sda so i simply attach to the sensor so the top of the display is rather good isn't it in fact if i've got a nine volt battery somewhere i can probably fire that up let's try this one oh red lights come on but that's all that happened probably find all these batteries are flat actually let's try this one that one appears to be flat what about this energizer one oh that's working so all two fancy fonts on here 75 percent humidity oh that's fading out oh that battery is flat as well well anyway it worked uh it's reading on i squared c the temperature and humidity sensor and it's writing the results to the oled now that very handily is on a little connector so i can take that off and i can put it in here in fact i'll do that right now with the power on which is very naughty i know which is vcc ground isn't it yeah and if i press the enable pin which works as a reboot that should work for the millis but what i really want to do now is read either temperature or humidity and write that to the display so i've got to look at the code i think for the transmitter of this because that's the thing that's reading the si7021 and still a bit of code out of there let's do that so i think what i need from this is and include i squared csi7021 dot h uh the constructor call i call the object simon that was pretty stupid uh then assignment initialize in setup and then a simon get humidity and don't i think this is where it dumps it so i could do a print simon get humidity that might work shall we try that so do we think this will work i've added in the include what's the difference does anyone know between using the braces here around the name and using quotes doesn't make any difference is there some subtle difference i'm not sure what the difference is si7021 sensor i've called the object sensor sensor initialize and then print sensor get humidity so is that going to work well let's find out let's upload that to the esp32 and see if it works oh we didn't like that uh no matching function for call to si7021 get humidity okay let's restructure it slightly well that was a struggle uh i had to switch to the adafruit si7021 library because the one i was using just didn't work i don't know why i kept getting compilation errors so i've got to include a constructor call sensor begin in setup and print read a sense of read temperature in my loop and it's working so here it is 21 degrees in here and if i put my hand near the sensor the temperature goes up because my hand is warm i presume so yeah that's certainly uh working it's reading the sensor now of course the sensors are being powered with 3.3 volts now not five but i believe that is actually a 3.3 volt sensor and on the back there is some level shifting i think there's a regulator and level shifting mosfets but of course they're not doing much but it does seem to work at 3.3 volts so yeah that's the oled and the si7021 both working on an esp32 well i think that's enough for today so cheerio
Info
Channel: Julian Ilett
Views: 20,737
Rating: undefined out of 5
Keywords: electronics, esp32, Arduino, OLED, Si7021
Id: yec_72giqf4
Channel Id: undefined
Length: 13min 12sec (792 seconds)
Published: Tue Jun 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.