1.把開關壓下,然後把bin檔案寫入
-檔案採用 https://github.com/lemariva/uPyCam
-寫入時,要按壓BOOT建
2.啟動Bin檔案
-要把開關打開
-重新按壓 BOOT鍵
-利用upycraft ,選擇COM5 ,則會出現>>>
-測試import camera 看看是否OK
3.將sdcard.py 上傳
ampy -p COM7 put sdcard.py
下載位置https://github.com/micropython/micropython/tree/master/drivers/sdcard
4.載入並設定spisd
import machine, sdcard, os
from machine import Pin, SPI
spisd = SPI(-1, sck=Pin(14), mosi=Pin(15), miso=Pin(2))
5.mount 起來
sd = sdcard.SDCard(spisd, machine.Pin(13))
os.mount(sd, ‘/sd’)
6.檢查SD內容
os.listdir(’/sd’)
7.unmount起來
os.umount(’/sd’)
8.將ESP32-Cam啟動,並儲存到img
import camera
camera.init()
img=camera.capture()
9.將img影像儲存到SD卡內
with open(’/sd/b.jpg’,‘w’) as f:
f.write(img)
10.將攝影機關閉
camera.deinit()
11.查詢SD卡內的檔案內容
os.listdir(“/sd”)
程式如下
import machine, sdcard, os
from machine import Pin, SPI
import camera
import time
spisd = SPI(-1, sck=Pin(14), mosi=Pin(15), miso=Pin(2))
#time.sleep(0.1)
while True:
try:
sd = sdcard.SDCard(spisd, machine.Pin(13))
break
except OSError:
print(’ This is error for SD connect.’)
flash=Pin(04,Pin.OUT)
try:
os.mount(sd, ‘/sd’)
except:
os.umount(’/sd’)
os.mount(sd, ‘/sd’)
os.listdir(’/sd’)
#---------------------------
camera.init()
#time.sleep(0.5)
flash.on()
img=camera.capture()
flash.off()
with open(’/sd/.jpg’,‘w’) as f:
f.write(img)
camera.deinit()
os.listdir("/sd")
os.umount(’/sd’)
PS:
1.如果出現 OSError: no SD card
-則把SD重新插拔
-先用Try except 處理了
2.如果要自己編譯Bin 檔案
-依照這篇https://github.com/shariltumin/esp32-cam-micropython/tree/master/esp32-cam-1-11-498
本文详细介绍ESP32-Cam微控制器如何进行SD卡的读写操作,包括bin文件的烧录、sdcard.py的上传、SPI配置、SD卡挂载与卸载、图像捕获及存储等步骤,为开发者提供实用的编程指南。

被折叠的 条评论
为什么被折叠?



