fork download
  1. const char* ssid = "AUTOMATA";
  2. const char* password = "AUTOMATA";
  3.  
  4. #include "esp_wifi.h"
  5. #include "esp_camera.h"
  6. #include <WiFi.h>
  7. #include "soc/soc.h"
  8. #include "soc/rtc_cntl_reg.h"
  9.  
  10. #define CAMERA_MODEL_AI_THINKER
  11.  
  12. #define PWDN_GPIO_NUM 32
  13. #define RESET_GPIO_NUM -1
  14. #define XCLK_GPIO_NUM 0
  15. #define SIOD_GPIO_NUM 26
  16. #define SIOC_GPIO_NUM 27
  17. #define Y9_GPIO_NUM 35
  18. #define Y8_GPIO_NUM 34
  19. #define Y7_GPIO_NUM 39
  20. #define Y6_GPIO_NUM 36
  21. #define Y5_GPIO_NUM 21
  22. #define Y4_GPIO_NUM 19
  23. #define Y3_GPIO_NUM 18
  24. #define Y2_GPIO_NUM 5
  25. #define VSYNC_GPIO_NUM 25
  26. #define HREF_GPIO_NUM 23
  27. #define PCLK_GPIO_NUM 22
  28.  
  29. void startCameraServer();
  30.  
  31. const int MotPin0 = 12;
  32. const int MotPin1 = 13;
  33. const int MotPin2 = 14;
  34. const int MotPin3 = 15;
  35.  
  36. void initMotors()
  37. {
  38. ledcSetup(3, 2000, 8); // 2000 hz PWM, 8-bit resolution
  39. ledcSetup(4, 2000, 8); // 2000 hz PWM, 8-bit resolution
  40. ledcSetup(5, 2000, 8); // 2000 hz PWM, 8-bit resolution
  41. ledcSetup(6, 2000, 8); // 2000 hz PWM, 8-bit resolution
  42. ledcAttachPin(MotPin0, 3);
  43. ledcAttachPin(MotPin1, 4);
  44. ledcAttachPin(MotPin2, 5);
  45. ledcAttachPin(MotPin3, 6);
  46. }
  47.  
  48. const int ServoPin = 2;
  49. void initServo(){
  50. ledcSetup(8, 50, 16); // 50 hz PWM, 16-bit resolution, range from 3250 to 6500.
  51. ledcAttachPin(ServoPin, 8);
  52. }
  53.  
  54. void setup(){
  55. WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // prevent brownouts by silencing them
  56.  
  57. Serial.begin(115200);
  58. Serial.setDebugOutput(true);
  59. Serial.println();
  60.  
  61. camera_config_t config;
  62. config.ledc_channel = LEDC_CHANNEL_0;
  63. config.ledc_timer = LEDC_TIMER_0;
  64. config.pin_d0 = Y2_GPIO_NUM;
  65. config.pin_d1 = Y3_GPIO_NUM;
  66. config.pin_d2 = Y4_GPIO_NUM;
  67. config.pin_d3 = Y5_GPIO_NUM;
  68. config.pin_d4 = Y6_GPIO_NUM;
  69. config.pin_d5 = Y7_GPIO_NUM;
  70. config.pin_d6 = Y8_GPIO_NUM;
  71. config.pin_d7 = Y9_GPIO_NUM;
  72. config.pin_xclk = XCLK_GPIO_NUM;
  73. config.pin_pclk = PCLK_GPIO_NUM;
  74. config.pin_vsync = VSYNC_GPIO_NUM;
  75. config.pin_href = HREF_GPIO_NUM;
  76. config.pin_sscb_sda = SIOD_GPIO_NUM;
  77. config.pin_sscb_scl = SIOC_GPIO_NUM;
  78. config.pin_pwdn = PWDN_GPIO_NUM;
  79. config.pin_reset = RESET_GPIO_NUM;
  80. config.xclk_freq_hz = 20000000;
  81. config.pixel_format = PIXFORMAT_JPEG;
  82. //init with high specs to pre-allocate larger buffers
  83. if (psramFound()){
  84. config.frame_size = FRAMESIZE_QVGA;
  85. config.jpeg_quality = 10;
  86. config.fb_count = 2;
  87. } else {
  88. config.frame_size = FRAMESIZE_QVGA;
  89. config.jpeg_quality = 12;
  90. config.fb_count = 1;
  91. }
  92.  
  93. // camera init
  94. esp_err_t err = esp_camera_init(&config);
  95. if (err != ESP_OK) {
  96. Serial.printf("Camera init failed with error 0x%x", err);
  97. return;
  98. }
  99.  
  100. //drop down frame size for higher initial frame rate
  101. sensor_t * s = esp_camera_sensor_get();
  102. s->set_framesize(s, FRAMESIZE_QVGA);
  103. s->set_vflip(s, 1);
  104. s->set_hmirror(s, 1);
  105.  
  106. // Remote Control Car
  107. initMotors();
  108. initServo();
  109.  
  110. ledcSetup(7, 5000, 8);
  111. ledcAttachPin(4, 7); //pin4 is LED
  112.  
  113. WiFi.softAP(ssid, password);
  114. IPAddress miIP = WiFi.softAPIP();
  115. Serial.print("AP IP address: ");
  116. Serial.println(miIP); //probar 192.168.4.1
  117.  
  118. startCameraServer();
  119.  
  120. for (int i = 0; i < 5; i++) {
  121. ledcWrite(7, 10); // flash led
  122. delay(50);
  123. ledcWrite(7, 0);
  124. delay(50);
  125. }
  126. }
  127.  
  128. void loop() {
  129. // put your main code here, to run repeatedly:
  130. delay(1000);
  131. Serial.printf("RSSi: %ld dBm\n", WiFi.RSSI());
  132. }
