firmware.ino 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <esp_camera.h>
  2. #include "camera_model.h"
  3. #include "initialize.h"
  4. #include "process_image.h"
  5. #include "serial_commands.h"
  6. camera_config_t config;
  7. // Entry point of the program.
  8. void setup()
  9. {
  10. // Set up the camera model.
  11. CameraModel *model = CameraModel::getInstance();
  12. // Set up the model defaults.
  13. model->setIsDitheringDisabled(false);
  14. model->setIsInverted(false);
  15. model->setIsFlashEnabled(false);
  16. model->setIsStreamEnabled(true);
  17. model->setDitherAlgorithm(FLOYD_STEINBERG);
  18. // Set initial camera configurations for grayscale.
  19. config.ledc_channel = LEDC_CHANNEL_0;
  20. config.ledc_timer = LEDC_TIMER_0;
  21. config.pin_d0 = Y2_GPIO_NUM;
  22. config.pin_d1 = Y3_GPIO_NUM;
  23. config.pin_d2 = Y4_GPIO_NUM;
  24. config.pin_d3 = Y5_GPIO_NUM;
  25. config.pin_d4 = Y6_GPIO_NUM;
  26. config.pin_d5 = Y7_GPIO_NUM;
  27. config.pin_d6 = Y8_GPIO_NUM;
  28. config.pin_d7 = Y9_GPIO_NUM;
  29. config.pin_xclk = XCLK_GPIO_NUM;
  30. config.pin_pclk = PCLK_GPIO_NUM;
  31. config.pin_vsync = VSYNC_GPIO_NUM;
  32. config.pin_href = HREF_GPIO_NUM;
  33. config.pin_sscb_sda = SIOD_GPIO_NUM;
  34. config.pin_sscb_scl = SIOC_GPIO_NUM;
  35. config.pin_pwdn = PWDN_GPIO_NUM;
  36. config.pin_reset = RESET_GPIO_NUM;
  37. config.xclk_freq_hz = 20000000;
  38. config.pixel_format = PIXFORMAT_GRAYSCALE;
  39. config.frame_size = FRAMESIZE_QQVGA;
  40. config.fb_count = 1;
  41. // Begin serial communication.
  42. Serial.begin(230400); // 115200
  43. // Initialize the camera.
  44. initialize(&config);
  45. }
  46. // Main loop of the program.
  47. void loop()
  48. {
  49. // Get the camera model reference.
  50. CameraModel *model = CameraModel::getInstance();
  51. if (model->getIsStreamEnabled())
  52. {
  53. camera_fb_t *frame_buffer = esp_camera_fb_get();
  54. if (frame_buffer)
  55. {
  56. process_image(frame_buffer);
  57. // Return the frame buffer back to the camera driver.
  58. esp_camera_fb_return(frame_buffer);
  59. }
  60. delay(25);
  61. }
  62. serial_commands();
  63. }