Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15652

Attempting to change references of SSD1306 to SH1106

$
0
0

Hello Everyone,

I am fairly new to Arduino and have been attempting my first project using a sensor and display.

I have a DHT22 sensor that I am trying to use with a SH1106 display. The problem is, the example I found online is written for a SSD1306 dsiplay.

My difficulty is changing the code to allow it to work with a SH1106 rather than the SSD1306.

The code provided is:

#include <Wire.h>
#include "DHT.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define DHTTYPE DHT22
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire, -1);
unsigned long delayTime;
uint8_t DHTPin = 2;
DHT dht(DHTPin, DHTTYPE);
float Temperature;
float Humidity;
float Temp_Fahrenheit;

  void setup() {
    Serial.begin(115200);
    pinMode(DHTPin, INPUT);
    dht.begin();
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
    display.display();
    delay(100);
    display.clearDisplay();
    display.display();
    display.setTextSize(1.75);
    display.setTextColor(WHITE);
  }


void loop(){
  Humidity = dht.readHumidity();

  // Read temperature as Celsius (the default)
  Temperature = dht.readTemperature();

  // Read temperature as Fahrenheit (isFahrenheit = true)
  Temp_Fahrenheit = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(Humidity) || isnan(Temperature) || isnan(Temp_Fahrenheit)) {

    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  Serial.print(F("Humidity: "));
  Serial.print(Humidity);
  Serial.print(F("%  Temperature: "));
  Serial.print(Temperature);
  Serial.print(F("°C "));
  Serial.print(Temp_Fahrenheit);
  Serial.println(F("°F "));
  display.setCursor(0, 0);
  display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.print("Temperature: ");
  display.setTextSize(2);
  display.setCursor(0, 10);
  display.print(Temperature);
  display.print(" ");
  display.setTextSize(1);
  display.cp437(true);
  display.write(167);
  display.setTextSize(2);
  display.print("C");
  display.setTextSize(1);
  display.setCursor(0, 35);
  display.print("Humidity: ");
  display.setTextSize(2);
  display.setCursor(0, 45);
  display.print(Humidity);
  display.print(" %");
  display.display();
  delay(1000);
}

Some of the steps I have taken so far are:
Change: #include <Adafruit_SSD1306.h> to #include <Adafruit_SH110X.h>

Change: Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire, -1); to
Adafruit_SH110X display = Adafruit_SH110X(128, 64, &Wire, -1);

When I tried to compile the sketch after making those changes, the error message I receive is:
Compilation error: 'SH110X' was not declared in this scope

I'm really confused about what I really need to change in order to get the sketch to compile. Or if it's just not possible to use a SH1106 display in this particular situation and I'll need to order a SSD1306 and try again?

If any of you could give me any ideas of what I can do going forward, I'd appreciate it so much.

Cheers,

Amy

4 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 15652

Latest Images

Trending Articles



Latest Images