Using I2C OLED with Si7021

I have been able to successfully use my I2C Si7021 temp/humidity sensor with the serial monitor. This is a good sensor for my many student projects. I have been searching for code that would help me use my I2C 128x32 OLED display to show my readings. Ultimately I will set up a small sensor that can be run anywhere (away from a computer serial monitor). I am a science teacher that frequently uses arduinos for student projects, but I am still a novice at code and usually download existing code (and manipulate values). Looking for some advice.

I use a library from Bill Greiman. It is text only (no graphics) but is very small and easy to use.

// Simple I2C test for ebay 128x64 oled.
// Uses the standard Wire.h class as we think the BME680 will already use wire. was: Use smaller faster AvrI2c class in place of Wire.
// Edit AVRI2C_FASTMODE in SSD1306Ascii.h to change the default I2C frequency.
// 2019-05-17 added Bill Greiman's comment regarding the addition of "Wire.begin()"  now working at 100Khz

#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"

#define I2C_ADDRESS 0x3C	// 0x3C alt add = 0x3D
SSD1306AsciiWire oled;		// create an "oled" object

//------------------------------------------------------------------------------
// Setup displays variable names and units.
//  We still have to identify the location and length for variable values.
//  We should in the future create functions to do the length and position calc.

void setup() {

  Wire.begin();
  Wire.setClock(100000);
  
  oled.begin(&SH1106_128x64, I2C_ADDRESS);
  oled.setFont(ZevvPeep8x16);  // results in 4 lines X 16 characters
  oled.clear();

// Fill display so we can see what is being cleared.
  oled.println("----------------");
  oled.println("----------------");
  oled.println("----------------");
  oled.println("----------------");
  delay(1000);

//							  (C,R)
  oled.SSD1306Ascii::setCursor(0,0);
  oled.print("Temp");				// leaves cursor at next char in row.
  oled.SSD1306Ascii::setCursor(8*14,0);
  oled.print("$F");
  oled.clearField(8*4,0,10);

  oled.SSD1306Ascii::setCursor(0,2);	// note rows are 8 pixels and our font is 16 pixels
  oled.print("Humidity");				// leaves cursor at next char in row.
  oled.SSD1306Ascii::setCursor(8*15,2);
  oled.print("%");
  oled.clearField(8*8,2,7);
  
  oled.SSD1306Ascii::setCursor(0,4);
  oled.print("Pressure");				// leaves cursor at next char in row.
  oled.SSD1306Ascii::setCursor(8*13,4);
  oled.print("hPa");
  oled.clearField(8*8,4,5);
 
  oled.SSD1306Ascii::setCursor(0,6);
  oled.print("IAQ   both");				// leaves cursor at next char in row.
  oled.clearField(8*3,6,13);
} 

void loop() {}




This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.