ช่วยแก้ทีคับปกติใช้ esp32 ปกติแล้วฮาร์ดแวร์เสียเลยลองใช้โค๊ตเดิมกับ esp32s แล้วขึ้นงี้อ่ะคับ

โค๊ตเดิมคับ

// #define BLYNK_TEMPLATE_ID "TMPL6zkP53VO7"
// #define BLYNK_TEMPLATE_NAME "farm"

#define BLYNK_TEMPLATE_ID           "TMPxxxxxx"
#define BLYNK_TEMPLATE_NAME         "Device"
#define BLYNK_AUTH_TOKEN "S6gL_8GZGyZvuLSrixCQp7kvJYT0Z7cI"
#include <LM75.h>
#include <BH1750.h>
#include <Wire.h>
#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char ssid[] = "Peem";
char pass[] = "0989980962";
float t;
int lux;

float Lowt, Hight;
int LowLux, HighLux;
int LowHum, HighHum;


LM75 Temp0;
BH1750 lightMeter;
#define Ry1 15
#define Ry2 13
#define Ry3 12
#define Ry4 14
const int analogInPin = A0;
int outputValue = 0;  // value output to the PWM (analog out)
int sensorValue = 0;  // value read from the pot
BlynkTimer timer;

void myTemp() {
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, t);
}
void myLight() {
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, lux);
}
void mySoil() {
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, outputValue);
}
BLYNK_WRITE(V6)  //กำหนดค่าต่ำของอุณหภูมิ
{
  int pinValue = param.asInt();  // assigning incoming value from pin V1 to a variable
  Lowt = pinValue;

  // process received value
}
BLYNK_WRITE(V7)  //กำหนดค่าสูงของอุณหภูมิ
{
  int pinValue = param.asInt();  // assigning incoming value from pin V1 to a variable
  Hight = pinValue;              //

  // process received value
}
BLYNK_WRITE(V8)  //กำหนดค่าต่ำของความชื้น
{
  int pinValue = param.asInt();  // assigning incoming value from pin V1 to a variable
  LowHum = pinValue;

  // process received value
}
BLYNK_WRITE(V9)  //กำหนดค่าสูงของอุณหภูมิ
{
  int pinValue = param.asInt();  // assigning incoming value from pin V1 to a variable
  HighHum = pinValue;            //

  // process received value
}
BLYNK_WRITE(V10)  //กำหนดค่าต่ำของแสง
{
  int pinValue = param.asInt();  // assigning incoming value from pin V1 to a variable
  LowLux = pinValue;

  // process received value
}
BLYNK_WRITE(V11)  //กำหนดค่าสองของแสง
{
  int pinValue = param.asInt();  // assigning incoming value from pin V1 to a variable
  HighLux = pinValue;            //

  // process received value
}




void setup() {
  Serial.begin(115200);
  //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(49,229,108,138), 8080);
  pinMode(Ry1, OUTPUT);
  pinMode(Ry2, OUTPUT);
  pinMode(Ry3, OUTPUT);
  pinMode(Ry4, OUTPUT);
  Temp0.begin();
  lightMeter.begin();
  Wire.begin();


  if (Temp0.isConnected())
    Serial.println("Connected!");
  else {
    Serial.println("Not Connected");
    while (true)
      ;
  }
  timer.setInterval(1000L, myTemp);
  timer.setInterval(1000L, myLight);
  timer.setInterval(1000L, mySoil);
}

void loop() {
  Blynk.run();
  timer.run();  // Initiates BlynkTimer
  t = Temp0.getTemperature();
  lux = lightMeter.readLightLevel();
  sensorValue = analogRead(analogInPin);
  outputValue = map(sensorValue, 0, 4093, 0, 100);
  Serial.print("Humi = ");
  Serial.print(outputValue);
  Serial.print("  Temp = ");
  Serial.print(t, 2);
  Serial.print("   Light = ");
  Serial.println(lux);
  if (t > Hight) 
  {
    digitalWrite(Ry1, HIGH);
    delay(100);
  }
  if (t < Hight) 
  {
    digitalWrite(Ry1, LOW);
    delay(100);
  }
  if (lux < LowLux)
   {
    digitalWrite(Ry2, HIGH);
    delay(100);
  }
  if (lux > LowLux) 
  {
    digitalWrite(Ry2, LOW);
    delay(100);
  }
  if (outputValue > LowHum) 
  {
    digitalWrite(Ry3, HIGH);
    digitalWrite(Ry4, HIGH);
    delay(100);
  }
  if (outputValue < LowHum) 
  {
    digitalWrite(Ry3, LOW);
    digitalWrite(Ry4, LOW);
    delay(100);
  }
  delay(1000);
}
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0xee

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

mode:DIO, clock div:1

load:0x3fff0030,len:4916

load:0x40078000,len:16436

load:0x40080400,len:4

ho 8 tail 4 room 4

load:0x40080404,len:3524

entry 0x400805b8

[18] Connecting to Peem

จากข้อความ “rst:0x1 (POWERON_RESET), boot:0x13 (SPI_FAST_FLASH_BOOT)” และข้อมูลที่ให้มา มันบอกว่า ESP32S กำลังรีเซ็ตตัวเองซ้ำๆ ซึ่งอาจเกิดจากสาเหตุ

ลองดู 2 ข้อนี้ก่อนครับ


:small_blue_diamond: สาเหตุที่เป็นไปได้ และแนวทางแก้ไข

1. ปัญหาเกี่ยวกับพลังงาน (Power Supply)

อาการ:

  • ESP32 รีเซ็ตตัวเองซ้ำๆ
  • บางครั้งขึ้นข้อความ “Brownout detector was triggered”

วิธีแก้ไข:

  • ลองเปลี่ยนไปใช้ อะแดปเตอร์ 5V 2A แทนการจ่ายไฟจากคอมพิวเตอร์
  • ใช้ ตัวเก็บประจุ (Capacitor) 470uF - 1000uF ที่ขา VCC และ GND ของ ESP32 เพื่อป้องกันแรงดันไฟตก

2. ปัญหาเกี่ยวกับ GPIO ที่ใช้

อาการ:

  • ถ้าเสียบโมดูล MAX485 แล้วบอร์ดรีเซ็ต
  • รีเซ็ตเมื่ออ่านค่า Sensor

วิธีแก้ไข:

  • หลีกเลี่ยงการใช้ GPIO 0, 2, 12, 15 (GPIO เหล่านี้มีผลตอนบูท)
  • ลองเปลี่ยนขาที่ใช้สื่อสารกับ MAX485 (จาก GPIO16/17 ไปเป็น GPIO4/5)