Assignment

  1. Measure the current draw of an output device.
  2. Add and drive one new output device.
  3. Write a program linking at least one input and one output.

For the Smart Mug Heater I focused on the SSD1306 OLED screen as the new output channel and profiled the power envelope of the relay-switched heater.

Measuring Power Consumption

I tried measuring the power consuption of the heatbed tile I would be using for my final project. Its resistance should be around 12 Ω. I measured 12.7 Ω. And hooking it up to a lab power supply configured in voltage mode set to 20 V it showed 1.57 Amps. This is consistent with the resistance measurement, as

I = U / R, I = 20 V / 12.7 Ω ≈ 1.57 A
This equates to a power consumption:
P = U * I, P = 20 V * 1.57 A ≈ 31.4 W
This is should do for more than sufficient temperature control of the mug, we are not aiming to boil the water in the shortest ammount of time.

Setup

For the OLED graphics I used the SSD1306 display with a resolution of 128x64 pixels, the I2C variant, 0.96" diagonal. It is a small, low-power OLED display that can be easily connected to an ESP8266 microcontroller via I2C.

For the OLED display I used the following libraries:

OLED Wiring

Rotary Encoder Wiring

Note: The encoder pins were specifically chosen to avoid interference with the ESP8266's boot process. Avoid pins D4 and D3 as they have specific functions during boot of the ESP and they may tamper with the normal boot process.

OLED Graphics

I implemented a temperature control interface using the OLED display and rotary encoder. The encoder allows adjusting the target temperature between 35°C and 95°C, with a default of 60°C. Pressing the encoder button resets the temperature back to 60°C.

The OLED displays the current target temperature in large digits with "°C" units. This simple UI allows for easy temperature adjustment and reading.

Here is a video of the interface in action, showing how the encoder adjusts the temperature:

Code

The program below demonstrates the integration of a rotary encoder as input and an OLED display as output. The encoder updates a target temperature value, which is displayed on the OLED:

// ESP8266 NodeMCU + SSD1306 OLED + rotary encoder
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_ADDR 0x3C
Adafruit_SSD1306 display(128, 64, &Wire, -1);

// --- encoder wiring (use pins that don't affect boot) ---
const uint8_t ENC_SW  = D5;   // GPIO14
const uint8_t ENC_CLK = D6;   // GPIO12
const uint8_t ENC_DT  = D7;   // GPIO13

volatile int16_t encoderCount = 60;   // start value (°C)
volatile bool   dirty         = true;


void drawScreen(int16_t v = encoderCount) {
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print(F("Target"));
  display.setCursor(0, 24);
  display.print(v);
  display.print(F(" C"));
  display.display();
  Serial.printf("Set-point: %d C\n", v);
}


void IRAM_ATTR encISR() {
  static bool lastDT = HIGH;
  bool dt = digitalRead(ENC_DT);
  if (dt != lastDT) {                       // state changed
    bool clk = digitalRead(ENC_CLK);
    encoderCount += (dt == clk) ? +1 : -1;  // Gray decoding
    encoderCount = constrain(encoderCount, 35, 95);
    dirty = true;
    lastDT = dt;
  }
}

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

  // I²C & display
  Wire.begin();                // D1, D2
  if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
    Serial.println(F("SSD1306 not found"));
    while (true) yield();
  }
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);

  // encoder pins
  pinMode(ENC_CLK, INPUT_PULLUP);
  pinMode(ENC_DT,  INPUT_PULLUP);
  pinMode(ENC_SW,  INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(ENC_DT), encISR, CHANGE);

  Serial.println(F("Ready – twist the dial"));
  drawScreen();
}

void loop() {
  // update screen only when the count changed
  if (dirty) {
    noInterrupts();
    int16_t val = encoderCount;
    dirty = false;
    interrupts();
    drawScreen(val);
  }

  // simple button demo: press to reset to 60 °C
  if (!digitalRead(ENC_SW)) {
    encoderCount = 60;
    dirty = true;
    delay(250);                // crude debounce
  }
}

Download the code:

Key features of the code:

Conclusion

Week 7 focused on output devices, successfully implementing an OLED display controlled by a rotary encoder. The project demonstrates a practical temperature control interface that will be integrated into the final Mug-Heater project. The power consumption measurements of the heating element confirm its suitability for the application, providing around 31W of heating power.

The combination of encoder input and OLED display creates an intuitive interface for setting and displaying temperature targets, essential for the smart mug heater's functionality.