Code: Select all
#include <Wire.h> // Used to establish serial communication on the I2C bus
#include <SparkFun_TMP117.h> // Used to send and recieve specific information from our sensor
// The default address of the device is 0x48 = (GND)
TMP117 sensor; // Initalize sensor
#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex
int TIME_TO_SLEEP = 5; // Time ESP32 will go to sleep (in seconds)
unsigned long long uS_TO_S_FACTOR = 1000000; // Conversion factor for microseconds to seconds
RTC_DATA_ATTR int bootCount = 0; // Number of reboots
void setup() {
/**** Do your stuff here! ****/
Serial.begin(115200); // Start serial communication at 115200 baud rate
Wire.begin();
Wire.setClock(400000); // Set clock speed to be the fastest for better communication (fast mode)
sensor.begin();
++bootCount; // Add 1 to the current value of bootCount
Serial.println("Boot number: " + String(bootCount)); // print the value of bootCount on the serial monitor
if (sensor.dataReady() == true) // Function to make sure that there is data ready to be printed, only prints temperature values when data is ready
{
float tempC = sensor.readTempC();
float tempF = sensor.readTempF();
// Print temperature in °C and °F
Serial.println(); // Create a white space for easier viewing
Serial.print("Temperature in Celsius: ");
Serial.println(tempC);
Serial.print("Temperature in Fahrenheit: ");
Serial.println(tempF);
}
Serial.println("Going to sleep now"); // Print when the ESP is about to go into deep sleep mode
/* Now we wrap up for Deep Sleep - I hope you did everything you needed to... */
//esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); // Set up timer as the wake up source and set sleep duration to 5 seconds
//esp_sleep_enable_timer_wakeup(750000);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,HIGH);
Serial.flush(); // Waits for the transmission of outgoing serial data to complete.
esp_deep_sleep_start(); // Start the deep sleep mode
}
void loop() {
// This is not going to be called
}