esp32 and oled display: internet clock - dht22
In my last tutorial: the internet of things became simple: playing ESP32 on Arduino IDE, we explored: Now let\'s include an OLED that shows the data captured by the DHT sensor locally
Temperature and humidity)
And local time.
We will be programming our ESP32 using the Arduino IDE, as we do with the ESP8266 family.
Install drivers: it is important that you have installed the updated cp10. x USB to USB driver on your computer.
Enter: usb-in this link-to-uart-bridge-vcp-
Driver and install the correct driver for your OS.
Installation Library: The novelty here is that the Expressif itself is in GitHub and will provide us with the correct direction for the installation of the library: arduino-esp32.
Follow the instructions of the operating system.
After that, restart the Arduino IDE and it\'s done!
You have to see several boards on the Tools menu.
Choose the right one for you.
In general, the \"universal\" ESP32 development module works fine.
We will start with the hardware assembled in my last tutorial.
We\'ll be faster here, but visit if you want more details: IoT becomes simple: in short, play ESP32 on Arduino IDEIn: to test the LED, you can test the potentiometer using code esp32_blinkfor (Analog input)
, You can test the DHT using the code: Dialog _ input, first install the library as described in the next step.
First, you need to install the adaffrut library on the IDE.
Go to their GitHub to download an updated version of this library: DHT-sensor-
When I first used the library, I received a message: After some digging, I found that there was also a need to install the Adafruit unified sensor Library.
So, I am from Arduino IDE library manager (
After that, everything went well just like we did with Arduino and NodeMCU.
Let\'s do some testing with this sensor.
You can use the \"DHT tester \".
The Ino \"sample sketch, which is included in the library, or made by itself.
I wrote a simple code to test the sensors that can be downloaded from my GitHub: esp32_dhtfor this tutorial, I will use the 128x32 I2C OLED display.
In principle, once the library is installed, the ESP32 will also work with the 128x64 OLED display.
Once this device is an I2C monitor, you need to connect 4 pins with ESP32: Now, install this library.
We will use the version of Daniel eihhoen here.
Open the library manager and search for \"OLED \".
See above. I have the 3. 2.
7 versions are installed.
Open ssd13306simple demo on the example menu and replace the code with: GIF below: show a simple demo of some work.
Please note that this demo is designed for a 128x64 monitor, so you will realize that the graphics will shrink in case I use 128x32.
You can easily create and install new fonts on your display.
I created a new font that can give me about 2 lines and 20 characters on the 128X32 OLED display.
How to create it: go to the SSD1306 font converter, a great tool developed by Daniel eihhoen.
There you have to choose: Press Create and voilá!
Create the \"C font\" file in the appropriate window.
The foto above shows a new \"Hello World\" using this new font \".
A clean code can be downloaded from my GitHub: esp32_ssd1306_testlet is now displayed on OLED showing the temperature and humidity captured by the DHT22 sensor. On our loop()
Function, we will have: function getDHT ()
It\'s the one I used before.
The new feature here is display data ()
, As shown in the following figure: the photo above shows the final result, you can download the complete file from my GitHub and also register the collection time.
Let\'s use NTPClient Library: change the line: enter with WiFi network credentials.
On the serial monitor you have to see the actual time.
In the basic version, European time will be displayed.
In the advanced version, you can change it.
Now, let\'s merge this timestamp code with the code we developed earlier.
The results are shown above.
The complete code can be downloaded from my GitHub: esp32_time_stam _ dht22_ssd136on the last step, we put all the code together, there is one how do we get each information to display one on the display at a time?
We need a \"page selection\" mechanism.
Several different mechanisms can be used.
There are usually multiple buttons to select the menu.
For fun, let\'s try something unusual here.
We will turn the potentiometer like we did with the radio dial, and depending on the value read, we will define a specific \"display\" that will be displayed on the OLED.
Let\'s define 4 possible displays: the analog input can read 4,095 different values.
We only need 5, so let\'s define the scope for this: let\'s define an int variable that will receive as content: 0, 1, 2, 3, 4, 5, according to the screen to be displayed: Now we need to create a function getDisplay ()
, Will read the value of the potentiometer, return the correct display number (
Display num will be a local variable in this function).
The function will look like this: Display Data ()
Function, the selected display will be displayed (or screen)
: Both of these functions will be included in our Loop ()
Function: the complete file can be downloaded from my GitHub: esp32_time_stam _ dht22_ssd306_multiple_display. Here is a selector with our display.
We will be back soon with a new tutorial!
Continue to learn the MJRoBot tutorial!
As always, I hope this project will help others find their way in the exciting world of electronics, robotics and the internet of things!
For more projects, please visit my blog: MJRoBot.
OrgSaludos from the south of the world!
See you on my next structure!