fork download
  1. #include "esp_wifi.h"
  2. #include "esp_camera.h"
  3. #include <WiFi.h>
  4.  
  5. /* Wifi Crdentials */
  6. const char* ssid = "hash";
  7. const char* password = "12345678";
  8.  
  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. /* Defining motor and servo pins */
  32. const int RMotor1 = 14;
  33. const int RMotor2 = 15;
  34. const int LMotor1 = 13;
  35. const int LMotor2 = 12;
  36. const int ServoPin = 2;
  37. const int FlashPin = 4;
  38.  
  39. void initMotors()
  40. {
  41. /* Configuring motor PWM functionalities to generate the signal */
  42. /* ledcSetup(Channel, Frequency, Resolution) */
  43. ledcSetup(3, 2000, 8); /* 2000 hz PWM, 8-bit resolution and range from 0 to 255 */
  44. ledcSetup(4, 2000, 8); /* 2000 hz PWM, 8-bit resolution and range from 0 to 255 */
  45. ledcSetup(5, 2000, 8); /* 2000 hz PWM, 8-bit resolution and range from 0 to 255 */
  46. ledcSetup(6, 2000, 8); /* 2000 hz PWM, 8-bit resolution and range from 0 to 255 */
  47.  
  48. /* Attaching the channel to the GPIO to be controlled */
  49. /* ledcAttachPin(GPIO, Channel) */
  50. ledcAttachPin(RMotor1, 3);
  51. ledcAttachPin(RMotor2, 4);
  52. ledcAttachPin(LMotor1, 5);
  53. ledcAttachPin(LMotor2, 6);
  54.  
  55. }
  56.  
  57. void initServo() {
  58. ledcSetup(8, 50, 16); /*50 hz PWM, 16-bit resolution and range from 3250 to 6500 */
  59. ledcAttachPin(ServoPin, 8);
  60. }
  61.  
  62. void initFlash() {
  63. ledcSetup(7, 5000, 8); /* 5000 hz PWM, 8-bit resolution and range from 0 to 255 */
  64. ledcAttachPin(FlashPin, 7);
  65. }
  66.  
  67. void setup() {
  68. Serial.begin(115200);
  69. Serial.setDebugOutput(true);
  70. Serial.println();
  71.  
  72. camera_config_t config;
  73. config.ledc_channel = LEDC_CHANNEL_0;
  74. config.ledc_timer = LEDC_TIMER_0;
  75. config.pin_d0 = Y2_GPIO_NUM;
  76. config.pin_d1 = Y3_GPIO_NUM;
  77. config.pin_d2 = Y4_GPIO_NUM;
  78. config.pin_d3 = Y5_GPIO_NUM;
  79. config.pin_d4 = Y6_GPIO_NUM;
  80. config.pin_d5 = Y7_GPIO_NUM;
  81. config.pin_d6 = Y8_GPIO_NUM;
  82. config.pin_d7 = Y9_GPIO_NUM;
  83. config.pin_xclk = XCLK_GPIO_NUM;
  84. config.pin_pclk = PCLK_GPIO_NUM;
  85. config.pin_vsync = VSYNC_GPIO_NUM;
  86. config.pin_href = HREF_GPIO_NUM;
  87. config.pin_sscb_sda = SIOD_GPIO_NUM;
  88. config.pin_sscb_scl = SIOC_GPIO_NUM;
  89. config.pin_pwdn = PWDN_GPIO_NUM;
  90. config.pin_reset = RESET_GPIO_NUM;
  91. config.xclk_freq_hz = 20000000;
  92. config.pixel_format = PIXFORMAT_JPEG;
  93. //init with high specs to pre-allocate larger buffers
  94. if (psramFound()) {
  95. config.frame_size = FRAMESIZE_QVGA;
  96. config.jpeg_quality = 10;
  97. config.fb_count = 2;
  98. } else {
  99. config.frame_size = FRAMESIZE_QVGA;
  100. config.jpeg_quality = 12;
  101. config.fb_count = 1;
  102. }
  103.  
  104. // camera init
  105. esp_err_t err = esp_camera_init(&config);
  106. if (err != ESP_OK) {
  107. Serial.printf("Camera init failed with error 0x%x", err);
  108. return;
  109. }
  110.  
  111. //drop down frame size for higher initial frame rate
  112. sensor_t * s = esp_camera_sensor_get();
  113. s->set_framesize(s, FRAMESIZE_QVGA);
  114. s->set_vflip(s, 1);
  115. s->set_hmirror(s, 1);
  116.  
  117. /* Initializing motor,servo and led */
  118. initMotors();
  119. initServo();
  120. initFlash();
  121.  
  122. /* Connecting to WiFi */
  123. WiFi.begin(ssid, password);
  124. while (WiFi.status() != WL_CONNECTED) {
  125. delay(500);
  126. Serial.print(".");
  127. }
  128. Serial.println("");
  129. Serial.println("WiFi connected");
  130.  
  131. startCameraServer();/* Starting camera server */
  132.  
  133. Serial.print("Camera Ready! Use 'http://");
  134. Serial.print(WiFi.localIP());
  135. //WiFiAddr = WiFi.localIP().toString();
  136. Serial.println("' to connect");
  137.  
  138. /* Flash led */
  139. for (int i = 0; i < 5; i++) {
  140. ledcWrite(7, 10);
  141. delay(50);
  142. ledcWrite(7, 0);
  143. delay(50);
  144. }
  145. }
  146.  
  147. void loop() {
  148. // put your main code here, to run repeatedly:
  149.  
  150. }
