首页 > 解决方案 > pyserial 和 esp-32s - 当 ser.open esp32 停止运行时

问题描述

我需要一些有关pyserial的帮助...

我正在尝试使用此代码查看使用 python 在串行 COM3 中打印的内容:

import serial
from serial.serialutil import Timeout

ser = serial.Serial('COM3', 115200, timeout=3)
ser.open()
while True:
    if ser.in_waiting:
        packet = ser.readline()
        print(packet.decode('utf'))

但是,当我运行它时,我的 esp32 停止运行之前在 Arduino IDE 中上传的代码,关闭手电筒和 wifi:

ESP32 代码:

#include "esp_camera.h"
#include <WiFi.h>


// Select camera model
#define CAMERA_MODEL_AI_THINKER



#define ACCESS_POINT 1
const char* ssid = "Jarvis";
const char* password = "123456789";
const int ledPin = 4;

#if defined(CAMERA_MODEL_AI_THINKER)
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22
#else
#error "Camera nao selecionada"
#endif

void startCameraServer();

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200);
  Serial.println();

  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
  
  if(psramFound()){
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("A inicializacao da camera falhou 0x%x", err);
    return;
  }

  sensor_t * s = esp_camera_sensor_get();
  s->set_framesize(s, FRAMESIZE_QVGA);

  if(ACCESS_POINT)
  {
    WiFi.softAP(ssid, password);
  }
  else
  {
    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi Conectado");
  }

  startCameraServer();

  Serial.print("Camera pronta para acessar 'http://");
  Serial.print(ACCESS_POINT ? WiFi.softAPIP() : WiFi.localIP());
}//setup

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(2000);
}

我该如何解决?我尝试了很多,但我没有找到任何东西......

标签: pythonarduinopyserialesp32

解决方案


推荐阅读