๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Showing BME280 on 128x32 OLED display i2C
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Showing BME280 on 128x32 OLED display i2C

by amithlon on Mon Nov 19, 2018 8:28 am

Have used the BME280 and OLED 128x32 display.
Both are i2c Display 0x3C sesnor (temp/hum/baro) 0x76
The sample code shows the serial write from the sensor is working OK.
It also shows that the display is writing correctly.

Question is what code is needed to actually show that temp/press/hum on the display - just cant seem to get it right...

Any help greatfully accepted, even prepared to offer a donation for assistance.
amithlon
 
Posts: 7
Joined: Tue Sep 03, 2013 3:22 am

Re: Showing BME280 on 128x32 OLED display i2C

by millercommamatt on Mon Nov 19, 2018 4:53 pm

Post your code and write specifically about what's not working.

millercommamatt
 
Posts: 508
Joined: Tue Jul 31, 2018 4:57 pm

Re: Showing BME280 on 128x32 OLED display i2C

by amithlon on Mon Nov 19, 2018 9:14 pm

That iss the problem - i have no idea how to actually put the sensor readings on the display.
i have no code . i can see how they read the sensor, and can see various demo display i cant find any examples specifically for these 2 items. plenty for 1602 lcd etc even the esp units, but not this. guess i need to either find a sample or the instructions related to printing values on the oled... i am pretty green on all this display stuff.
amithlon
 
Posts: 7
Joined: Tue Sep 03, 2013 3:22 am

Re: Showing BME280 on 128x32 OLED display i2C

by amithlon on Tue Nov 20, 2018 2:10 am

oops, one point i did forget - arduino, not pi ! - big difference, my bad!
amithlon
 
Posts: 7
Joined: Tue Sep 03, 2013 3:22 am

Re: Showing BME280 on 128x32 OLED display i2C

by millercommamatt on Tue Nov 20, 2018 12:13 pm

Not promises this works. I don't have matching hardware. I trimmed and mashed together the examples from the required libraries. You would need to make sure the pin numbers are correct and things like that. There SPI stuff in here that I'm not sure belongs.

This needs ADAFRUIT_BME280 library and the ADAFRUIT_SSD1306 library and their dependencies.

Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

Adafruit_BME280 bme; // I2C

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

void setup() {
  Serial.begin(9600);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
    bool status;
   
    // default settings
    // (you can also pass in a Wire library object like &Wire2)
    status = bme.begin(); 
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);
    }
  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...
}

void loop() {
  printValues();
}

void printValues() {
  display.clearDisplay();
  display.setTextSize(1);      // Normal 1:1 pixel scale
  display.setTextColor(WHITE); // Draw white text
  display.setCursor(0, 0);     // Start at top-left corner
  //display.cp437(true);         // Use full 256 char 'Code Page 437' font
    display.println("Temperature = ");
    display.print(bme.readTemperature());
    display.println(" *C");

    display.println("Pressure = ");
    display.print(bme.readPressure() / 100.0F);
    display.println(" hPa");

    display.println("Humidity = ");
    display.print(bme.readHumidity());
    display.println(" %");

    display.display();
}

millercommamatt
 
Posts: 508
Joined: Tue Jul 31, 2018 4:57 pm

Re: Showing BME280 on 128x32 OLED display i2C

by amithlon on Wed Nov 21, 2018 4:06 am

I like the neat code, makes life a lot easier.
I found as it stands it can't find the sensor, yet other software can.
I am thinking the address is wrong, i have (from i2c scanner) Display at 0x3C and sensor t 0x76
but can't see any reference to altering the sensor address.
Bu then i could be totally wrong (i am a neophyte after all)
amithlon
 
Posts: 7
Joined: Tue Sep 03, 2013 3:22 am

Re: Showing BME280 on 128x32 OLED display i2C

by amithlon on Wed Nov 21, 2018 7:46 am

Just found a link on the net, used notepad to correct the address in the .h file and bingo!
this should be an example in the main library as a really good way of showing the use of both sensor/read/write and display to the oled.
3 thumbs up fella's (also fixing address if different)
amithlon
 
Posts: 7
Joined: Tue Sep 03, 2013 3:22 am

Re: Showing BME280 on 128x32 OLED display i2C

by millercommamatt on Wed Nov 21, 2018 11:46 am

Instead of editing the library file you can give the code the I2C address.

Code: Select all | TOGGLE FULL SIZE
...

status = bme.begin(<your address i.e. 0x76>);

...



Your I2C address is 0x76 because you have SDO tied to ground. Let if float and you should have 0x77.

millercommamatt
 
Posts: 508
Joined: Tue Jul 31, 2018 4:57 pm

Re: Showing BME280 on 128x32 OLED display i2C

by millercommamatt on Wed Nov 21, 2018 11:48 am

I'd also like to see an image showing the output. I cobbled that code together without any testing and I've never used that display before. If not setting the I2C address is the only thing that didn't work, I'd be amazed with myself.

millercommamatt
 
Posts: 508
Joined: Tue Jul 31, 2018 4:57 pm

Re: Showing BME280 on 128x32 OLED display i2C

by amithlon on Thu Nov 22, 2018 5:54 am

be amazed with yourself - it worked perfectly, the cod eis exactly as you sent - with the address mod.
congrats and kudos - you are amazbeans.
amithlon
 
Posts: 7
Joined: Tue Sep 03, 2013 3:22 am

Re: Showing BME280 on 128x32 OLED display i2C

by kflmiami420 on Fri Jun 14, 2019 10:36 am

amithlon


Do you have some photos of your project that you can post or a link to them ? I am now interested in a little display for my sensors in my project.

I have a handfull of I2C sensors and want to know what their data would look like in a small display like the one you are using
Last edited by kflmiami420 on Fri Jun 14, 2019 5:03 pm, edited 1 time in total.

kflmiami420
 
Posts: 124
Joined: Tue Aug 21, 2018 9:43 pm

Re: Showing BME280 on 128x32 OLED display i2C

by amithlon on Fri Jun 14, 2019 4:56 pm

have some photos. will post them later today (probably tomorrow if you are in USA or Euroope) - they worked well.
amithlon
 
Posts: 7
Joined: Tue Sep 03, 2013 3:22 am

Please be positive and constructive with your questions and comments.