Car temperature display, (esp32, bmp180, ssd1806)

The thing about cars, nowadays the AC units are adjusted by the temperature unlike old cars. So you need to adjust the temperature in order to heat or cool the cabin. However, if you set the temperature too high or too cold, it will cost fuel and it is not really efficient.

In prius 30 series, there is an indicator for the outside temperature but there is nothing for the inside temperature. Also, there are not a lot of thermostat sold in stores which is visible at dark places. So, I created this display. It is organic led display which is called ssd1306. The lights are adequate and visible at night.

In this project, I used both bmp180 the air pressure and temperature sensor and ssd1306 the organic led display connected with I2C protocol. So it required a little bit of adjustments in the coding.

The theory

ssd1306 and bmp180 are connected to the esp32 via I2C protocol. Pretty much thats it. lol

Here’s a breakdown of the setup and key considerations:

Here’s a breakdown of the setup and key considerations:

  1. I2C Protocol and Device Addressing:
    • The I2C protocol enables multiple devices to communicate over the same bus using unique addresses.
    • Each device, such as the BMP180 sensor and SSD1306 display, is assigned a specific I2C address to distinguish it from others on the bus.
    • In our case, the BMP180 sensor had an I2C address of 0x77, which was used during initialization in the code (bmp.begin(0x77)).
  2. SSD1306 OLED Display Initialization:
    • The SSD1306 OLED display is initialized in the code using the Adafruit_SSD1306 library, specifying parameters such as screen width, height, and the I2C interface (&Wire).
    • Optionally, a reset pin can be declared in the initialization code if the specific SSD1306 variant requires it.
  3. Coding Adjustments for Multiple Devices:
    • When working with multiple devices using the I2C protocol, it’s crucial to ensure that the code correctly addresses each device and manages data exchange efficiently.
    • The ESP32 microcontroller orchestrates communication between the BMP180 sensor and SSD1306 display, allowing temperature data from the sensor to be displayed on the OLED screen.

By leveraging the I2C protocol and integrating the BMP180 sensor with the SSD1306 OLED display, this project provides a practical solution for monitoring cabin temperature in vehicles lacking built-in temperature displays. The OLED display’s visibility in low-light conditions enhances user experience and usability, making it a valuable addition to automotive applications.

In ssd1306, the initializing is pretty much done with below code.

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire,-1);

The reset pin also have to be declared, but the ssd1306 we used didn`t have one. So, the code was unexpectedly worked out fine without the -1.

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);

I`m not sure why though.

Code

There are some comments made as well to help understand the code.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_BMP085.h> // use above libraries, careful its not SPI connection
//画面のサイズの設定, settings on the screen
#define SCREEN_WIDTH    (128)
#define SCREEN_HEIGHT   (64)

//画面のサイズ(データシートから), setting on the screen size
#define SCREEN_ADDRESS  (0x3C)
Adafruit_BMP085 bmp;
int loopCount = 0;

// ディスプレイ変数の宣言, display declaration on the function
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);

void setup() {
  Serial.begin(115200);
bmp.begin(0x77);//0X76DATTA
  if (!bmp.begin()) {  // ! mark taking false of bmp.begin which mean if bmp didnt initialize, this code will be executed. 
    Serial.println("Could not find a valid BMP180 sensor, check wiring!");
   // while (1);
  }
  //Setup SSD1306
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
  Serial.println(F("SSD1306 can not allocate memory!"));
  return;
  }

  //Clear display.
  display.clearDisplay();

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 16);
  display.println("Hello world");
  display.print("Initializing..");
//      display.print(".");
//    cursorPosition++;
  display.display();

  delay(4000);
 display.clearDisplay();

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 16);
  display.println("Connected!");
//  display.print("Initializing..");
//      display.print(".");
//    cursorPosition++;
  display.display();
  delay(3000);
}

void loop() {  // Read pressure and temperature from BMP180
  float pressure = bmp.readPressure();
  float temperature = bmp.readTemperature();
////   pressure = bmp.readPressure();
////  temperature = bmp.readTemperature();
//  // Display pressure and temperature on On
  display.clearDisplay();
  display.setTextSize(2);
  
  //display.setTextColor(SSD1306_WHITE);
  //display.setTextColor(WHITE);
  display.setCursor(0, 18);
  display.println("Inside");
 // display.println("Pressure: ");
  display.print(((pressure)/100)); // divide for hPa , initial readings are in Pa 
  display.print("hPa");

 // display.print("Temperature: ");
  display.print(temperature);
 display.print((char)247);// this is the code for the simbol for the degrees, ° 
  display.println("C");// with this, it will be showed as ℃

display.display();
Serial.println(pressure);
Serial.println(temperature);
  delay(5000); // Adjust the delay according to your needs, inside is mili seconds 
}

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です