Go Down

Topic: Sensor Problem using Monochrome OLED I2C with Adafruit Library  (Read 214 times) previous topic - next topic



I have the following code. using 128x64 Oled display and SHT10 temperature humidity sensor on Arduino Mega.

I connected the CLK and DAT pins of both SHT10 and OLED display directly to I2C pins on mega, pins 20 and 21.

I cannot read data from SHT10 sensors when I run it with ADafruit library and oled. The values are all -40 and -4 if I try to display sht10 data on screen or view it with serial monitor.

Seperately things seem fine.

I read on this page https://learn.adafruit.com/2-3-monochrome-128x32-oled-display-module/wiring-and-test that "If using with other I2C devices"... they "....suggest using a 3V-logic arduino or an I2C-safe shifter."

Am I having this sensor problem because I'm not using shifter?

Code: [Select]

#include <SPI.h>
#include <Wire.h> //DS3231 librarysi
#include <SHT1x.h>
#define dataPinSHT  20
#define clockPinSHT 21
SHT1x sht1x(dataPinSHT, clockPinSHT);

#include <RunningAverage.h>
RunningAverage raMinute_OutsideHumiditySensor(10);
RunningAverage raHour_OutsideHumiditySensor(10);
int OutsideHumiditySamples = 0;
int OutsideHumiditySensorValue = 0;

RunningAverage raMinute_OutsideSicaklikSensor(10);
RunningAverage raHour_OutsideSicaklikSensor(10);
int OutsideTempSamples = 0;
int OutsideTempSensorValue = 0;

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 43
Adafruit_SSD1306 display(OLED_RESET);
static const unsigned char PROGMEM logo16_glcd_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
#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");

int Outside_Humidity =0;
int Outside_Temp =0;

void setup()   { ///---------------------------------------------------------------------------------------------------------SETUP
Serial1.begin(4800); //9600bps is default for OpenLog

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)

  //////////////////////////////////////////////////*20* OUTSIDE HUMIDITY VE TEMP OKUMA ORTALAMALARI////////////////////////////////////

} ///---------------------------------------------------------------------------------------------------------SETUP----------------------------------------------------------------------------

void loop() { //-----------------------------------------------------------------------------------LOOP:

Outside_Humidity = OutsideHumidityRead();
  Outside_Temp = OutsideTempRead();
  display.setCursor(0, 0);
  display.setTextColor(WHITE); display.print("OUTSIDE TEMP:"); display.setTextColor(WHITE);   display.println(Outside_Temp);
    display.setTextColor(WHITE); display.print("OUTSIDE HUMIDITY:"); display.setTextColor(WHITE);   display.println(Outside_Humidity);


} // ------------------------------------------------------------------------------------------------LOOP-------------------------------------------- -

int ValueFontColor(int VariableLowValue, int VariableHighValue, int VariableValue)
  if (VariableValue <= VariableLowValue || VariableValue >= VariableHighValue)
  { return 0;
    return 1;

int ValueBackGroundColor(int VariableLowValue, int VariableHighValue, int VariableValue)
  if (VariableValue <= VariableLowValue || VariableValue >= VariableHighValue)
  { return 1;
    return 0;

int OutsideHumidityRead() {
  OutsideHumiditySensorValue =  sht1x.readHumidity();
  Serial.print("OutsideHumiditySensorValue: ");  Serial.println(OutsideHumiditySensorValue);

  if (OutsideHumiditySamples % 10 == 0) raHour_OutsideHumiditySensor.addValue(raMinute_OutsideHumiditySensor.getAverage());
  Serial.print("Veri 1: Outside Humidity Seviyesi Dakikalik Ortalama:");//prints out liquid level sensor reading
  Serial.println(raMinute_OutsideHumiditySensor.getAverage());//prints out liquid level sensor reading
  return raMinute_OutsideHumiditySensor.getAverage();

int OutsideTempRead() {
  OutsideTempSensorValue = sht1x.readTemperatureC();

 Serial.print("OutsideTempSensorValue: ");  Serial.println(OutsideTempSensorValue);

  if (OutsideTempSamples % 10 == 0) raHour_OutsideTempSensor.addValue(raMinute_OutsideTempSensor.getAverage());
  Serial.print("Veri 2: Outside Temp Seviyesi Dakikalik Ortalama:");//prints out liquid level sensor reading
  Serial.println(raMinute_OutsideTempSensor.getAverage());//prints out liquid level sensor reading
  return raMinute_OutsideTempSensor.getAverage();

void MyOpenLog(){

  delay(1000); //Wait a second for OpenLog to init

  Serial1.println("Run OpenLog Test");



I got around a similar issue by using William Greiman's library for monochrome oled displays. It doesn't do the graphics the Adafruit library does, but it has a much smaller memory footprint.
Wubba lubba dub dub!



I switched to William Greiman's library for monochrome oled displays and it seems like a much cleaner simpler library. The oled I have is working nicely withit however I have 2 issues

1) I dont know how to display the sensor values on the screen. The example code had the display values shown in SETUP however when I put the values inside loop in doesnt show or flickers beyond control.

2) After I plugged in the RTC realtime clock #include <Sodaq_DS3231.h>  wow I'm having issues again with the SHT10 sensor. So I believe there is something wrong with the library I'm using for the SHT sensor #include <SHT1x.h>


Sorry I forgot to put   oled.clear();   in code so now the issue #1 above is solved.


the main issue was the sht10 sensor, I had to plug it to pins other than i2c pins of the arduino. all resolved now.

The SHT1x is not true I2C. Putting it and a real I2C on the same pins means the 2 drivers will conflict with each other.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131