Success #stdin #stdout 0.03s 25856KB
stdin
Standard input is empty
stdout
const char* ssid = "AUTOMATA";
const char* password = "AUTOMATA";

#include "esp_wifi.h"
#include "esp_camera.h"
#include <WiFi.h>
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"

#define 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

void startCameraServer();

const int MotPin0 = 12;
const int MotPin1 = 13;
const int MotPin2 = 14;
const int MotPin3 = 15;

void initMotors()
{
  ledcSetup(3, 2000, 8); // 2000 hz PWM, 8-bit resolution
  ledcSetup(4, 2000, 8); // 2000 hz PWM, 8-bit resolution
  ledcSetup(5, 2000, 8); // 2000 hz PWM, 8-bit resolution
  ledcSetup(6, 2000, 8); // 2000 hz PWM, 8-bit resolution
  ledcAttachPin(MotPin0, 3);
  ledcAttachPin(MotPin1, 4);
  ledcAttachPin(MotPin2, 5);
  ledcAttachPin(MotPin3, 6);
}

const int ServoPin = 2;
void initServo(){
  ledcSetup(8, 50, 16); // 50 hz PWM, 16-bit resolution, range from 3250 to 6500.
  ledcAttachPin(ServoPin, 8);
}

void setup(){
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // prevent brownouts by silencing them

  Serial.begin(115200);
  Serial.setDebugOutput(true);
  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;
  //init with high specs to pre-allocate larger buffers
  if (psramFound()){
    config.frame_size = FRAMESIZE_QVGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_QVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }

  //drop down frame size for higher initial frame rate
  sensor_t * s = esp_camera_sensor_get();
  s->set_framesize(s, FRAMESIZE_QVGA);
  s->set_vflip(s, 1);
  s->set_hmirror(s, 1);

  // Remote Control Car
  initMotors();
  initServo();

  ledcSetup(7, 5000, 8);
  ledcAttachPin(4, 7);  //pin4 is LED

  WiFi.softAP(ssid, password);
  IPAddress miIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(miIP); //probar 192.168.4.1

  startCameraServer();

  for (int i = 0; i < 5; i++) {
    ledcWrite(7, 10); // flash led
    delay(50);
    ledcWrite(7, 0);
    delay(50);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  Serial.printf("RSSi: %ld dBm\n", WiFi.RSSI());
}