• Stars
    star
    430
  • Rank 101,083 (Top 2 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

add camera support to MicroPython

micropython-camera-driver

This repository adds camera (OV2640) support to MicroPython for the ESP32 family.

NEW: The camera uses now the PSRAM. Thus, you are able to take photos with more resolution. The standard mode is without PSRAM you can activate that using the argument fb_location=camera.PSRAM. Thanks @mocleiri for the info and the MicroPython PR.

I follow the advice of #32 and modify the repository to fit to those requirements.

For more information about installing MicroPython visit this tutorial: https://lemariva.com/blog/2022/01/micropython-upgraded-support-cameras-m5camera-esp32-cam-etc

The MicroPython example codes are included here:

Example

import camera

## ESP32-CAM (default configuration) - https://bit.ly/2Ndn8tN
camera.init(0, format=camera.JPEG, fb_location=camera.PSRAM)

## M5Camera (Version B) - https://bit.ly/317Xb74
camera.init(0, d0=32, d1=35, d2=34, d3=5, d4=39, d5=18, d6=36, d7=19,
            format=camera.JPEG, framesize=camera.FRAME_VGA, xclk_freq=camera.XCLK_10MHz,
            href=26, vsync=25, reset=15, sioc=23, siod=22, xclk=27, pclk=21, fb_location=camera.PSRAM)   #M5CAMERA

## T-Camera Mini (green PCB) - https://bit.ly/31H1aaF
import axp202 # source https://github.com/lewisxhe/AXP202_PythonLibrary
# USB current limit must be disabled (otherwise init fails)
axp=axp202.PMU( scl=22, sda=21, address=axp202.AXP192_SLAVE_ADDRESS  )
limiting=axp.read_byte( axp202.AXP202_IPS_SET )
limiting &= 0xfc
axp.write_byte( axp202.AXP202_IPS_SET, limiting )

camera.init(0, d0=5, d1=14, d2=4, d3=15, d4=18, d5=23, d6=36, d7=39,
            format=camera.JPEG, framesize=camera.FRAME_VGA, 
            xclk_freq=camera.XCLK_20MHz,
            href=25, vsync=27, reset=-1, pwdn=-1,
            sioc=12, siod=13, xclk=32, pclk=19)

# The parameters: format=camera.JPEG, xclk_freq=camera.XCLK_10MHz are standard for all cameras.
# You can try using a faster xclk (20MHz), this also worked with the esp32-cam and m5camera
# but the image was pixelated and somehow green.

## Other settings:
# flip up side down
camera.flip(1)
# left / right
camera.mirror(1)

# framesize
camera.framesize(camera.FRAME_240x240)
# The options are the following:
# FRAME_96X96 FRAME_QQVGA FRAME_QCIF FRAME_HQVGA FRAME_240X240
# FRAME_QVGA FRAME_CIF FRAME_HVGA FRAME_VGA FRAME_SVGA
# FRAME_XGA FRAME_HD FRAME_SXGA FRAME_UXGA FRAME_FHD
# FRAME_P_HD FRAME_P_3MP FRAME_QXGA FRAME_QHD FRAME_WQXGA
# FRAME_P_FHD FRAME_QSXGA
# Check this link for more information: https://bit.ly/2YOzizz

# special effects
camera.speffect(camera.EFFECT_NONE)
# The options are the following:
# EFFECT_NONE (default) EFFECT_NEG EFFECT_BW EFFECT_RED EFFECT_GREEN EFFECT_BLUE EFFECT_RETRO

# white balance
camera.whitebalance(camera.WB_NONE)
# The options are the following:
# WB_NONE (default) WB_SUNNY WB_CLOUDY WB_OFFICE WB_HOME

# saturation
camera.saturation(0)
# -2,2 (default 0). -2 grayscale 

# brightness
camera.brightness(0)
# -2,2 (default 0). 2 brightness

# contrast
camera.contrast(0)
#-2,2 (default 0). 2 highcontrast

# quality
camera.quality(10)
# 10-63 lower number means higher quality

buf = camera.capture()

Important

  • Except when using CIF or lower resolution with JPEG, the driver requires PSRAM to be installed and activated. This is activated, but it is limited due that MicroPython needs RAM.
  • Using YUV or RGB puts a lot of strain on the chip because writing to PSRAM is not particularly fast. The result is that image data might be missing. This is particularly true if WiFi is enabled. If you need RGB data, it is recommended that JPEG is captured and then turned into RGB using fmt2rgb888 or fmt2bmp/frame2bmp. The conversion is not supported. The formats are included, but I got almost every time out of memory, trying to capture an image in a different format than JPEG.
  • The firmware was compiled without BLE support. Otherwise I got region 'iram0_0_seg' overflowed by xxx bytes.

Firmware

I've included a compiled MicroPython firmware with camera (check the firmware folder). The firmware was compiled using following versions and hashes:

To flash it to the board, you need to type the following:

esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash
esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 micropython_camera_feeeb5ea3_esp32_idf4_4.bin

More information is available in this tutorial.

If you want to compile your driver from scratch follow the next section:

DIY

Read this section if you want to include the camera support to MicroPython from scratch. To do that follow these steps:

  1. Clone the MicroPython repository:

    git clone --recursive https://github.com/micropython/micropython.git
    

    Note: The MicroPython repo changes a lot, I've done this using the version with the hash mentioned above.

    ⚠️ If you want to directly replace the original files with the provided in this repository, be sure that you've taken the same commit hash. MicroPython changes a lot, and you'll compiling issues if you ignore this warning.

  2. Copy the files and folders inside the boards folder into micropython/ports/esp32/boards. Or use a symbolic link ln -s [...]/micropython-camera-driver/boards/ESP32_CAM micropython/ports/esp32/boards/ESP32_CAM (recommended - change the [...] to the right path).

  3. Clone the https://github.com/espressif/esp32-camera repository inside the ~/esp/esp-idf/components folder.

        cd ~/esp/esp-idf/components
        git clone https://github.com/espressif/esp32-camera
        git checkout [CHECK-HASH-ABOVE]
  4. Compile the firmware by typing following commands:

    cd micropython/ports/esp32
    make USER_C_MODULES=../../../../micropython-camera-driver/src/micropython.cmake BOARD=ESP32_CAM all
    

    Note that the folder micropython-camera-driver should be in the same folder level as the micropython. Otherwise, you'll need to change the path (../../../../micropython-camera-driver/src/) to the micropython.cmake file.

  5. Deploy the firmware into the ESP32 by typing:

    cd micropython/ports/esp32
    esptool.py --port /dev/ttyUSB0 erase_flash
    esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 build-ESP32_CAM/firmware.bin
    

More Repositories

1

uPyLoRaWAN

ESP32 using MicroPython meets LoRa and LoRaWAN.
Python
219
star
2

uPyCam

Take a photo with an ESP32-CAM running MicroPython
Python
139
star
3

RT-Tools-RPi

Tools for Patching the Rasbian kernel with RT-Preempt.
Jupyter Notebook
68
star
4

uPySensors

MicroPython sensor, actuator and display libraries
Python
60
star
5

uPyEcho

Emulated Belkin WeMo device that works with Amazon Echo (Alexa) using MicroPython on an ESP32
Python
53
star
6

micropython-core2

MicroPython version for the M5Stack CORE2
C
51
star
7

uPyPortal

A captive portal for MicroPython using ESP32 (WeMos)
Python
40
star
8

raspbian-EdgeTPU

Docker with Raspbian, SSH and the Coral USB Edge TPU libraries.
Dockerfile
34
star
9

ESP32MicroPython

Basic functions/libraries for ESP32 running MicroPython
Python
31
star
10

ePaperWidgets

Widgets on E-INK display using a Raspberry Pi
Python
29
star
11

rPIFocus

Add autofocus to the 16 mm Telephoto Lens mounted on the Raspberry Pi HQ Camera (Raspberry Pi Microservice Application)
Python
28
star
12

uPyEINK

Control a Waveshare 7.5" E-INK display using an ESP32 running MicroPython
Python
26
star
13

MaixPy_YoloV2

YOLOv2 object detector training for a MAix-board
Python
23
star
14

uPyM5BLE

This project is about using the BLE module of an M5Stack running MicroPython
Python
19
star
15

SensorTag-CC2650

BLE SensorTag Android application working on Android Studio 3.1.2 and Android SDK 27
Java
18
star
16

SquirelCrawl

This code compress a webpage into an html file. Images are converted to base64 and integrated together with CSS files in the html. Useful for webpages on microcontrollers (or low memory devices), a complete offline copy of a webpage etc.
Python
18
star
17

wifi-cups-server

Raspberry PI CUPS - Plug&Play solution to make your old printer Wi-Fi compatible
HTML
15
star
18

micropython-i2s-driver

This repository adds I2S support to MicroPython for the ESP32 family.
Makefile
14
star
19

SmartUPy

Controlling "Tuya-type" smart power outlets using MicroPython
Python
13
star
20

image2eink

This repository includes code to convert an image to a 3-color-image in order to display it on an E-ink display.
Python
13
star
21

uPyFocus

Add autofocus to the 16 mm Telephoto Lens mounted on the Raspberry Pi HQ Camera (Firmware for the M5Stack)
Python
13
star
22

uPyM5Echo

Two applications for the M5Stack ATOM Echo running MicroPython.
Python
12
star
23

uPyBikeTracker

Python
12
star
24

uPySteppers

DIY rotating platform using an ESP32 connected to Wi-Fi
Python
11
star
25

wipy2.0-GPS

Connect a Ublox NEO-6M/NE0-M8N gps module to a WiPy2.0/3.0
Python
10
star
26

timeular-python

Linux application for the Timeular ZEI / Timeular Tracker programmed in Python
Python
10
star
27

wipy2.0-Weather

This project is about connecting a Wipy 2.0 with an Ublox NEO-6M/M8N GPS and a ST7735 display. The Wipy 2.0 gets the GPS coordinates, makes a get request to obtain weather information and displays this info on the LCD.
Python
9
star
28

uPyIMU

Camera stabilisation application!
Python
7
star
29

micropython-pico-mbedtls

MicroPython with Encryption (MBEDTLS) support for Raspberry Pi Pico
C
7
star
30

uPyGeo

Geolocation on WiPy 2.0 (MicroPython) without GPS Module, only WiFi
Python
7
star
31

uPyLaser

VL53L0X sample application for ESP32, ESP8266 & WiPy (PyCom)
Python
7
star
32

uPyMaixYoloV2

A YOLOv2 object detector running on AIoT using MicroPython
Python
5
star
33

uPyIoT

Connect an M5Stack ATOM running MicroPython to the Google Cloud Platform (GCP) to collect air-quality variables obtained from reading sensors.
Python
5
star
34

uPyJupyter

Dockerfile: Jupyter with custom added Kernel for ESP32/ESP8266
Jupyter Notebook
5
star
35

nRF24Things

nrf24l01+ modules working with Android Things > 0.8.1 RF24, RF24Network and RF24Mesh implemented in Java
Java
4
star
36

uPyBlynk

Blynk and Micropython on WiPy 2.0/3.0 and ESP32 for home automation
Python
4
star
37

haproxy-certbot

A Dockerized service that adds SSL layer (reverse proxy) and automatically renews the SSL certificate when needed.
Shell
3
star
38

ws2812b-wipy2.0-christmas

Merry Christmas lights using WS2812b leds and WiPy2.0
Python
3
star
39

rPI-Tests

Tools & data: Performance Tests on Raspberry PI 3B, 3B+ and 4B
Jupyter Notebook
3
star
40

openproject-docker

Docker-compose configuration to run OpenProject and NginX on a f1-micro VM instance on GPC
Shell
3
star
41

MQTT-M5Camera

MQTT subscriber to save photos sent from an M5Camera
Python
3
star
42

uPyTrain

This tutorial helps you update a BRIO locomotive using an ESP32 that runs MicroPython. As a result, you can control the speed of the BRIO using a cell phone or a laptop (basically, everything that has a browser).
Python
3
star
43

tiva_tm4c1294_ov7670_security_camera

"Security camera" using ov7670 and LauchPad Tiva(TM) C Series TM4C1294XL
C
3
star
44

uPyCO2

This repository has the code that helps you to build DIY CO2 measuring devices and connect them to your smartphone.
Python
2
star
45

docker-embedded-systems

Docker on Embedded Systems
2
star
46

PiCoBo-Dehumidifier

This project makes a peltier element dehumidifier "smarter". The PiCoBo board measures the humidity using a DHT11 sensor, and controls the peltier element and the fans.
C++
2
star
47

adsensekit-ads

AdsenseKit for Pagekit offers a quicker & flexible way to insert Google Adsense or any Ads code into a blog post.
JavaScript
1
star
48

N-Queens-Problem

N-Queens-Problem Python multi-thread testbench.
Python
1
star
49

tiva_tm4c1294_ov7670

LaunchPad Tiva(TM) C Series TM4C1294XL connected to OnmiVision ov7670
C
1
star
50

wipy2.0-MIC

Vu Meter using: Wipy2.0, SPW2430 MEMS Microphone & WS2812 led strip
Python
1
star
51

nrf24amini

Arduino Pro Mini node compatible with nRF24Things (Android Things)
C++
1
star
52

wipy2.0-ST7735

Connect a ST7735 display to a WiPy2.0
Python
1
star
53

uPyDistance

HCSR04 sample application for ESP32, ESP8266 & WiPy (PyCom)
Python
1
star
54

zerynth-google-iot

Connecting the ESP32 to Google Iot Core
Python
1
star
55

lemariva

Personal information and motivation for GitHub
1
star