1.ESP32-CAM 下使用 ESP-IDF 打开摄像头

主要资料:

本文目标是在 Windows 下跑通摄像头 hello world 程序。之后再在Linux下跑程序。

ESP32-CAM 简介

ESP32-CAM是安信可最新发布小尺寸的摄像头模组。
本体:
image.png
可以用OV2640/OV7670摄像头。

管脚定义:

摄像头和SD卡管脚定义:

使用ESP-IDF

之前折腾过了,直接给结论:最简单的安装方法就是通过 vscode+espidf。
官方教程:vscode-esp-idf-extension/docs/tutorial/install.md。安装时自备梯子,如果没有,可以考虑下离线版的idf:ESP32 开发环境的搭建与详解

基本使用

创建基本项目不赘述,basic_use.md, 或扩展首页的使用说明即可,翻译在这里
需要注意的是,烧录时使用串口即可,JTAG太麻烦(RISC-V的JTAG还挺难找)。

如果需要JTAG调试,参考:配置其他 JTAG 接口
image.png

我用ESP32-CAM 烧录的时候,一直不成功,便把 boot0 接地即可。参考:关于ESP32下载的几个小问题

Windows下测试摄像头 (这节别看,放弃Win下的ESP-IDF了

  1. 克隆这个项目 Ai-Thinker-Open_ESP32-CAMERA_LAN

    克隆时需要拉取子模块,如果使用 git clone --recursive git@github.com:Ai-Thinker-Open/Ai-Thinker-Open_ESP32-CAMERA_LAN.git(recursive 递归拉取子模块)会超级慢,
    可以用 git clone --depth 1 git@github.com:Ai-Thinker-Open/Ai-Thinker-Open_ESP32-CAMERA_LAN.git depth=1 只拉取最新版本不拉取历史,这样的话主模块是浅拉取,但是子模块还是全拉取特别慢。
    先拉取单独的主模块
    git clone --depth 1 git@github.com:Ai-Thinker-Open/Ai-Thinker-Open_ESP32-CAMERA_LAN.git
    再拉取子模块 git submodule update --init --depth 1 --recursive 初始化、浅拉取、递归拉取。这样也得重试好几次才能成功。

    移动到examples 目录下,创建项目,
    配置时还会报错,mdns 模块不存在,因为esp who 项目再IDF V5.0中移除了mdns
    image.png
    手动下载 who-idfV5.0-mdns , 拉取或下载这个版本的 idf-who,然后复制 mdns到本地 Ai-Thinker-Open_ESP32-CAMERA_LAN\components 目录下。

  2. target 和 配置

    还需要修改项目下的 CMakeLists.txt 中的components路径
    image.png
    接着配置,即可成功。

  3. build

    编译时候一些函数不存在。
    error: 'portTICK_RATE_MS' undeclared 新版本中用 portTICK_PERIOD_MS 来替代了,要在配置中的 FreeRTOS下勾选 configENABLE_BACKWARD_COMPATIBILITY (兼容以前)配置。

    error: implicit declaration of function ‘periph_module_enable’

Two thousand years later …
总之,编译各种出错。遂放弃,后续Windows 下用Arduino开发。我决定去使用Linux版了

Linux 下 ESP-IDF 环境安装

参考 安信可ESP32-CAM摄像头开发demo–局域网拍照、实时视频、人脸识别 教程。
如果使用 ./install.sh 时 的 python 下载时慢,可以添加系统代理。

export http_proxy="http://127.0.0.1:1231"
export https_proxy="http://127.0.0.1:1231"

然后继续安装,出现了错误,好像是pip安装哪个库时出现了版本依赖错误

#python-2-support pip 21.0 will remove support for this functionality.
Requirement already satisfied: setuptools in /home/chad/.espressif/python_env/idf4.0_py2.7_env/lib/python2.7/site-packages (from -r /home/chad/data/ai-thinker/esp-idf/requirements.txt (line 4)) (44.1.1)
Collecting click>=5.0
  Using cached click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting pyserial>=3.0
  Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB)
Collecting future>=0.15.2
  Using cached future-1.0.0.tar.gz (1.2 MB)
Collecting cryptography>=2.1.4
  Using cached cryptography-3.3.2-cp27-cp27mu-manylinux2010_x86_64.whl (2.6 MB)
Collecting pyparsing<2.4.0,>=2.0.3
  Using cached pyparsing-2.3.1-py2.py3-none-any.whl (61 kB)
