Page 1 of 1

ESP32 OLED interfacing issue any ideas?

Posted: Fri Jul 07, 2017 7:43 pm
by machman2823
Hello,
I am trying to make a small electronic multi tool, using an ESP32 dev board with an OLED screen.
I have a dht11, and a chronoDot both using I2C just fine, but the OLED (https://www.adafruit.com/product/938) using SPI will not display anything.
I know the screen and code are good (code works perfectly on a pro mini), and the ESP32 is outputting the data just fine with Serial.print(). The OLED screen is setup for SPI, it can do I2C, but I would like to use SPI if possible.

Any help getting the OLED screen working with the ESP32 would be greatly appreciated

Here is the code, it's just a start for now, and will use wifi and ble when it is done.

Code: Select all

#include <Adafruit_Sensor.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RTClib.h>
#include <DHT.h>
#include <DHT_U.h>
#include <SPI.h>
#include <Wire.h>

#define DHTPIN            23         // Pin which is connected to the DHT sensor.
#define DHTTYPE           DHT11     // DHT 11 
DHT_Unified dht(DHTPIN, DHTTYPE);

// If using software SPI (the default case):
#define OLED_MOSI   16
#define OLED_CLK   5
#define OLED_DC    23
#define OLED_CS    19
#define OLED_RESET 18
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

#define XPOS 0
#define YPOS 1
#define DELTAY 2

RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

uint32_t delayMS;

int temp;
int humi;

void setup()
{
  display.begin(SSD1306_SWITCHCAPVCC);
  display.clearDisplay();
  Serial.begin(9600);
  dht.begin();
  sensor_t ths;
  dht.temperature().getSensor(&ths);
  Serial.println("------------------------------------");
  Serial.println("Temperature");
  Serial.print  ("Sensor:       "); Serial.println(ths.name);
  Serial.print  ("Driver Ver:   "); Serial.println(ths.version);
  Serial.print  ("Unique ID:    "); Serial.println(ths.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(ths.max_value); Serial.println(" *C");
  Serial.print  ("Min Value:    "); Serial.print(ths.min_value); Serial.println(" *C");
  Serial.print  ("Resolution:   "); Serial.print(ths.resolution); Serial.println(" *C");
  Serial.println("------------------------------------");
  // Print humidity sensor details.
  dht.humidity().getSensor(&ths);
  Serial.println("------------------------------------");
  Serial.println("Humidity");
  Serial.print  ("Sensor:       "); Serial.println(ths.name);
  Serial.print  ("Driver Ver:   "); Serial.println(ths.version);
  Serial.print  ("Unique ID:    "); Serial.println(ths.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(ths.max_value); Serial.println("%");
  Serial.print  ("Min Value:    "); Serial.print(ths.min_value); Serial.println("%");
  Serial.print  ("Resolution:   "); Serial.print(ths.resolution); Serial.println("%");
  Serial.println("------------------------------------");
  // Set delay between sensor readings based on sensor details.
  delayMS = ths.min_delay / 1000;
}

void loop()
{
  // Delay between measurements.
  delay(delayMS);

  sensors_event_t event;
  dht.temperature().getEvent(&event);

  if (isnan(event.temperature))
  {
    Serial.println("Error reading temperature!");
  }
  else
  {
    Serial.print("Temperature: ");
    Serial.print(event.temperature);
    Serial.println(" *C");
    temp = (event.temperature);
  }

  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity))
  {
    Serial.println("Error reading humidity!");
  }
  else
  {
    Serial.print("Humidity: ");
    Serial.print(event.relative_humidity);
    Serial.println("%");
    humi = (event.relative_humidity);
  }
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(10, 1);
  display.clearDisplay();
  display.print(temp); 
  display.print(" *C, ");
  display.print((temp*1.8)+32); 
  display.println(" *F, ");
  display.print(humi); 
  display.println(" % Humidity");
  
  display.display();
}

//    Serial.print(now.month(), DEC);
//    Serial.print('/');
//    Serial.print(now.day(), DEC);
//    Serial.print(" (");
//    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
//    Serial.print(") ");
//    Serial.print(now.hour(), DEC);
//    Serial.print(':');
//    Serial.print(now.minute(), DEC);

Re: ESP32 OLED interfacing issue any ideas?

Posted: Mon Jul 10, 2017 6:30 pm
by chegewara
I think its problem with this line:

Code: Select all

display.begin(SSD1306_SWITCHCAPVCC);
You didnt set 3rd parameter (reset) to true, and display need to be reseted. Try this:

Code: Select all

display.begin(SSD1306_SWITCHCAPVCC, null, true);

Re: ESP32 OLED interfacing issue any ideas?

Posted: Tue Jul 11, 2017 6:30 am
by machman2823
Copying what you sugested threw this "'null' was not declared in this scope" But, if null is removed, it does compile, I will upload the software when I get to work in the morning. Thank you, I will let you know what happens when it gets uploaded.

Re: ESP32 OLED interfacing issue any ideas?

Posted: Tue Jul 11, 2017 4:23 pm
by chegewara
Then try -1 as 2nd param.

Re: ESP32 OLED interfacing issue any ideas?

Posted: Tue Jul 11, 2017 5:53 pm
by machman2823
-1 doesn't work either, tried the software spi and the other option in the adafruit code, nothing. do I have the pins wrong? i've tried a few different pin combinations as well. thanks for your fast replies.

Re: ESP32 OLED interfacing issue any ideas?

Posted: Tue Jul 11, 2017 7:51 pm
by chegewara
2nd parameter is irrelevant, its i2c address. When you use spi then it is ignored. Try one more thing:

Code: Select all

#define ESP32