PCB Design Questions
flux
BOARD_DEFINITION_GENERIC validation error without identifying the underlying object.flux
flux
esp32devOneWireTable
| Function | GPIO | Schematic destination |
|---|---|---|
| Logic output 1 | 16 | U7 1A -> J3 pin 1 |
| Logic output 2 | 17 | U7 2A -> J3 pin 2 |
| Logic output 3 | 18 | U7 3A -> J3 pin 3 |
| Logic output 4 | 19 | U7 4A -> J3 pin 4 |
| I2C SDA | 21 | J2 pin 3, R3 pull-up |
| I2C SCL | 22 | J2 pin 4, R4 pull-up |
| 1-Wire data | 27 | J5 pin 3, R5 pull-up |
| Load output 1 | 25 | R6/Q1 -> J4 pin 1 |
| Load output 2 | 26 | R7/Q2 -> J4 pin 2 |
| Load output 3 | 32 | R8/Q3 -> J4 pin 3 |
| Load output 4 | 33 | R9/Q4 -> J4 pin 4 |
| UART0 TX | 1 | U8 FT231XS-R RXD (TXD0_GPIO1) |
| UART0 RX | 3 | U8 FT231XS-R TXD (RXD0_GPIO3) |
| Reset | EN | SW1 and U8 DTR#/RTS# automatic-flash transistor circuit |
| Boot | 0 | SW2 and U8 DTR#/RTS# automatic-flash transistor circuit |
platformio.ini:Ini
[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 lib_deps = paulstoffregen/OneWire@^2.3.8 build_flags = -DCORE_DEBUG_LEVEL=3
src/main.cpp:Cpp
#include <Arduino.h> #include <WiFi.h> #include <Wire.h> #include <OneWire.h> constexpr uint8_t PIN_LOGIC[4] = {16, 17, 18, 19}; constexpr uint8_t PIN_LOAD[4] = {25, 26, 32, 33}; constexpr uint8_t PIN_I2C_SDA = 21; constexpr uint8_t PIN_I2C_SCL = 22; constexpr uint8_t PIN_ONEWIRE = 27; const char *WIFI_SSID = "YOUR_SSID"; const char *WIFI_PASSWORD = "YOUR_PASSWORD"; OneWire oneWire(PIN_ONEWIRE); uint32_t lastReportMs = 0; void setAllOutputsSafe() { for (uint8_t pin : PIN_LOGIC) { pinMode(pin, OUTPUT); digitalWrite(pin, LOW); } for (uint8_t pin : PIN_LOAD) { pinMode(pin, OUTPUT); digitalWrite(pin, LOW); } } void connectWiFi() { WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("WiFi"); for (uint8_t tries = 0; tries < 20 && WiFi.status() != WL_CONNECTED; ++tries) { delay(500); Serial.print('.'); } if (WiFi.status() == WL_CONNECTED) { Serial.printf(" connected: %s\n", WiFi.localIP().toString().c_str()); } else { Serial.println(" unavailable; continuing offline"); } } void scanI2C() { uint8_t found = 0; for (uint8_t address = 1; address < 127; ++address) { Wire.beginTransmission(address); if (Wire.endTransmission() == 0) { Serial.printf("I2C device: 0x%02X\n", address); ++found; } } if (!found) Serial.println("No I2C devices found"); } void scanOneWire() { uint8_t rom[8]; oneWire.reset_search(); bool found = false; while (oneWire.search(rom)) { if (OneWire::crc8(rom, 7) != rom[7]) { Serial.println("1-Wire ROM CRC error"); continue; } Serial.print("1-Wire ROM:"); for (uint8_t byte : rom) Serial.printf(" %02X", byte); Serial.println(); found = true; } if (!found) Serial.println("No 1-Wire devices found"); } void handleSerialCommand() { if (!Serial.available()) return; String command = Serial.readStringUntil('\n'); command.trim(); int bank = -1, channel = -1, state = -1; if (sscanf(command.c_str(), "%d %d %d", &bank, &channel, &state) == 3 && bank >= 0 && bank <= 1 && channel >= 1 && channel <= 4 && state >= 0 && state <= 1) { const uint8_t pin = bank == 0 ? PIN_LOGIC[channel - 1] : PIN_LOAD[channel - 1]; digitalWrite(pin, state ? HIGH : LOW); Serial.printf("bank=%d channel=%d state=%d\n", bank, channel, state); } else { Serial.println("Command: <bank> <channel> <state>; bank 0=logic, 1=load"); } } void setup() { Serial.begin(115200); Serial.setTimeout(50); setAllOutputsSafe(); Wire.begin(PIN_I2C_SDA, PIN_I2C_SCL, 100000); delay(200); Serial.println("ESP32 Environmental Controller starting"); scanI2C(); scanOneWire(); connectWiFi(); } void loop() { handleSerialCommand(); const uint32_t now = millis(); if (now - lastReportMs >= 5000) { lastReportMs = now; Serial.printf("uptime=%lu ms wifi=%s heap=%u\n", static_cast<unsigned long>(now), WiFi.status() == WL_CONNECTED ? "up" : "down", ESP.getFreeHeap()); scanOneWire(); } if (WiFi.status() != WL_CONNECTED && now > 30000 && (now % 30000) < 20) { connectWiFi(); } delay(10); }
FTDI_3V3 VCCIO rail, and drives the EN/IO0 automatic-flashing circuit from DTR#/RTS#.Bash
pio run pio run -t upload pio device monitor
upload_port and monitor_port in platformio.ini or pass the detected port on the command line. Close the serial monitor before uploading if the operating system does not permit shared access.pio run -t upload, then release BOOT when the uploader begins connecting. After flashing, press RESET once if the application does not start automatically. The onboard FT231XS-R remains the serial interface; no external USB-UART adapter is required.Platform and Toolchain
Pin Mapping
PlatformIO Configuration
Complete Starter Source
Build and Flash
Manual BOOT/RESET Recovery
Safety Defaults