Time lapse snapshot

Hi, I´d like to use the openMV cam H7 to take snapshots (GRAYSCALE, VGA resolution) every 2 seconds. I also want to give images a name based on timestamp and save them in jpg. I found the below code and I saved it on the cam, then I disconnected the USB and started powering the cam with a power bank. When I reconnected the cam to the laptop to see the saved images it could not find the cam anymore. Suggestion? Is there something I should modify in the code?

import pyb, machine, sensor, image, pyb, os

# Create and init RTC object.
rtc = pyb.RTC()
newFile  =False

except OSError: # If the log file doesn't exist then set the RTC and set newFile to True
   #datetime format: year, month, day, weekday (Monday=1, Sunday=7), hours (24 hour clock), minutes, seconds, subseconds (counds down from 255 to 0)
   rtc.datetime((2018, 3, 9, 5, 13, 0, 0, 0)) 
   newFile = True
year = str(dateTime[0])
month = '%02d' % dateTime[1]
day = '%02d' % dateTime[2]
hour = '%02d' % dateTime[4]
minute = '%02d' % dateTime[5]
second = '%02d' % dateTime[6]
subSecond = str(dateTime[7])
newName='I'+year+month+day+hour+minute+second # Image file name based on RTC 

# Enable RTC interrupts every 10 seconds, camera will RESET after wakeup from deepsleep Mode.


sensor.reset() # Initialize the camera sensor.
sensor.skip_frames(time = 1000) # Let new settings take affect.
if(newFile): # If log file does not exist then create it   
   with open('time.txt', 'a') as timeFile:  # Write text file to keep track of date, time and image number
      timeFile.write('Date and time format: year, month, day, hours, minutes, seconds, subseconds' + '\n')
      timeFile.write(newName + ',' + year + ',' + month +  ',' + day +  ',' + hour +  ',' + minute +  ',' + second +  ',' + subSecond + '\n')
   with open('time.txt', 'a') as timeFile:  # Append to date, time and image number to text file
      timeFile.write(newName + ',' + year + ',' + month +  ',' + day +  ',' + hour +  ',' + minute +  ',' + second +  ',' + subSecond + '\n')
# Take photo and save to SD card
img.save('images/' + newName, quality=90)

# Enter Deepsleep Mode

Try updating the firmware, I’ve just released a new firmware image which fixes some issues with the RTC and deepsleep on the H7.

Hi, if you use deep sleep in your script the computer will not be able to connect to the camera because the script turns the camera power off. Directly connect the USD card to the PC.

I was able to see the pictures but the date and time were wrong. And also I don´t know how to make it take snapshots every exactly 30 seconds for example… What should I modify in the code?

# Enable RTC interrupts every x seconds, camera will RESET after wakeup from deepsleep Mode.
rtc.wakeup(30 * 1000)

Note if you’re having any other issues with RTC and deepsleep on the H7 you should update the firmware.

Thank you.
And sorry if ask these simple questions but I am not an expert in python language.
Actually, I´m having issues with RTC and deepsleep mode. How can I update the firmware?

New firmware is here. Please use the OPENMV4/firmware.binary file to update the OpenMV Cam H7. See the Tools->Run Bootloader dialog in OpenMV IDE.

I will release new resources for the IDE shortly which will do this auotmagically for you.