With a WiFi-enabled board like the Espressif Kaluga, you can upload your image data to Adafruit IO. We made sure that this example works with the free version, so you can try it out even if you haven't upgraded to a Plus subscription yet. New to Adafruit IO? Start with this guide to learn the basics.
Set up the IO Feed
Create a feed called "image" and then set "Feed History" to "OFF". This allows storage of data up to 100kB, which is plenty to upload JPEGs at 640x480 resolution. (You can choose another feed name but you'll need to make sure that Adafruit IO's "key" for the feed matches what you use in your CircuitPython program!)
Set up the IO Dashboard
Create a new dashboard. Click the gear icon and then "Create New Block". Choose the camera icon ("image") and then select your feed named "image". Enter a block title if you like, and click "Create Block".
Secrets File Setup for Adafruit IO
If you don't have a secrets.py file in your CIRCUITPY drive yet, create one and add the information about your WiFi connection.
Then, add the following code to your secrets.py file, replacing _your_adafruit_io_username
with your Adafruit IO username.
Then, replace _your_big_huge_super_long_aio_key_
with your Adafruit IO Active Key.
secrets = { 'ssid' : '_your_wifi_ssid_', 'password' : '_your_wifi_password_', 'aio_username' : '_your_adafruit_io_username_', 'aio_key' : '_your_big_huge_super_long_aio_key_', }
Make sure you save this file before proceeding as secrets.py in the root directory of your board CIRCUITPY drive.
Upload the code
Grab the Bundle below and unzip it on your Espressif Kaluga's CIRCUITPY drive. It will automatically start the code and upload a 640x480 JPEG to Adafruit IO every 3 seconds or so.
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries # # SPDX-License-Identifier: Unlicense """ The Kaluga development kit comes in two versions (v1.2 and v1.3); this demo is tested on v1.3. The audio board must be mounted between the Kaluga and the LCD, it provides the I2C pull-ups(!) This example requires that your WIFI and Adafruit IO credentials be configured in CIRCUITPY/secrets.py, and that you have created a feed called "image" with history disabled. The maximum image size is 100kB after base64 encoding, or about 65kB before base64 encoding. In practice, "SVGA" (800x600) images are typically around 40kB even though the "capture_buffer_size" (theoretical maximum size) is (width*height/5) bytes or 96kB. """ import binascii import ssl import time from secrets import secrets # pylint: disable=no-name-in-module import board import busio import wifi import socketpool import adafruit_minimqtt.adafruit_minimqtt as MQTT from adafruit_io.adafruit_io import IO_MQTT import adafruit_ov2640 feed_name = "image" print("Connecting to WIFI") wifi.radio.connect(secrets["ssid"], secrets["password"]) pool = socketpool.SocketPool(wifi.radio) print("Connecting to Adafruit IO") mqtt_client = MQTT.MQTT( broker="io.adafruit.com", username=secrets["aio_username"], password=secrets["aio_key"], socket_pool=pool, ssl_context=ssl.create_default_context(), ) mqtt_client.connect() io = IO_MQTT(mqtt_client) bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD) cam = adafruit_ov2640.OV2640( bus, data_pins=board.CAMERA_DATA, clock=board.CAMERA_PCLK, vsync=board.CAMERA_VSYNC, href=board.CAMERA_HREF, mclk=board.CAMERA_XCLK, mclk_frequency=20_000_000, size=adafruit_ov2640.OV2640_SIZE_QVGA, ) cam.flip_x = False cam.flip_y = False cam.test_pattern = False cam.size = adafruit_ov2640.OV2640_SIZE_SVGA cam.colorspace = adafruit_ov2640.OV2640_COLOR_JPEG jpeg_buffer = bytearray(cam.capture_buffer_size) while True: jpeg = cam.capture(jpeg_buffer) print(f"Captured {len(jpeg)} bytes of jpeg data") # b2a_base64() appends a trailing newline, which IO does not like encoded_data = binascii.b2a_base64(jpeg).strip() print(f"Expanded to {len(encoded_data)} for IO upload") io.publish("image", encoded_data) print("Waiting 3s") time.sleep(3)
Text editor powered by tinymce.