Better for the eyes: Displays BMP280 sensor readings on an OLED display

--

Okay guys back again with me, Ananta. Guess what, next week’s midterm! It’s so fun innit :( But I need to continue the blog in order to accommodate the needs of the audience. LOL

This week’s assignment is the sixth module of the embedded systems course in this semester. So what’s so unique about this module is that this week we no longer refer to a tutorial from randomnerdtutorial, but instead we combine two modules that have been experimented previously. We will use the last two modules for this experiment which are module four: external sensors on the ESP32, and also module five: display as an external representation tool of the ESP32.

As you can guess, in this module we will be using both of them at the same time. So the essence of this module experiment is that we have to display the aspects detected by the sensor on our external display, so in this module we no longer need to see the sensor results on the serial monitor. In this module, I chose to display room temperature and pressure on the display.

— — -Jumping to the components section, as usual we will need:
1. ESP32
2. Breadboard (optional)
3. MicroUSB cable
4. A PC with the Arduino IDE installed
5. Dupont cable
— — - And of course the main components for this module:
7. OLED Display
8. BMP280 Sensor

Furthermore, the circuit diagram. I arranged my circuit in Fritzing as shown below, and i attached the real life circuit too, a bit different but the wires formation is pretty much the same.

Now a little explanation for the circuit, I’m still connecting the sensor’s SCL with the GPIO 22 which is indeed an SCL sender on the ESP32, take a look again at this picture of GPIO specification on ESP32. I also still connect the sensor’s SDA with the GPIO 21 which is the SDA sender on the ESP32. As usual, the ESP32's ground is connected to the sensor’s ground and the ESP32 voltage is connected to the sensor’s voltage. After that we can just connect the sensor to the display. It’s easy, connect SDA to SDA, SCL to SCL, ground to ground, and voltage to voltage, respectively on the display and sensor.

The next step is the process of writing code. I’m actually quite confused because I was not given a tutorial that directly contains sample code, but I’m thinking of combining the codes from the two previous modules. Unfortunately it failed hahaha, the code could not compile, it said that the <SPI.H> library could not be found, even though the use of the library was fine 2 weeks ago.

So I tried to look for another similar tutorials. It’s quite difficult to find a combination of OLED and BMP280 tutorial , but I found a similar tutorial using a DHT sensor. With a little modification, it turned out that there was still some error too hahaha, apparently I forgot to change readHumidity to readPressure. I re-proofread it, and am ready to run the program. The program can be compiled, but strangely nothing happens to OLED, I was curious and opened the monitor serial. The output seen on the serial monitor is that the ESP32 cannot detect any BMP280 and told me to check the wires. I’m so confused, I tried running the code I used two weeks ago to run only BMP280, the same error message still came out. Because I was confused for too long, I tried to unplug all the cables that lead to the OLED, and tried to run it again, it WORKS !!! The sensor is detected by the ESP32 and gave temperature, pressure and altitude output. Then I reconnected the OLED with the BMP280 and ran the final program, apparently the output came out as expected, yay!

You can find the code here anyway::

The code isn’t so much different than the code used in display and sensor module

All you got to do to show the value from the sensor to the display is by making a new variable, here I’m using h and t as floats to store the values from the sensor. And the next right thing is to print that using code from the display module.This is the sample code for showing pressure

  float t = bmp.readTemperature();
float h = bmp.readPressure();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from BMP sensor!");
display.setTextSize(1);
display.setCursor(0, 35);
display.print("Pressure: (in Pa)");
display.setTextSize(2);
display.setCursor(0, 45);
display.print(h);
display.print(" ");

display.display();

I’ll show you how did my experiment go in this video, make sure to check this out 😉

Conclusion and analysis

Well this is the most difficult module so far, hahaha because this is the first module without tutorial from a website. However, if we are willing to try new things and keep our spirits up, even a hard obstacle wouldn’t stop us. Be careful in writing code, I had a failure because I forgot to write the address sensor in the code, but it’s okay becaus failure is just a delayed success. When we are using a complex program but the program does not run, try scanning the entire program and sequence with a simpler program to detect the location of the error. Like earlier I separated the sensor from the display to find out if the error was in the sensor area or the display area

The next lesson, when we are sure about the software we are using, but the program is still not running, we have to check the hardware that the program will run, whether something is damaged, or have to restart it. Don’t be afraid to start over because by starting over we can find gaps where we made mistakes before and fix them.

That’s all for this week guys, I hope you enjoy your weekend. (I Wayan Ananta Suandira / 18219038)

--

--