Success #stdin #stdout 0.02s 25924KB
stdin
Standard input is empty
stdout
#include "esp_wifi.h"
#include "esp_camera.h"
#include <WiFi.h>

/* Wifi Crdentials */
const char* ssid = "hash";
const char* password = "12345678";


#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();

/* Defining motor and servo pins */
const int RMotor1 = 14;
const int RMotor2 = 15;
const int LMotor1 = 13;
const int LMotor2 = 12;
const int ServoPin = 2;
const int FlashPin = 4;

void initMotors()
{
  /* Configuring motor PWM functionalities to generate the signal */
  /* ledcSetup(Channel, Frequency, Resolution) */
  ledcSetup(3, 2000, 8); /* 2000 hz PWM, 8-bit resolution and range from 0 to 255 */
  ledcSetup(4, 2000, 8); /* 2000 hz PWM, 8-bit resolution and range from 0 to 255 */
  ledcSetup(5, 2000, 8); /* 2000 hz PWM, 8-bit resolution and range from 0 to 255 */
  ledcSetup(6, 2000, 8); /* 2000 hz PWM, 8-bit resolution and range from 0 to 255 */

  /* Attaching the channel to the GPIO to be controlled */
  /* ledcAttachPin(GPIO, Channel) */
  ledcAttachPin(RMotor1, 3);
  ledcAttachPin(RMotor2, 4);
  ledcAttachPin(LMotor1, 5);
  ledcAttachPin(LMotor2, 6);

}

void initServo() {
  ledcSetup(8, 50, 16); /*50 hz PWM, 16-bit resolution and range from 3250 to 6500 */
  ledcAttachPin(ServoPin, 8);
}

void initFlash() {
  ledcSetup(7, 5000, 8); /* 5000 hz PWM, 8-bit resolution and range from 0 to 255 */
  ledcAttachPin(FlashPin, 7);
}

void setup() {
  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);

  /* Initializing motor,servo and led */
  initMotors();
  initServo();
  initFlash();

  /* Connecting to WiFi */
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  startCameraServer();/* Starting camera server */

  Serial.print("Camera Ready! Use 'http://");
  Serial.print(WiFi.localIP());
  //WiFiAddr = WiFi.localIP().toString();
  Serial.println("' to connect");

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

void loop() {
  // put your main code here, to run repeatedly:

}