Arnov Sharma
Published © GPL3+

MacTEMPtosh

MacTEMPtosh is a small portable Temperature and Humidity Monitor that displays real-time TEMP and Humidity data on an OLED Display.

BeginnerFull instructions provided1 hour257

Things used in this project

Hardware components

Espressif ESP32 Development Board - Developer Edition
Espressif ESP32 Development Board - Developer Edition
×1
aht10
×1
PCBWay Custom PCB
PCBWay Custom PCB
×1
ssd1306
×1

Software apps and online services

Fusion
Autodesk Fusion
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Fusion360File

Schematics

sch

Code

code

C/C++
#include <Wire.h>
#include <AHTxx.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

float ahtValue;                               //to store T/RH result

AHTxx aht10(AHTXX_ADDRESS_X38, AHT1x_SENSOR); //sensor address, sensor type


void setup()
{
  
  display.begin(SSD1306_SWITCHCAPVCC,0x3C);
  display.clearDisplay();
  
  #if defined(ESP8266)
  WiFi.persistent(false);  //disable saving wifi config into SDK flash area
  WiFi.forceSleepBegin();  //disable AP & station by calling "WiFi.mode(WIFI_OFF)" & put modem to sleep
  #endif

  Serial.begin(115200);
  Serial.println();
  
  while (aht10.begin() != true) //for ESP-01 use aht10.begin(0, 2);
  {
    Serial.println(F("AHT1x not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free

    delay(10000);
  }

  Serial.println(F("AHT10 OK"));

}

void loop()
{
  Serial.println();
  Serial.println(F("DEMO 1: read 12-bytes"));

  ahtValue = aht10.readTemperature(); //read 6-bytes via I2C, takes 80 milliseconds
  
    display.display();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(1, 0);
    display.println(F("TEMP C"));
    display.display();
    
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(0, 35);
    display.println(ahtValue);
    display.display();

    display.clearDisplay();
    delay(20000);
    

 ahtValue = aht10.readHumidity(); //read another 6-bytes via I2C, takes 80 milliseconds
   
    
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(1, 0);
    display.println(F("Humidity %"));
    display.display();

    display.setTextSize(3);
    display.setTextColor(WHITE);
   display.setCursor(0, 35);
    display.println(ahtValue);
    display.display();
    
    display.clearDisplay();
    delay(20000);
}

void printStatus()
{
  switch (aht10.getStatus())
  {
    case AHTXX_NO_ERROR:
      Serial.println(F("no error"));
      break;

    case AHTXX_BUSY_ERROR:
      Serial.println(F("sensor busy, increase polling time"));
      break;

    case AHTXX_ACK_ERROR:
      Serial.println(F("sensor didn't return ACK, not connected, broken, long wires (reduce speed), bus locked by slave (increase stretch limit)"));
      break;

    case AHTXX_DATA_ERROR:
      Serial.println(F("received data smaller than expected, not connected, broken, long wires (reduce speed), bus locked by slave (increase stretch limit)"));
      break;

    case AHTXX_CRC8_ERROR:
      Serial.println(F("computed CRC8 not match received CRC8, this feature supported only by AHT2x sensors"));
      break;

    default:
      Serial.println(F("unknown status"));    
      break;
  }
}

Credits

Arnov Sharma
352 projects • 360 followers
I'm Arnov. I build, design, and experiment with tech—3D printing, PCB design, and retro consoles are my jam.

Comments