0

Adafruit AHT sensor, ESP32 Feather and OLED display
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit AHT sensor, ESP32 Feather and OLED display

by lilypalumbo on Tue Jun 28, 2022 2:14 pm

Currently having trouble finding/ writing code that helps us use the AHT temperature and humidity sensor readings to be displayed onto the Featherwing OLED Display. I can get the sensor to work with one code and it reads the temperature and humidity to the serial monitor, and the display to work on the OLED display with another code but I cannot link them together, so that the display reads the sensor readings. Any suggestions?

lilypalumbo
 
Posts: 5
Joined: Tue Jun 28, 2022 2:07 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by dastels on Tue Jun 28, 2022 2:28 pm

Don't try to mash the actual code together, but take what you've learned in each. You can read from the sensor and you can display to the screen. Now you need to take those readings and convert then to strings to be displayed. Are you using C++ or CircuitPython?

Dave

dastels
 
Posts: 10563
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by lilypalumbo on Tue Jun 28, 2022 2:32 pm

We are using Arduino for coding. We aren't familiar with coding so I am not sure how to write that type of code from scratch.

I am using this for the sensor:

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit AHT10/AHT20 demo!");

  if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  }
  Serial.println("AHT10 or AHT20 found");
}

void loop() {
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
  Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
  Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");

  delay(500);
}

and this for the display:
Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>

Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);

// OLED FeatherWing buttons map to different pins depending on board:
#if defined(ESP8266)
  #define BUTTON_A  0
  #define BUTTON_B 16
  #define BUTTON_C  2
#elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
#elif defined(ARDUINO_STM32_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
#elif defined(TEENSYDUINO)
  #define BUTTON_A  4
  #define BUTTON_B  3
  #define BUTTON_C  8
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
#else // 32u4, M0, M4, nrf52840, esp32-s2 and 328p
  #define BUTTON_A  9
  #define BUTTON_B  6
  #define BUTTON_C  5
#endif

void setup() {
  Serial.begin(115200);

  Serial.println("128x64 OLED FeatherWing test");
  delay(250); // wait for the OLED to power up
  display.begin(0x3C, true); // Address 0x3C default

  Serial.println("OLED begun");

  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(1000);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  display.setRotation(1);
  Serial.println("Button test");

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);

  // text display tests
  display.setTextSize(1);
  display.setTextColor(SH110X_WHITE);
  display.setCursor(0,0);
  display.print("Connecting to SSID\n'adafruit':");
  display.print("connected!");
  display.println("IP: 10.0.1.23");
  display.println("Sending val #0");
  display.display(); // actually display all of the above
}

void loop() {
  if(!digitalRead(BUTTON_A)) display.print("A");
  if(!digitalRead(BUTTON_B)) display.print("B");
  if(!digitalRead(BUTTON_C)) display.print("C");
  delay(10);
  yield();
  display.display();
}


They are both examples from the libraries I have downloaded.
Last edited by dastels on Tue Jun 28, 2022 6:56 pm, edited 2 times in total.
Reason: Add code block

lilypalumbo
 
Posts: 5
Joined: Tue Jun 28, 2022 2:07 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by dastels on Tue Jun 28, 2022 6:58 pm

Set up the display along with the sensor and instead of printing to Serial, print to display. There are details, but that should get you most of the way.

Dave

dastels
 
Posts: 10563
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by lilypalumbo on Fri Jul 01, 2022 10:59 am

Thank you for your help. I've been trying to take your suggestions and still not getting the sensor output to come onto the display. Is there any other details I could be missing? I am just not fluent in coding language so this has been a struggle for me.

lilypalumbo
 
Posts: 5
Joined: Tue Jun 28, 2022 2:07 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by dastels on Fri Jul 01, 2022 11:19 am

Let's see what you have so far.

Dave

dastels
 
Posts: 10563
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by lovetheants on Fri Jul 01, 2022 12:10 pm

Hi, I'm working on the same thing and also stuck. Here's the code I've tried to put together... can you take a look, please? The goal is just to get the feather OLED to read out the temperature and humidity data.

https://collabedit.com/3pe5h

Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Adafruit_AHTX0.h>

Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
Adafruit_AHTX0 aht;

void setup() {
  Serial.begin(115200);

  Serial.println("128x64 OLED WatersLab Test");
  delay(250); // wait for the OLED to power up
  display.begin(0x3C, true); // Address 0x3C default

  Serial.println("OLED begun");

  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(1000);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  display.setRotation(1);


  // text display tests
  display.setTextSize(1);
  display.setTextColor(SH110X_WHITE);
  display.setCursor(0,0);
  display.print("Connecting to SSID\n'adafruit':");
  display.print("connected!");
  display.println("IP: 10.0.1.23");
  display.println("Sending val #0");
  display.display(); // actually display all of the above
}

void loop() {
  delay(10);
  yield();
  display.display();
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
  display.println("Temperature: "); display.print(temp.temperature); display.println(" degrees C");
  display.println("Humidity: "); display.print(humidity.relative_humidity); display.println("% rH");
  delay(500);
}

lovetheants
 
Posts: 5
Joined: Mon Mar 22, 2021 11:35 am

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by dastels on Fri Jul 01, 2022 12:49 pm

And what happens when you run this code?

Dave

dastels
 
Posts: 10563
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by lilypalumbo on Fri Jul 01, 2022 3:57 pm

When we use that code, it compiles and uploads to the feather, but then the old display just flashes back and forth between the Adafruit symbol and the default page, and on the serial monitor it doesn't display any values of temperature or humidity.

lilypalumbo
 
Posts: 5
Joined: Tue Jun 28, 2022 2:07 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by dastels on Fri Jul 01, 2022 4:18 pm

Do you see "128x64 OLED WatersLab Test" and "OLED begun", and the WiFi related output. You can remove that since it isn't relevant. You shouldn't need to yield in this code. And put display.display(); just before the delay(500);.

What do you mean by "default page"? You're not outputting the measurements to Serial so they won't show up in the serial monitor.

Dave

dastels
 
Posts: 10563
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by lilypalumbo on Fri Jul 01, 2022 4:34 pm

Okay, I will try that. And sorry, by default page I meant when it turns on it displays a screen that says some of the product information that it was set to from the example code. So it just says like, "welcome Adafruit" and it says some SSID information.

lilypalumbo
 
Posts: 5
Joined: Tue Jun 28, 2022 2:07 pm

Re: Adafruit AHT sensor, ESP32 Feather and OLED display

by dastels on Fri Jul 01, 2022 5:02 pm

Are you sure it's uploading correctly?

Dave

dastels
 
Posts: 10563
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.