Design & Order on EasyEDA, PCB+SMT $10 Off: https://easyeda.com/editor
Get coupon & Join JLC&EDA Group: https://jlcpcb.com/EDA
How easy is it to get a 128x64 OLED and a Si7021 temperature and humidity sensor working with the ESP32?
https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/
https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/
Subscribed to my 2nd channel? Watch all my 3 minute videos on Julian's Shorts: https://www.youtube.com/channel/UCeewzdnwcY5Q6gcbnZKIY8g
Interested in my new garden workshop? Follow the entire build on Julian's Shednanigans:
https://www.youtube.com/channel/UCXfDjPehpC7B7lW2JFxeS4w
Join me on Odysee/LBRY: https://lbry.tv/$/invite/ @julian256:d
Octopus Energy referral link: share.octopus.energy/aqua-birch-918
(We each get £50)
#ElectronicsCreators

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 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.

By Julian

Youtuber, shed dweller, solar charge controller aficionado

12 thoughts on “ESP32 with I2C OLED and Temperature Sensor”
  1. Avataaar/Circle Created with python_avatars q zorn says:

    okok… i have the arduino ide working "not fun" with the esp32 and built-in oled working… i think? now, to display an analog read-out with an alarm.. 😎 thanks a lot…👍👍👍

  2. Avataaar/Circle Created with python_avatars Robert Ritchie says:

    I just ordered a few of these, some with cameras today. Lo and behold Julian makes an Esp32 video == compelled to watch as this is almost the identical project I am building.
    Thanks Julian you have saved me some time.

  3. Avataaar/Circle Created with python_avatars Roby 300 says:

    Dude pls tell me… Can i run machine learning in esp32 dev board… That same board… Pls tell.. Which is better arduino 33 ble something or esp32 dev board… Pls reply… Can i run tensorflow lite in esp32 dev board.. What are the basic components need to do a machine learning.. In esp32 dev board

  4. Avataaar/Circle Created with python_avatars Defpom's Electronics Repair says:

    To make programming the ESP32 easier, install a 1uF cap between the Enable and Ground pins, this means you don’t need to press the button to program it from the arduino IDE, you just upload and it works.

  5. Avataaar/Circle Created with python_avatars TheMockTv says:

    i use a wemos d1 mini with battery shield the bme280 can Temperature/Humidity/Pressure measure and all the data put it over

    the wlan from the wemos d1 in my mysql data base with a php script peer get/post string receive so can i over my webinterface in all my rooms the Temperature/Humidity/Pressure see or over home assistants

    i can not untersand why you it so complicated make, of course i can untersand the you try out it but you wasting so mutch time for a lost way, the'r i can not understand why

  6. Avataaar/Circle Created with python_avatars Graham Eida says:

    All my esp32 sensors report back to a MQTT server, gives you loads of flexibility for control and logging.
    Look up the IOTstack for the raspberry pi, very easy to set up

  7. Avataaar/Circle Created with python_avatars SarahKchannel says:

    i have done pretty much the same, but with esp8266 WEMOS boards, that connect via WIFI and MQTT. Feed through Node_Red into InfluxDB and visualize all sensors around the house in Grafana.
    Each SensorPuck has a the same mini OLED, DHT22, AirPressure sensor and some variations of that configuration.

  8. Avataaar/Circle Created with python_avatars Timothe Pennec says:

    Hi, i don't have understand why you change from ATMega 328 to ESP32, for the wifi only ? the identical value for the first screen and the second are the same from the code no ? Or ATmega 328 doesn't have much memory to control the two screen at the same time ? thank you 😛

  9. Avataaar/Circle Created with python_avatars K M says:

    i designed my own esp32 board with battery management built in for wearable sensor interfaces and sensor projects 🙂 esp32 module is very cheap and powerfull

  10. Avataaar/Circle Created with python_avatars PicoNano says:

    Why don't you buy a USB rechargeable (No charger required) AA and 9V Li-ion battery?
    I bought one brand "Znter" from AliExpress. I replaced all my AA and 9V batteries inside my stuff, and I'm happy with their capacity and performance.
    It can sit months inside an instruments and don't lose much due to very low internal discharge and boost converters that take microAmps in standby.
    The only problem I found, if you can call it a problem, is the battery gives no indication it's low and suddenly stops and wants to be charged.
    Small price to pay, if you ask me.
    I also bought Soshine brand, but they come with a charger station.
    Search "Soshine 2pcs 650mAh 9V 6F22 Rechargeable Battery" if interested.

  11. Avataaar/Circle Created with python_avatars dean laughing says:

    nice , i made one of these with a DHT22 the other week. i hate the cheap esp though…. never is too stable, web server always goes out

  12. Avataaar/Circle Created with python_avatars John Macrae - Mostly Magic Smoke says:

    Hi Julian, for what its worth, you can use almost any pin to drive I2C. You may have to declare those pins when you call your driver library though

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.