Use M5CORE devices to connect to TimerCAM/Unit CAM through the GROVE interface, enabling control over the camera to transmit images via UART for preview on the M5CORE screen, or to configure timed shooting for cloud upload (returning a fixed HTTP API).
UIFlow supports configuring the camera to switch between UART
and Wi-Fi
modes. Wi-Fi mode supports timed shooting and automatic upload of images to the M5 cloud, returning the image call interface (URL). In UART mode, users can obtain image frames through UART communication with other control devices
and modify image parameters. The CORE controller will be used as an example below, connecting to UnitCAM and retrieving image data.
Cloud Mode Functions:
Configure the camera to connect to a specified WiFi
Set-unitcam-connect-wifi-ssid
Configure the interval for camera image upload to the cloud
Set-unitcam-cloud-mode-upload-interval
Get camera Token
Get-unitcam-cloud-token
Get camera cloud image URL
Get-unitcam-cloud-image-url
UART Mode Functions:
In UART mode, start the thread for displaying images on the screen, with the default display coordinates at 0,0
Set-unitcam-image-show-in-screen
Set the camera return image size
Set-unitcam-image-size
Set image display position
Set-unitcam-image-position-x-y
Command:
Switch between UART/CLOUD modes
Switch-unitcam-mode-to-UART/CLOUD
Set the brightness of the camera onboard LED
Set-unitcam, led-brightness
import unit
# Create a unitcam instance
unitcam0 = unit.get(unit.UNITCAM, unit.PORTB)
# UART mode: unitcam0.UART_MODE
# WIFI mode: unitcam0.CLOUD_MODE
unitcam0.set_mode(unitcam0.UART_MODE)
# In WiFi mode, configure the camera to connect to specified WiFi
unitcam0.set_wifi('', '')
# In WiFi mode, configure the interval for camera image upload to the cloud
unitcam0.set_upload_time(5)
# Get camera Token
unitcam_token = unitcam0.get_token()
# Concatenate fixed domain fields to get camera cloud image URL
unicam_image_url = 'camera.m5stack.com/timer-cam/image?tok=' + unitcam0.get_token()
# In UART mode, start the thread for displaying images on the screen, with the default display coordinates at 0,0
unitcam0.set_show(True)
# Set the camera return image size
#unitcam0.SIZE_800_600
#unitcam0.SIZE_640_480
#unitcam0.SIZE_320_
240
#unitcam0.SIZE_240_240
#unitcam0.SIZE_160_120
unitcam0.set_image_size(unitcam0.SIZE_320_240)
# Set the brightness of the Unit CAM onboard LED, value: 0~100
unitcam0.set_led_brightness(0)