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);