// OLED pins details: https://docs.wokwi.com/parts/board-ssd1306
/* Library SPI.h configures the pin D21 of ESP32 as SDA (Serial DAta lne) to send the data to the LCD,
while pin D22 is configured as SCL (Serial CLock line) to sinchronize the serial data transmission between ESP32 & LCD.
https://youtu.be/CAvawEcxoPU */
#include <SPI.h> //List of commands: https://www.arduino.cc/reference/en/language/functions/communication/spi/
// Includes the library to allow the I2C communication from the micro to the LCD
#include <Wire.h> // https://www.arduino.cc/reference/en/language/functions/communication/wire/
/* Includes the library to manage the OLDE through I2C (Inter-Integrated Circuit) communication protocol by using
specific commands developed by Adafruit: https://wokwi.com/projects/344892392214626898 */
#include <Adafruit_GFX.h> //List of commands: http://adafruit.github.io/Adafruit-GFX-Library/html/class_adafruit___g_f_x.html#a6f6f1abccf677eac244fa17d105133ea
#include <Adafruit_SSD1306.h> //List of commands: https://adafruit.github.io/Adafruit_SSD1306/html/class_adafruit___s_s_d1306.html
// Assign values to constants that will help to define the widht and height of OLED display in pixels
#define SCREEN_WIDTH 128 // OLED display width as 128 pixels
#define SCREEN_HEIGHT 64 // OLED display height as 64 in pixels
// Declaration for OLED SSD1306 display connected using I2C
#define OLED_RESET -1 // ESP32 reset pin for display was defined as -1 because is not going to be used
#define SCREEN_ADDRESS 0x3C // The address already defined for the OLED display
//Intialized OLED display
Adafruit_SSD1306 displayOLED(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // &Wire means the microcontroller's primary I2C bus is going to be: used pin D22 SDA and D21 SCL
// Assign names to ESP32
#define PinAnalog 35 //ESP32 pin where the voltage from the temperature sensor is going be read
// Variables declarations
int DigitalValue, Resolution;
float Volts, TempC; // Valor equivalente en volts que se convirtieron a digital
//websute to convert images to code
//http://javl.github.io/image2cpp/
// 'Flame1Small', 37x50px
const unsigned char epd_bitmap_Flame1Small [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x80, 0x00, 0x00, 0x00, 0x38, 0x80, 0x00, 0x00, 0x00, 0xf8,
0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00,
0x00, 0x00, 0x01, 0x3e, 0x00, 0x00, 0x00, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xe0, 0x00,
0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x80, 0x00, 0x00, 0x07, 0xff, 0xc0, 0x00,
0x00, 0x03, 0xff, 0xe0, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00,
0x03, 0xfa, 0x00, 0x00, 0x00, 0x03, 0xfb, 0x00, 0x00, 0x00, 0x07, 0xf9, 0x80, 0x00, 0x00, 0x1f,
0xf9, 0xe0, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x00, 0x00, 0xff, 0xf8, 0x30, 0x00, 0x03, 0xff, 0xf0,
0x10, 0x00, 0x0c, 0xff, 0xf0, 0x00, 0x00, 0x19, 0xff, 0xe0, 0x00, 0x00, 0x33, 0xff, 0xe0, 0x00,
0x00, 0x23, 0xfc, 0xe0, 0x00, 0x00, 0x23, 0xfc, 0xe0, 0x00, 0x00, 0x23, 0xf8, 0xe2, 0x00, 0x00,
0x23, 0xf8, 0xe1, 0x00, 0x00, 0x31, 0xf8, 0xf1, 0x80, 0x00, 0x18, 0xf0, 0x70, 0x80, 0x00, 0x0f,
0xf0, 0x78, 0x00, 0x00, 0x03, 0xf0, 0x3c, 0x00, 0x00, 0x00, 0x78, 0x1f, 0x80, 0x00, 0x10, 0x38,
0x03, 0xf8, 0x00, 0x00, 0x18, 0x00, 0x7e, 0x00, 0x00, 0x1c, 0x00, 0x3e, 0x00, 0x08, 0x1c, 0x00,
0x1f, 0x00, 0x1c, 0x7c, 0x00, 0x1f, 0x00, 0x3f, 0xfc, 0x00, 0x0f, 0x80, 0x3f, 0xfc, 0x00, 0x0f,
0x80, 0x3f, 0xf8, 0x00, 0x0f, 0x80, 0x7f, 0xf0, 0x07, 0xff, 0x80, 0x39, 0xc0, 0x1f, 0xff, 0x00,
0x78, 0x00, 0x3f, 0xff, 0x00, 0x00, 0x3f, 0xff, 0x00, 0x00
};
// 'Flame2Small', 37x50px
const unsigned char epd_bitmap_Flame2Small [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x38,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x00,
0x00, 0x00, 0x03, 0xd8, 0x00, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x00, 0x00,
0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00,
0x3f, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x01, 0x80, 0x00, 0x00, 0x3f, 0x81, 0xc0, 0x00, 0x03, 0x1f,
0x83, 0xe0, 0x00, 0x00, 0x0f, 0xc7, 0xf0, 0x00, 0x00, 0x07, 0xff, 0xf8, 0x00, 0x00, 0x03, 0xff,
0xfc, 0x00, 0x03, 0x03, 0xff, 0xfc, 0x00, 0x07, 0x01, 0xff, 0xfe, 0x00, 0x0f, 0x01, 0xff, 0xfe,
0x00, 0x1f, 0x03, 0xff, 0xff, 0x00, 0x3f, 0x87, 0xff, 0xf9, 0x00, 0x3f, 0xff, 0xff, 0xf9, 0x00,
0x7f, 0xff, 0xff, 0xf9, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x00, 0x7f, 0xff, 0xff, 0xe2, 0x00, 0x71,
0xff, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x00, 0x03, 0xdf, 0x0f, 0xf0, 0x00, 0x07, 0xc0,
0x0e, 0x00, 0x00, 0x0f, 0xe0, 0x0c, 0x00, 0x00, 0x0f, 0xe0, 0x18, 0x01, 0x00, 0x1f, 0xf0, 0x18,
0x11, 0x00, 0x1f, 0xf0, 0x38, 0x01, 0x00, 0x1f, 0xf0, 0x78, 0x03, 0x00, 0x1f, 0xf0, 0x78, 0x07,
0x00, 0x1f, 0xf0, 0x78, 0x0f, 0x00, 0x1f, 0xe0, 0xfc, 0x3f, 0x00, 0x1b, 0xc0, 0x7f, 0xfe, 0x00,
0x18, 0x00, 0x7f, 0xfa, 0x00, 0x00, 0x3f, 0xff, 0xc0, 0x00
};
// 'Flame3Small', 37x50px
const unsigned char epd_bitmap_Flame3Small [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x03, 0xc0,
0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x21, 0xf0, 0x00,
0x00, 0x00, 0x20, 0xf8, 0x00, 0x00, 0x00, 0x20, 0xf4, 0x00, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00,
0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x80, 0x00, 0x00, 0x80, 0xf8, 0x80, 0x00, 0x00,
0x01, 0xf0, 0x00, 0x00, 0x01, 0xbf, 0xf0, 0x00, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x07, 0xff,
0xf0, 0x00, 0x00, 0x07, 0xff, 0xf8, 0x00, 0x00, 0x07, 0xff, 0xff, 0xf0, 0x00, 0x04, 0x07, 0xff,
0xfc, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x80, 0x00, 0x00, 0x7c, 0x7f,
0xc0, 0x00, 0x00, 0x7c, 0x3f, 0xe0, 0x04, 0x00, 0x3e, 0x3f, 0xe0, 0x04, 0x00, 0x3e, 0x1f, 0xe0,
0x04, 0x00, 0x3e, 0x1f, 0xe0, 0x04, 0x00, 0x3e, 0x3f, 0x90, 0x05, 0x00, 0x3e, 0x3f, 0xc0, 0x09,
0x00, 0x3c, 0x30, 0x80, 0x09, 0x00, 0x7c, 0x60, 0x00, 0x03, 0x80, 0x7c, 0x40, 0x00, 0x03, 0xc0,
0xf8, 0xc0, 0x00, 0x07, 0xff, 0xf8, 0xc0, 0x00, 0x1f, 0xff, 0xf0, 0xc0, 0x00, 0x3f, 0xff, 0xf0,
0xc0, 0x00, 0x3d, 0xff, 0xe0, 0x60, 0x80, 0x38, 0xff, 0x80, 0x7f, 0x80, 0x38, 0x3e, 0x00, 0x3f,
0x80, 0x30, 0x00, 0x00, 0x1f, 0x80, 0x30, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x00,
0x18, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'Flame4Small', 37x50px
const unsigned char epd_bitmap_Flame4Small [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x60,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00,
0x00, 0x04, 0x0f, 0xc0, 0x00, 0x00, 0x04, 0x0f, 0xe0, 0x00, 0x00, 0x10, 0x1f, 0xd0, 0x00, 0x00,
0x20, 0x1f, 0x90, 0x00, 0x00, 0x70, 0x1f, 0xb0, 0x00, 0x00, 0xf0, 0x3f, 0xf0, 0x00, 0x00, 0xf8,
0xff, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xe0, 0x00, 0x01, 0xff, 0xff, 0xe0, 0x00, 0x01, 0xff, 0xff,
0xc4, 0x00, 0x01, 0xff, 0xff, 0xc4, 0x00, 0x01, 0xff, 0xff, 0xcc, 0x00, 0x01, 0xff, 0xff, 0xc4,
0x00, 0x01, 0x03, 0xff, 0xe0, 0x00, 0x00, 0x01, 0xff, 0xf0, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00,
0x00, 0x09, 0xff, 0xff, 0xc0, 0x00, 0x09, 0xff, 0xff, 0xe0, 0x00, 0x09, 0xdf, 0xff, 0xf0, 0x00,
0x19, 0xdf, 0xff, 0xf0, 0x01, 0xc3, 0xcf, 0xff, 0xf0, 0x03, 0xc7, 0xcf, 0xff, 0xf0, 0x07, 0xff,
0xc3, 0xff, 0xf0, 0x0f, 0xff, 0xc0, 0x03, 0xf0, 0x0f, 0xff, 0xc0, 0x03, 0xf0, 0x19, 0xff, 0x80,
0x03, 0xe0, 0x18, 0xff, 0x80, 0x07, 0xc0, 0x18, 0x3e, 0x00, 0x1f, 0x80, 0x18, 0x00, 0x00, 0x7f,
0x00, 0x18, 0x00, 0x00, 0xfc, 0x00, 0x18, 0x00, 0x00, 0xf8, 0x00, 0x08, 0x00, 0x00, 0xf0, 0x00,
0x1c, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'RectangleSmall', 37x50px
const unsigned char epd_bitmap_RectangleSmall [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff,
0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff,
0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff,
0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff,
0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8,
0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff,
0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff,
0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff,
0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff,
0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8,
0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff,
0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff,
0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff,
0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff,
0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8,
0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xf8
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 1360)
const int epd_bitmap_allArray_LEN = 5;
const unsigned char* epd_bitmap_allArray[5] = {
epd_bitmap_Flame1Small,
epd_bitmap_Flame2Small,
epd_bitmap_Flame3Small,
epd_bitmap_Flame4Small,
epd_bitmap_RectangleSmall
};
void setup()
{
Serial.begin(9600);
// Configure Analog-Digital converter resolution of 12 bits (0-4095 -> 4096), 10 bits (0-1023 -> 1024), 8 bits (0-255 -> 256)
analogReadResolution(8);
#define Resolution 255
// initialize the OLED object
if(!displayOLED.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Configure text size and color of the OLED display
displayOLED.setTextSize(1); // set text size
displayOLED.setTextColor(WHITE); // set text color
//Clear OLED display
displayOLED.clearDisplay();
}
void loop()
{
// Read analog voltage from Pin 35 of ESP32
DigitalValue = analogRead(PinAnalog);
// Obtain the mili volts value that was converter by ADC from LM35
Volts = DigitalValue * (3300/Resolution);
// LM35 provides 10mV by each 1C degres
TempC = Volts / 10;
Serial.printf("Voltage: %0.1fV, ADC Value: %d, TempC: %0.1fC, \n", Volts, DigitalValue,TempC);
//Move cursor on the OLED display to column 0 and line 2
displayOLED.setCursor(0,2); // set position to display (x,y)
//Display the first message on position (0,2)
displayOLED.setCursor(0,2); // set position to display (x,y)
displayOLED.print("Temperature: ");
//Display variable value
displayOLED.print(TempC);
displayOLED.display(); // display on OLED
//Display flame animation
displayOLED.drawBitmap(50, 10, epd_bitmap_Flame1Small, 34, 50, WHITE);
displayOLED.display();
delay(100);
//displayOLED.clearDisplay();
displayOLED.drawBitmap(50, 10, epd_bitmap_RectangleSmall, 37, 50, BLACK);
displayOLED.display();
displayOLED.drawBitmap(50, 10, epd_bitmap_Flame2Small, 35, 50, WHITE);
displayOLED.display();
delay(100);
//displayOLED.clearDisplay();
displayOLED.drawBitmap(50, 10, epd_bitmap_RectangleSmall, 37, 50, BLACK);
displayOLED.display();
displayOLED.drawBitmap(50, 10, epd_bitmap_Flame3Small, 37, 50, WHITE);
displayOLED.display();
delay(100);
//displayOLED.clearDisplay();
displayOLED.drawBitmap(50, 10, epd_bitmap_RectangleSmall, 37, 50, BLACK);
displayOLED.display();
displayOLED.drawBitmap(50, 10, epd_bitmap_Flame4Small, 37, 50, WHITE);
displayOLED.display();
delay(100);
displayOLED.clearDisplay(); //Clear OLED display
}