Power Distribution Schematic Design
BAT_12V, FAN_GND, and servo power.Table
| Function | GPIO | Net | Direction | Notes |
|---|---|---|---|---|
| MAX31855 shared clock | 18 | SPI_CLK_GPIO18 | Output | Shared SCK to U3-U7 |
| MAX31855 shared data | 19 | SPI_DO_GPIO19 | Input | Shared SO/DO from U3-U7 |
| Dome CS | 5 | CS_DOME_GPIO5 | Output | U3 CS |
| Food 1 CS | 14 | CS_FOOD1_GPIO14 | Output | U4 CS |
| Food 2 CS | 27 | CS_FOOD2_GPIO27 | Output | U5 CS |
| Food 3 CS | 26 | CS_FOOD3_GPIO26 | Output | U6 CS |
| Food 4 CS | 25 | CS_FOOD4_GPIO25 | Output | U7 CS |
| Blower PWM | 23 | FAN_PWM_GPIO23 | Output PWM | Drives Q1 gate through R1 |
| Battery sense ADC | 34 | BATTERY_SENSE_GPIO34 | Analog input | 100k/22k divider from BAT_12V |
| Servo TX2 | 17 | SERVO_TX_GPIO17 | UART TX | Through 1k to SERVO_DATA |
| Servo RX2 | 16 | SERVO_RX_GPIO16 | UART RX | Through 1k to SERVO_DATA |
platformio.ini:Ini
[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 lib_deps = adafruit/Adafruit MAX31855 library@^1.4.2 adafruit/Adafruit BusIO@^1.16.0
src/main.cpp:Cpp
#include <Arduino.h> #include <Adafruit_MAX31855.h> // Thermocouple SPI pins constexpr int PIN_SPI_CLK = 18; constexpr int PIN_SPI_DO = 19; constexpr int PIN_CS_DOME = 5; constexpr int PIN_CS_FOOD1 = 14; constexpr int PIN_CS_FOOD2 = 27; constexpr int PIN_CS_FOOD3 = 26; constexpr int PIN_CS_FOOD4 = 25; // Blower PWM constexpr int PIN_FAN_PWM = 23; constexpr int FAN_PWM_CHANNEL = 0; constexpr int FAN_PWM_FREQ_HZ = 25000; constexpr int FAN_PWM_RES_BITS = 8; // Battery ADC constexpr int PIN_BATTERY_SENSE = 34; constexpr float R_TOP_OHMS = 100000.0f; constexpr float R_BOTTOM_OHMS = 22000.0f; constexpr float DIVIDER_GAIN = (R_TOP_OHMS + R_BOTTOM_OHMS) / R_BOTTOM_OHMS; constexpr float ADC_REF_VOLTS = 3.3f; constexpr int ADC_MAX_COUNTS = 4095; // STS3215 half-duplex TTL bus through resistor-combined TX/RX constexpr int PIN_SERVO_RX = 16; constexpr int PIN_SERVO_TX = 17; constexpr uint32_t SERVO_BAUD = 1000000; // confirm actual STS3215 bus baud in firmware settings Adafruit_MAX31855 tcDome(PIN_SPI_CLK, PIN_CS_DOME, PIN_SPI_DO); Adafruit_MAX31855 tcFood1(PIN_SPI_CLK, PIN_CS_FOOD1, PIN_SPI_DO); Adafruit_MAX31855 tcFood2(PIN_SPI_CLK, PIN_CS_FOOD2, PIN_SPI_DO); Adafruit_MAX31855 tcFood3(PIN_SPI_CLK, PIN_CS_FOOD3, PIN_SPI_DO); Adafruit_MAX31855 tcFood4(PIN_SPI_CLK, PIN_CS_FOOD4, PIN_SPI_DO); unsigned long lastTelemetryMs = 0; float readBatteryVoltage() { int raw = analogRead(PIN_BATTERY_SENSE); float adcVolts = (static_cast<float>(raw) * ADC_REF_VOLTS) / ADC_MAX_COUNTS; return adcVolts * DIVIDER_GAIN; } void setFanDutyPercent(float dutyPercent) { if (dutyPercent < 0.0f) dutyPercent = 0.0f; if (dutyPercent > 100.0f) dutyPercent = 100.0f; uint32_t duty = static_cast<uint32_t>((dutyPercent / 100.0f) * 255.0f); ledcWrite(FAN_PWM_CHANNEL, duty); } void printThermocouple(const char* name, Adafruit_MAX31855& tc) { double tempC = tc.readCelsius(); if (isnan(tempC)) { Serial.printf("%s: fault=0x%02X\n", name, tc.readError()); } else { Serial.printf("%s: %.2f C\n", name, tempC); } } void initThermocouples() { // Software SPI constructors do not require SPI.begin(). Delay lets MAX31855 modules settle. delay(500); } void initFanPwm() { ledcSetup(FAN_PWM_CHANNEL, FAN_PWM_FREQ_HZ, FAN_PWM_RES_BITS); ledcAttachPin(PIN_FAN_PWM, FAN_PWM_CHANNEL); setFanDutyPercent(0.0f); } void initBatteryAdc() { analogReadResolution(12); analogSetPinAttenuation(PIN_BATTERY_SENSE, ADC_11db); } void initServoBus() { Serial2.begin(SERVO_BAUD, SERIAL_8N1, PIN_SERVO_RX, PIN_SERVO_TX); } void setup() { Serial.begin(115200); delay(200); Serial.println("DIY Grill Controller firmware starting"); initThermocouples(); initFanPwm(); initBatteryAdc(); initServoBus(); Serial.println("Init complete"); } void loop() { unsigned long now = millis(); if (now - lastTelemetryMs >= 1000) { lastTelemetryMs = now; printThermocouple("DOME_TC", tcDome); printThermocouple("FOOD1_TC", tcFood1); printThermocouple("FOOD2_TC", tcFood2); printThermocouple("FOOD3_TC", tcFood3); printThermocouple("FOOD4_TC", tcFood4); float batteryV = readBatteryVoltage(); Serial.printf("Battery: %.2f V\n", batteryV); // Safe default: fan off until control logic is implemented. setFanDutyPercent(0.0f); } }
Bash
pio run pio run -t upload pio device monitor
5V and 3V3 rails before connecting the ESP32.BATTERY_SENSE_GPIO34 is below 3.3V at maximum battery voltage.Platform & Toolchain
Pin Mapping
Dependencies & Project Setup
Complete Firmware Source
Build & Flash
Bring-Up Notes