Ready to take some photos of your favorite goat-based still life*? Nice. Here you'll code a simple point-and-shoot camera as a way to get familiar with the MEMENTO's basic functions. It'll be just like that Instamatic you had in the 1970s, except digital and programmable!
* Other subjects are acceptable as well. We don't judge.
CircuitPython
Be sure you've installed CircuitPython on your MEMENTO before proceeding.
SD Card
Format your SD card to FAT32 using the method shown on the Formatting Notes page in this guide (don't rely on your operating system tools, the official formatter works more reliably).
With the MEMENTO turned off, insert the SD card into the MEMENTO's SD card reader as shown -- note the direction of the pins. Press it in until it bottoms out on the spring and then release pressure so it clicks into place.
Download the Project Bundle
Your project will use a specific set of CircuitPython libraries, and the code.py file. To get everything you need, click on the Download Project Bundle button below, and uncompress the .zip file.
Connect your computer to the board via a known good USB power+data cable. A new flash drive should show up as CIRCUITPY.
Drag the contents of the uncompressed bundle directory onto your board CIRCUITPY drive, replacing any existing files or directories with the same names, and adding any new ones that are necessary.
# SPDX-FileCopyrightText: Copyright (c) 2023 john park for Adafruit Industries # # SPDX-License-Identifier: MIT """ simple point-and-shoot camera example. No bells! Zero whistles! """ import time import adafruit_pycamera # pylint: disable=import-error pycam = adafruit_pycamera.PyCamera() pycam.mode = 0 # only mode 0 (JPEG) will work in this example # User settings - try changing these: pycam.resolution = 8 # 0-12 preset resolutions: # 0: 240x240, 1: 320x240, 2: 640x480, 3: 800x600, 4: 1024x768, # 5: 1280x720, 6: 1280x1024, 7: 1600x1200, 8: 1920x1080, 9: 2048x1536, # 10: 2560x1440, 11: 2560x1600, 12: 2560x1920 pycam.led_level = 1 # 0-4 preset brightness levels pycam.led_color = 0 # 0-7 preset colors: 0: white, 1: green, 2: yellow, 3: red, # 4: pink, 5: blue, 6: teal, 7: rainbow pycam.effect = 0 # 0-7 preset FX: 0: normal, 1: invert, 2: b&w, 3: red, # 4: green, 5: blue, 6: sepia, 7: solarize print("Simple camera ready.") pycam.tone(800, 0.1) pycam.tone(1200, 0.05) while True: pycam.blit(pycam.continuous_capture()) pycam.keys_debounce() if pycam.shutter.short_count: print("Shutter released") pycam.tone(1200, 0.05) pycam.tone(1600, 0.05) try: pycam.display_message("snap", color=0x00DD00) pycam.capture_jpeg() pycam.live_preview_mode() except TypeError as exception: pycam.display_message("Failed", color=0xFF0000) time.sleep(0.5) pycam.live_preview_mode() except RuntimeError as exception: pycam.display_message("Error\nNo SD Card", color=0xFF0000) time.sleep(0.5) if pycam.card_detect.fell: print("SD card removed") pycam.unmount_sd_card() pycam.display.refresh() if pycam.card_detect.rose: print("SD card inserted") pycam.display_message("Mounting\nSD Card", color=0xFFFFFF) for _ in range(3): try: print("Mounting card") pycam.mount_sd_card() print("Success!") break except OSError as exception: print("Retrying!", exception) time.sleep(0.5) else: pycam.display_message("SD Card\nFailed!", color=0xFF0000) time.sleep(0.5) pycam.display.refresh()
Flip the "-> On" switch and you're ready to go!
Camera HUD
The PyCamera library includes a real-time image preview and heads-up-display (HUD). The HUD provides the following information:
- image pixel resolution
- SD card status
- current effect/filter
- picture mode
Take a Photo
To snap a photo, flip the -> On switch to the right if the camera isn't already on, then once the camera has started and you see the preview image and "SD OK" simply press and release the shutter button (labeled with "Cheese!" or the ✌️ sign if you have the back panel in place). You'll see "snap" show on screen and hear a beep.
The image will be saved to the SD card as a high-quality JPEG with a unique filename.
Image Retrieval
To admire your photo and send it to other goat fanciers, press and release the microSD card to pop it out of the camera. Be careful not to fling it across the room, that spring is pretty springy.
Put your microSD card into an SD card reader on your computer and open up the image (you may need a microSD to SD adapter such as this). You can copy/paste or drag the images onto your computer's hard drive, too. Be sure to eject the microSD card drive from your computer before physically removing it.
Here you can see an 800x600 resolution image (the thumbnail of the preview and HUD won't be there, those were added for clarity in this guide).
Change Resolution
In code you can adjust the resolution by setting a different value for pycam.resolution
.
pycam.resolution = 0 # 0-12 preset resolutions: # 0: 240x240, 1: 320x240, 2: 640x480, 3: 800x600, 4: 1024x768, # 5: 1280x720, 6: 1280x1024, 7: 1600x1200, 8: 1920x1080, 9: 2048x1536, # 10: 2560x1440, 11: 2560x1600, 12: 2560x1920
Here's the 0
setting, which is a 240x240 image.
This is the 1920x1080 option, click the image for the option to see the original at full size.
This is the 2560x1920 option, click the image for the option to see the original at full size.
pycam.effect = 0 # 0-7 preset FX: 0: normal, 1: invert, 2: b&w, 3: red, # 4: green, 5: blue, 6: sepia, 7: solarize
LED Color
If you have the LED light ring faceplate connected, you can set LED brightness and color values using pycam.led_level
and pycam.led_color
.
pycam.led_level = 1 # 0-4 preset brightness levels pycam.led_color = 0 # 0-7 preset colors: 0: white, 1: green, 2: yellow, 3: red, # 4: pink, 5: blue, 6: teal, 7: rainbow
Here are some examples of colored lighting on the scene. There is a lot of ambient light here, so the color is reasonably subtle. With less ambient light the color will be more intense.
Text editor powered by tinymce.