Using an ESP32-WROOM-32U but I don't think the uC is relevant. I use only and all ESP32's for the various projects I develop (approaching 100 now).
No matter what I tried, I was unable to use both peripherals at the same time.
I'm now trying to do nearly the same thing but with a SHTC3 instead of the MAX.
Here's my sketch:
Code: Select all
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include "Adafruit_SHTC3.h"
#if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32
#define TFT_CS 14
#define TFT_RST 15
#define TFT_DC 32
#elif defined(ESP8266)
#define TFT_CS 2
#define TFT_RST 1
#define TFT_DC 3
#else
// For the breakout board, you can use any 2 or 3 pins.
// These pins will also work for the 1.8" TFT shield.
#define TFT_CS 14
#define TFT_RST 15 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 32
#endif
// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
// tradeoff being that performance is not as fast as hardware SPI above.
#define TFT_MOSI 21 // Data out
#define TFT_SCLK 22 // Clock out
// For ST7735-based displays, we will use this call
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
// OR for the ST7789-based displays, we will use this call
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
Adafruit_SHTC3 shtc3 = Adafruit_SHTC3();
float p = 3.1415926;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("SHTC3 test");
if (! shtc3.begin()) {
Serial.println("Couldn't find SHTC3");
while (1) delay(1);
}
Serial.println("Found SHTC3 sensor");
Serial.print(F("Hello! ST77xx TFT Test"));
// OR use this initializer (uncomment) if using a 1.44" TFT:
tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab
Serial.println(F("Initialized"));
uint16_t time = millis();
tft.fillScreen(ST77XX_BLACK);
time = millis() - time;
tft.fillScreen(ST77XX_BLACK);
Serial.println("done");
delay(1000);
}
int runningsecs = 0;
void loop() {
//digitalWrite(14, LOW);
//tftPrintTest();
//digitalWrite(14, HIGH);
sensors_event_t humidity, temp;
shtc3.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
/*
Serial.print("Temperature: "); Serial.print((temp.temperature * 1.8) + 32); Serial.println(" degrees F");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
float tempF = ((temp.temperature * 1.8) + 32);
String tempfAsString = String(tempF);
Serial.print("Converted temp: ");
Serial.println(tempfAsString);*/
//time = millis();
//digitalWrite(14, LOW);
tft.setCursor(0, 0);
tft.setTextSize(4);
tft.println(runningsecs);
Serial.println(runningsecs);
tft.println(String(temp.temperature));
//tft.println(dstime);
delay(1000);
tft.fillScreen(ST77XX_BLACK);
//digitalWrite(14, HIGH);
runningsecs++;
}
Code: Select all
sensors_event_t humidity, temp;
shtc3.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
/*
Serial.print("Temperature: "); Serial.print((temp.temperature * 1.8) + 32); Serial.println(" degrees F");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
float tempF = ((temp.temperature * 1.8) + 32);
String tempfAsString = String(tempF);
Serial.print("Converted temp: ");
Serial.println(tempfAsString);*/
Then when uncommented, the SHTC3 works properly and the screen does not update.