Collecting pyelftools>=0.22
  Using cached pyelftools-0.31.tar.gz (14.1 MB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /home/chad/.espressif/python_env/idf4.0_py2.7_env/bin/python /home/chad/.espressif/python_env/idf4.0_py2.7_env/lib/python2.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-krjwBt/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools >= 46.4.0'
       cwd: None
  Complete output (3 lines):
  DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
  ERROR: Could not find a version that satisfies the requirement setuptools>=46.4.0 (from versions: 0.6b1, 0.6b2, 0.6b3, ..., 44.1.1)
  ERROR: No matching distribution found for setuptools>=46.4.0
  ----------------------------------------
ERROR: Command errored out with exit status 1: /home/chad/.espressif/python_env/idf4.0_py2.7_env/bin/python /home/chad/.espressif/python_env/idf4.0_py2.7_env/lib/python2.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-krjwBt/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools >= 46.4.0' Check the logs for full command output.
Traceback (most recent call last):
  File "/home/chad/data/ai-thinker/esp-idf/tools/idf_tools.py", line 1387, in <module>
    main(sys.argv[1:])
  File "/home/chad/data/ai-thinker/esp-idf/tools/idf_tools.py", line 1383, in main
    action_func(args)
  File "/home/chad/data/ai-thinker/esp-idf/tools/idf_tools.py", line 1196, in action_install_python_env
    subprocess.check_call(run_args, stdout=sys.stdout, stderr=sys.stderr)
  File "/usr/lib/python2.7/subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/chad/.espressif/python_env/idf4.0_py2.7_env/bin/python', '-m', 'pip', 'install', '--no-warn-script-location', '-r', '/home/chad/data/ai-thinker/esp-idf/requirements.txt']' returned non-zero exit status 1

排查发现,这个包是Collecting pyelftools>=0.22,看到这张图中安装的是0.26

从之前的日志能看到依赖文件 /home/chad/data/ai-thinker/esp-idf/requirements.txt里面是:

  1 # This is a list of python packages needed for ESP-IDF. This file is used w    ith pip.                                                                   
  2 # Please see the Get Started section of the ESP-IDF Programming Guide for f    urther information.
  3 #
  4 setuptools
  5 # The setuptools package is required to install source distributions and on     some systems is not installed by default.
  6 # Please keep it as the first item of this list.
  7 #
  8 click>=5.0
  9 pyserial>=3.0
 10 future>=0.15.2
 11 cryptography>=2.1.4
 12 pyparsing>=2.0.3,<2.4.0
 13 pyelftools>=0.22 // 改成: pyelftools>=0.22,<0.28

pyelftools>=0.22 改为 pyelftools>=0.22,<0.28,安装即可。

make menuconfig 时出错

fatal error: ncurses.h: No such file or directory

因为缺少库,编译Busybox时,出现错误fatal error: curses.h: No such file or directory
使用 sudo apt-get install libncurses5-dev libncursesw5-dev安装即可。
再次运行,最后出错

b_server/sdkconfig.defaults...
Your display is too small to run Menuconfig!
It must be at least 19 lines by 80 columns.
make: *** No rule to make target 'menuconfig', needed by '/home/chad/data/ai-thinker/examples/single_chip/camera_web_server/sdkconfig'.  Stop.

这个不慌,界面太小了,放大即可。

编译:make
编译完成后提醒烧录指令

To flash all build output, run 'make flash' or:
python /home/chad/data/ai-thinker/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 230400 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0x1000 /home/chad/data/ai-thinker/examples/single_chip/camera_web_server/build/bootloader/bootloader.bin 0x10000 /home/chad/data/ai-thinker/examples/single_chip/camera_web_server/build/camera_web_server.bin 0x8000 /home/chad/data/ai-thinker/examples/single_chip/camera_web_server/build/partitions.bin

make flash, 或 xxxxx
我用 make flash 烧录时报错

: recipe for target 'flash' failed
make: *** [flash] Error 1

便试着用比较长的那个指令,可以~

打开串口监听 make monitor
如果报权限错误可以先 su root 再打开
image.png
没有显示连接成功,
但是在路由器界面可以看到连接了
image.png

访问:
image.png
手机端查看
image.png
成功了。后续需要使用Arduino在Windows下开发吧。

其他:
ESP32-CAM 故障排除指南:修复的最常见问题

  • 13
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值