Skip to content

Instantly share code, notes, and snippets.

@johnaboxall
Last active April 14, 2025 00:11
Show Gist options
  • Save johnaboxall/c5b858fe80298464a562d3c06b5723fb to your computer and use it in GitHub Desktop.
Save johnaboxall/c5b858fe80298464a562d3c06b5723fb to your computer and use it in GitHub Desktop.
// BMP180 library - https://github.com/adafruit/Adafruit-BMP085-Library
#include <Arduino.h>
#include <U8g2lib.h>
#include <Adafruit_BMP085.h>
#include <Wire.h>
U8G2_SSD1306_64X32_1F_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
Adafruit_BMP085 bmp;
int temperature;
void TCA9548A(uint8_t bus)
{
Wire.beginTransmission(0x70); // TCA9548A address is 0x70
Wire.write(1 << bus); // send byte to select bus
Wire.endTransmission();
}
void setup()
{
Wire.begin();
u8g2.begin();
TCA9548A(7); // select I2C bus 7 for the BMP180
if (!bmp.begin())
{
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
}
void loop()
{
// first, get the temperature from the BMP180
TCA9548A(7); // select I2C bus 7 for the BMP180
temperature = int(bmp.readTemperature());
// next, display the temperature on the OLED
TCA9548A(0); // select I2C bus 0 for the OLED
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_inb24_mr ); // choose a suitable font
u8g2.setCursor(0, 24);
u8g2.print(temperature);
u8g2.sendBuffer();
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment