esp32-cam-micropython-2022
esp32-cam-micropython-2022 copied to clipboard
Camera probe failed with error 0x103(ESP_ERR_INVALID_STATE)
Several years of fighting with various bootup issues the latest camera does the following: takes a picture, deinit, init and then it won't take a 2nd picture. A machine reset after deinit fixes it some times.
A power-on reset is the most reliable.
Appreciate any suggestions.
Camera ready?: True
E (139170) camera: Camera probe failed with error 0x103(ESP_ERR_INVALID_STATE)
E (139180) camera: Camera Init Failed
Camera ready?: False
E (140300) cam_hal: cam_config(409): cam intr alloc failed
E (140300) camera: Camera config failed with error 0xffffffff
E (140300) camera: Camera Init Failed
Camera ready?: False
E (141420) cam_hal: cam_config(409): cam intr alloc failed
E (141420) camera: Camera config failed with error 0xffffffff
E (141420) camera: Camera Init Failed
import machine
import time
import gc
gc.collect()
if machine.reset_cause() == machine.SOFT_RESET:
print('doing a machine.reset()')
time.sleep_ms(5)
machine.reset()
print('wait 2 seconds to allow a CTRL-C')
time.sleep(2)
pix = const(17)
frame = const(18)
PIXFORMAT = {
'RGB565':1, # 2BPP/RGB565
'YUV422':2, # 2BPP/YUV422
'YUV420':3, # 1.5BPP/YUV420
'GRAYSCALE':4, # 1BPP/GRAYSCALE
'JPEG':5, # JPEG/COMPRESSED
'RGB888':6, # 3BPP/RGB888
'RAW':7, # RAW
'RGB444':8, # 3BP2P/RGB444
'RGB555':9, # 3BP2P/RGB555
}
FRAMESIZE = {
'96X96':1, # 96x96
'QQVGA':2, # 160x120
'QCIF':3, # 176x144
'HQVGA':4, # 240x176
'240X240':5, # 240x240
'QVGA':6, # 320x240
'CIF':7, # 400x296
'HVGA':8, # 480x320
'VGA':9, # 640x480
'SVGA':10, # 800x600
'XGA':11, # 1024x768
'HD':12, # 1280x720
'SXGA':13, # 1280x1024
'UXGA':14, # 1600x1200
'FHD':15, # 1920x1080
'P_HD':16, # 720x1280
'P_3MP':17, # 864x1536
'QXGA':18, # 2048x1536
}
n = PIXFORMAT.get('JPEG')
s = FRAMESIZE.get('SXGA')
import camera # do this after the above machine.reset()
camera.conf(pix, n) # set pixelformat
camera.conf(frame, s) # set framesize
def main():
while True:
if 1 == 1: # for testing
# wait for camera ready
for i in range(5):
cam = camera.init()
print("Camera ready?: ", cam)
if cam:
break
else:
time.sleep(1)
else:
print('Timeout, doing a machine.reset()')
time.sleep_ms(5)
machine.reset()
# other settings after init
camera.quality(5)
camera.brightness(-2)
print('taking a picture')
time.sleep_ms(10)
img = camera.capture()
time.sleep_ms(100)
print('picture taken')
time.sleep_ms(10)
camera.deinit()
# try leaving this out
machine.reset()
# wait for camera ready
for i in range(5):
cam = camera.init()
print("Camera ready?: ", cam)
if cam:
break
else:
time.sleep(1)
else:
print('Timeout, doing a machine.reset()')
time.sleep_ms(5)
machine.reset()
# other settings after camera.init()
camera.quality(5)
camera.brightness(-2)
else:
print('looping')
time.sleep_ms(10)
if __name__ == '__main__':
main()