├── LICENSE ├── README.md ├── boot.py ├── main.py ├── ov2640.py ├── ov2640_constants.py ├── ov2640_hires_constants.py └── ov2640_lores_constants.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Nick Amato 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # MicroPython class for OV2640 Camera 3 | 4 | This is a basic interface to the [ArduCAM OV2640](http://www.arducam.com/camera-modules/2mp-ov2640/) under MicroPython for the ESP8266. I wrote this because I could not find any good camera interfaces with MicroPython on the ESP8266. 5 | 6 | Using this class you can: 7 | * Initiate still pictures up to 1600x1200 resolution 8 | * Read them from the camera 9 | * Save them to flash on the ESP8266 10 | 11 | After saving the image you can use other modules to post it to a REST API, 12 | or save a (short) history of pictures on the flash for later retrieval. 13 | 14 | ## Usage - Hardware Setup 15 | 16 | This particular camera has both an i2c and spi interface for setup and 17 | getting data on/off the camera. A good way to wire up the camera to 18 | the ESP8266 is as follows (note Vcc and GND pins are not included here): 19 | 20 | Camera Pin | ESP8266 Pin | 21 | | --------- | ------------ | 22 | | CS | GPIO2 | 23 | | MOSI | GPIO13 | 24 | | MISO | GPIO12 | 25 | | SCK | GPIO14 | 26 | | SDA | GPIO4 | 27 | | SCL | GPIO5 | 28 | 29 | ## Usage - Software 30 | 31 | First upload the module 'ov2640.py' into the root filesystem on the 32 | ESP8266 board you are using. The [ampy](https://github.com/adafruit/ampy) 33 | tool from Adafruit is a useful tool for doing that. Together with 34 | [esptool](https://github.com/espressif/esptool), you can re-flash your 35 | board and load the code here in one shot with these commands. 36 | 37 | First download the latest MicroPython [image from here](http://micropython.org/download#esp8266). 38 | 39 | ``` 40 | sudo esptool.py --port /dev/ttyUSB0 erase_flash 41 | sudo esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 ~/Downloads/esp8266-20170526-v1.9.bin 42 | git clone https://github.com/namato/micropython-ov2640 43 | cd micropython-ov2640 44 | sudo ampy -p /dev/ttyUSB0 put boot.py 45 | sudo ampy -p /dev/ttyUSB0 put main.py 46 | sudo ampy -p /dev/ttyUSB0 put ov2640_constants.py 47 | sudo ampy -p /dev/ttyUSB0 put ov2640_hires_constants.py 48 | sudo ampy -p /dev/ttyUSB0 put ov2640_lores_constants.py 49 | sudo ampy -p /dev/ttyUSB0 put ov2640.py 50 | ``` 51 | 52 | Then initialize and capture still frames using code like this. The included `main.py` contains an example. 53 | 54 | ``` 55 | import ov2640 56 | cam = ov2640.ov2640() 57 | nbytes = cam.capture_to_file("/image.jpg") 58 | ``` 59 | You can then retrieve the image off of the board, upload it to a server, etc. 60 | 61 | A good way to retrieve files for testing/verification is 62 | [rshell](https://github.com/dhylands/rshell). 63 | 64 | ``` 65 | sudo rshell -p /dev/ttyUSB0 66 | Connecting to /dev/ttyUSB0 ... 67 | Welcome to rshell. Use Control-D to exit. 68 | /home/namato/micropython-ov2640> 69 | /home/namato/micropython-ov2640> cp /image2.jpg . 70 | ``` 71 | 72 | This will copy the newly created image locally for viewing. 73 | 74 | ## Credits 75 | 76 | The original driver source from Arducam was instrumental in the creation of this pure 77 | MicroPython version. 78 | 79 | The overall project was inspired by 80 | [esparducam](https://johan.kanflo.com/building-the-esparducam/), but 81 | getting this to work doesn't require any SMD soldering. :) 82 | 83 | -------------------------------------------------------------------------------- /boot.py: -------------------------------------------------------------------------------- 1 | import esp 2 | esp.osdebug(None) 3 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import ov2640 2 | import gc 3 | import time 4 | import sys 5 | 6 | FNAME = 'image2.jpg' 7 | 8 | def main(): 9 | try: 10 | print("initializing camera") 11 | #cam = ov2640.ov2640(resolution=ov2640.OV2640_320x240_JPEG) 12 | cam = ov2640.ov2640(resolution=ov2640.OV2640_1024x768_JPEG) 13 | print(gc.mem_free()) 14 | 15 | clen = cam.capture_to_file(FNAME, True) 16 | print("captured image is %d bytes" % clen) 17 | print("image is saved to %s" % FNAME) 18 | 19 | time.sleep(10) 20 | sys.exit(0) 21 | 22 | except KeyboardInterrupt: 23 | print("exiting...") 24 | sys.exit(0) 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | -------------------------------------------------------------------------------- /ov2640.py: -------------------------------------------------------------------------------- 1 | from ov2640_constants import * 2 | from ov2640_lores_constants import * 3 | from ov2640_hires_constants import * 4 | import machine 5 | import time 6 | import ubinascii 7 | import uos 8 | import gc 9 | 10 | class ov2640(object): 11 | def __init__(self, sclpin=5, sdapin=4, cspin=2, resolution=OV2640_320x240_JPEG): 12 | self.sdapin=sdapin 13 | self.sclpin=sclpin 14 | self.cspin=cspin 15 | self.standby = False 16 | 17 | self.hspi = machine.SPI(1, baudrate=80000000, polarity=0, phase=0) 18 | self.i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4), freq=1000000) 19 | 20 | # first init spi assuming the hardware spi is connected 21 | self.hspi.init(baudrate=2000000) 22 | 23 | # chip select -- active low 24 | self.cspin = machine.Pin(2, machine.Pin.OUT) 25 | self.cspin.on() 26 | 27 | # init the i2c interface 28 | addrs = self.i2c.scan() 29 | print('ov2640_init: devices detected on on i2c:') 30 | for a in addrs: 31 | print('0x%x' % a) 32 | 33 | # select register set 34 | self.i2c.writeto_mem(SENSORADDR, 0xff, b'\x01') 35 | # initiate system reset 36 | self.i2c.writeto_mem(SENSORADDR, 0x12, b'\x80') 37 | 38 | # let it come up 39 | time.sleep_ms(100) 40 | 41 | # jpg init registers 42 | cam_write_register_set(self.i2c, SENSORADDR, OV2640_JPEG_INIT) 43 | cam_write_register_set(self.i2c, SENSORADDR, OV2640_YUV422) 44 | cam_write_register_set(self.i2c, SENSORADDR, OV2640_JPEG) 45 | 46 | # select register set 47 | self.i2c.writeto_mem(SENSORADDR, 0xff, b'\x01') 48 | self.i2c.writeto_mem(SENSORADDR, 0x15, b'\x00') 49 | 50 | # select jpg resolution 51 | cam_write_register_set(self.i2c, SENSORADDR, resolution) 52 | 53 | # test the SPI bus 54 | cam_spi_write(b'\x00', b'\x55', self.hspi, self.cspin) 55 | res = cam_spi_read(b'\x00', self.hspi, self.cspin) 56 | print("ov2640 init: register test return bytes %s" % ubinascii.hexlify(res)) 57 | if (res == b'\x55'): 58 | print("ov2640_init: register test successful") 59 | else: 60 | print("ov2640_init: register test failed!") 61 | 62 | # register set select 63 | self.i2c.writeto_mem(SENSORADDR, 0xff, b'\x01') 64 | # check the camera type 65 | parta = self.i2c.readfrom_mem(SENSORADDR, 0x0a, 1) 66 | partb = self.i2c.readfrom_mem(SENSORADDR, 0x0b, 1) 67 | if ((parta != b'\x26') or (partb != b'\x42')): 68 | print("ov2640_init: device type does not appear to be ov2640, bytes: %s/%s" % \ 69 | (ubinascii.hexlify(parta), ubinascii.hexlify(partb))) 70 | else: 71 | print("ov2640_init: device type looks correct, bytes: %s/%s" % \ 72 | (ubinascii.hexlify(parta), ubinascii.hexlify(partb))) 73 | 74 | def capture_to_file(self, fn, overwrite): 75 | # bit 0 - clear FIFO write done flag 76 | cam_spi_write(b'\x04', b'\x01', self.hspi, self.cspin) 77 | 78 | # bit 1 - start capture then read status 79 | cam_spi_write(b'\x04', b'\x02', self.hspi, self.cspin) 80 | time.sleep_ms(10) 81 | 82 | # read status 83 | res = cam_spi_read(b'\x41', self.hspi, self.cspin) 84 | cnt = 0 85 | #if (res == b'\x00'): 86 | # print("initiate capture may have failed, return byte: %s" % ubinascii.hexlify(res)) 87 | 88 | # read the image from the camera fifo 89 | while True: 90 | res = cam_spi_read(b'\x41', self.hspi, self.cspin) 91 | mask = b'\x08' 92 | if (res[0] & mask[0]): 93 | break 94 | #print("continuing, res register %s" % ubinascii.hexlify(res)) 95 | time.sleep_ms(10) 96 | cnt += 1 97 | #print("slept in loop %d times" % cnt) 98 | 99 | # read the fifo size 100 | b1 = cam_spi_read(b'\x44', self.hspi, self.cspin) 101 | b2 = cam_spi_read(b'\x43', self.hspi, self.cspin) 102 | b3 = cam_spi_read(b'\x42', self.hspi, self.cspin) 103 | val = b1[0] << 16 | b2[0] << 8 | b3[0] 104 | print("ov2640_capture: %d bytes in fifo" % val) 105 | gc.collect() 106 | 107 | bytebuf = [ 0, 0 ] 108 | picbuf = [ b'\x00' ] * PICBUFSIZE 109 | l = 0 110 | bp = 0 111 | if (overwrite == True): 112 | #print("deleting old file %s" % fn) 113 | try: 114 | uos.remove(fn) 115 | except OSError: 116 | pass 117 | while ((bytebuf[0] != b'\xd9') or (bytebuf[1] != b'\xff')): 118 | bytebuf[1] = bytebuf[0] 119 | if (bp > (len(picbuf) - 1)): 120 | #print("appending buffer to %s" % fn) 121 | appendbuf(fn, picbuf, bp) 122 | bp = 0 123 | 124 | bytebuf[0] = cam_spi_read(b'\x3d', self.hspi, self.cspin) 125 | l += 1 126 | #print("read so far: %d, next byte: %s" % (l, ubinascii.hexlify(bytebuf[0]))) 127 | picbuf[bp] = bytebuf[0] 128 | bp += 1 129 | if (bp > 0): 130 | #print("appending final buffer to %s" % fn) 131 | appendbuf(fn, picbuf, bp) 132 | print("read %d bytes from fifo, camera said %d were available" % (l, val)) 133 | return (l) 134 | 135 | # XXX these need some work 136 | def standby(self): 137 | # register set select 138 | self.i2c.writeto_mem(SENSORADDR, 0xff, b'\x01') 139 | # standby mode 140 | self.i2c.writeto_mem(SENSORADDR, 0x09, b'\x10') 141 | self.standby = True 142 | 143 | def wake(self): 144 | # register set select 145 | self.i2c.writeto_mem(SENSORADDR, 0xff, b'\x01') 146 | # standby mode 147 | self.i2c.writeto_mem(SENSORADDR, 0x09, b'\x00') 148 | self.standby = False 149 | 150 | def cam_write_register_set(i, addr, set): 151 | for el in set: 152 | raddr = el[0] 153 | val = bytes([el[1]]) 154 | if (raddr == 0xff and val == b'\xff'): 155 | return 156 | #print("writing byte %s to addr %x register addr %x" % \ 157 | # (ubinascii.hexlify(val), addr, raddr)) 158 | i.writeto_mem(addr, raddr, val) 159 | 160 | def appendbuf(fn, picbuf, howmany): 161 | try: 162 | f = open(fn, 'ab') 163 | c = 1 164 | for by in picbuf: 165 | if (c > howmany): 166 | break 167 | c += 1 168 | f.write(bytes([by[0]])) 169 | f.close() 170 | except OSError: 171 | print("error writing file") 172 | print("write %d bytes from buffer" % howmany) 173 | 174 | def cam_spi_write(address, value, hspi, cspin): 175 | cspin.off() 176 | modebit = b'\x80' 177 | d = bytes([address[0] | modebit[0], value[0]]) 178 | #print("bytes %s" % ubinascii.hexlify(d)) 179 | #print (ubd.hex()) 180 | hspi.write(d) 181 | cspin.on() 182 | 183 | def cam_spi_read(address, hspi, cspin): 184 | cspin.off() 185 | maskbits = b'\x7f' 186 | wbuf = bytes([address[0] & maskbits[0]]) 187 | hspi.write(wbuf) 188 | buf = hspi.read(1) 189 | cspin.on() 190 | return (buf) 191 | 192 | # cam driver code 193 | # https://github.com/kanflo/esparducam/blob/master/arducam/arducam.c 194 | # register info 195 | # https://github.com/ArduCAM/Sensor-Regsiter-Decoder/blob/master/OV2640_JPEG_INIT.csv 196 | -------------------------------------------------------------------------------- /ov2640_constants.py: -------------------------------------------------------------------------------- 1 | 2 | OV2640_JPEG_INIT = [ 3 | [ 0xff, 0x00 ], 4 | [ 0x2c, 0xff ], 5 | [ 0x2e, 0xdf ], 6 | [ 0xff, 0x01 ], 7 | [ 0x3c, 0x32 ], 8 | [ 0x11, 0x04 ], 9 | [ 0x09, 0x02 ], 10 | [ 0x04, 0x28 ], 11 | [ 0x13, 0xe5 ], 12 | [ 0x14, 0x48 ], 13 | [ 0x2c, 0x0c ], 14 | [ 0x33, 0x78 ], 15 | [ 0x3a, 0x33 ], 16 | [ 0x3b, 0xfB ], 17 | [ 0x3e, 0x00 ], 18 | [ 0x43, 0x11 ], 19 | [ 0x16, 0x10 ], 20 | [ 0x39, 0x92 ], 21 | [ 0x35, 0xda ], 22 | [ 0x22, 0x1a ], 23 | [ 0x37, 0xc3 ], 24 | [ 0x23, 0x00 ], 25 | [ 0x34, 0xc0 ], 26 | [ 0x36, 0x1a ], 27 | [ 0x06, 0x88 ], 28 | [ 0x07, 0xc0 ], 29 | [ 0x0d, 0x87 ], 30 | [ 0x0e, 0x41 ], 31 | [ 0x4c, 0x00 ], 32 | [ 0x48, 0x00 ], 33 | [ 0x5B, 0x00 ], 34 | [ 0x42, 0x03 ], 35 | [ 0x4a, 0x81 ], 36 | [ 0x21, 0x99 ], 37 | [ 0x24, 0x40 ], 38 | [ 0x25, 0x38 ], 39 | [ 0x26, 0x82 ], 40 | [ 0x5c, 0x00 ], 41 | [ 0x63, 0x00 ], 42 | [ 0x61, 0x70 ], 43 | [ 0x62, 0x80 ], 44 | [ 0x7c, 0x05 ], 45 | [ 0x20, 0x80 ], 46 | [ 0x28, 0x30 ], 47 | [ 0x6c, 0x00 ], 48 | [ 0x6d, 0x80 ], 49 | [ 0x6e, 0x00 ], 50 | [ 0x70, 0x02 ], 51 | [ 0x71, 0x94 ], 52 | [ 0x73, 0xc1 ], 53 | [ 0x12, 0x40 ], 54 | [ 0x17, 0x11 ], 55 | [ 0x18, 0x43 ], 56 | [ 0x19, 0x00 ], 57 | [ 0x1a, 0x4b ], 58 | [ 0x32, 0x09 ], 59 | [ 0x37, 0xc0 ], 60 | [ 0x4f, 0x60 ], 61 | [ 0x50, 0xa8 ], 62 | [ 0x6d, 0x00 ], 63 | [ 0x3d, 0x38 ], 64 | [ 0x46, 0x3f ], 65 | [ 0x4f, 0x60 ], 66 | [ 0x0c, 0x3c ], 67 | [ 0xff, 0x00 ], 68 | [ 0xe5, 0x7f ], 69 | [ 0xf9, 0xc0 ], 70 | [ 0x41, 0x24 ], 71 | [ 0xe0, 0x14 ], 72 | [ 0x76, 0xff ], 73 | [ 0x33, 0xa0 ], 74 | [ 0x42, 0x20 ], 75 | [ 0x43, 0x18 ], 76 | [ 0x4c, 0x00 ], 77 | [ 0x87, 0xd5 ], 78 | [ 0x88, 0x3f ], 79 | [ 0xd7, 0x03 ], 80 | [ 0xd9, 0x10 ], 81 | [ 0xd3, 0x82 ], 82 | [ 0xc8, 0x08 ], 83 | [ 0xc9, 0x80 ], 84 | [ 0x7c, 0x00 ], 85 | [ 0x7d, 0x00 ], 86 | [ 0x7c, 0x03 ], 87 | [ 0x7d, 0x48 ], 88 | [ 0x7d, 0x48 ], 89 | [ 0x7c, 0x08 ], 90 | [ 0x7d, 0x20 ], 91 | [ 0x7d, 0x10 ], 92 | [ 0x7d, 0x0e ], 93 | [ 0x90, 0x00 ], 94 | [ 0x91, 0x0e ], 95 | [ 0x91, 0x1a ], 96 | [ 0x91, 0x31 ], 97 | [ 0x91, 0x5a ], 98 | [ 0x91, 0x69 ], 99 | [ 0x91, 0x75 ], 100 | [ 0x91, 0x7e ], 101 | [ 0x91, 0x88 ], 102 | [ 0x91, 0x8f ], 103 | [ 0x91, 0x96 ], 104 | [ 0x91, 0xa3 ], 105 | [ 0x91, 0xaf ], 106 | [ 0x91, 0xc4 ], 107 | [ 0x91, 0xd7 ], 108 | [ 0x91, 0xe8 ], 109 | [ 0x91, 0x20 ], 110 | [ 0x92, 0x00 ], 111 | [ 0x93, 0x06 ], 112 | [ 0x93, 0xe3 ], 113 | [ 0x93, 0x05 ], 114 | [ 0x93, 0x05 ], 115 | [ 0x93, 0x00 ], 116 | [ 0x93, 0x04 ], 117 | [ 0x93, 0x00 ], 118 | [ 0x93, 0x00 ], 119 | [ 0x93, 0x00 ], 120 | [ 0x93, 0x00 ], 121 | [ 0x93, 0x00 ], 122 | [ 0x93, 0x00 ], 123 | [ 0x93, 0x00 ], 124 | [ 0x96, 0x00 ], 125 | [ 0x97, 0x08 ], 126 | [ 0x97, 0x19 ], 127 | [ 0x97, 0x02 ], 128 | [ 0x97, 0x0c ], 129 | [ 0x97, 0x24 ], 130 | [ 0x97, 0x30 ], 131 | [ 0x97, 0x28 ], 132 | [ 0x97, 0x26 ], 133 | [ 0x97, 0x02 ], 134 | [ 0x97, 0x98 ], 135 | [ 0x97, 0x80 ], 136 | [ 0x97, 0x00 ], 137 | [ 0x97, 0x00 ], 138 | [ 0xc3, 0xed ], 139 | [ 0xa4, 0x00 ], 140 | [ 0xa8, 0x00 ], 141 | [ 0xc5, 0x11 ], 142 | [ 0xc6, 0x51 ], 143 | [ 0xbf, 0x80 ], 144 | [ 0xc7, 0x10 ], 145 | [ 0xb6, 0x66 ], 146 | [ 0xb8, 0xA5 ], 147 | [ 0xb7, 0x64 ], 148 | [ 0xb9, 0x7C ], 149 | [ 0xb3, 0xaf ], 150 | [ 0xb4, 0x97 ], 151 | [ 0xb5, 0xFF ], 152 | [ 0xb0, 0xC5 ], 153 | [ 0xb1, 0x94 ], 154 | [ 0xb2, 0x0f ], 155 | [ 0xc4, 0x5c ], 156 | [ 0xc0, 0x64 ], 157 | [ 0xc1, 0x4B ], 158 | [ 0x8c, 0x00 ], 159 | [ 0x86, 0x3D ], 160 | [ 0x50, 0x00 ], 161 | [ 0x51, 0xC8 ], 162 | [ 0x52, 0x96 ], 163 | [ 0x53, 0x00 ], 164 | [ 0x54, 0x00 ], 165 | [ 0x55, 0x00 ], 166 | [ 0x5a, 0xC8 ], 167 | [ 0x5b, 0x96 ], 168 | [ 0x5c, 0x00 ], 169 | [ 0xd3, 0x00 ], 170 | [ 0xc3, 0xed ], 171 | [ 0x7f, 0x00 ], 172 | [ 0xda, 0x00 ], 173 | [ 0xe5, 0x1f ], 174 | [ 0xe1, 0x67 ], 175 | [ 0xe0, 0x00 ], 176 | [ 0xdd, 0x7f ], 177 | [ 0x05, 0x00 ], 178 | [ 0x12, 0x40 ], 179 | [ 0xd3, 0x04 ], 180 | [ 0xc0, 0x16 ], 181 | [ 0xC1, 0x12 ], 182 | [ 0x8c, 0x00 ], 183 | [ 0x86, 0x3d ], 184 | [ 0x50, 0x00 ], 185 | [ 0x51, 0x2C ], 186 | [ 0x52, 0x24 ], 187 | [ 0x53, 0x00 ], 188 | [ 0x54, 0x00 ], 189 | [ 0x55, 0x00 ], 190 | [ 0x5A, 0x2c ], 191 | [ 0x5b, 0x24 ], 192 | [ 0x5c, 0x00 ], 193 | [ 0xff, 0xff ], 194 | ] 195 | 196 | OV2640_YUV422 = [ 197 | [ 0xFF, 0x00 ], 198 | [ 0x05, 0x00 ], 199 | [ 0xDA, 0x10 ], 200 | [ 0xD7, 0x03 ], 201 | [ 0xDF, 0x00 ], 202 | [ 0x33, 0x80 ], 203 | [ 0x3C, 0x40 ], 204 | [ 0xe1, 0x77 ], 205 | [ 0x00, 0x00 ], 206 | [ 0xff, 0xff ], 207 | ] 208 | 209 | OV2640_JPEG = [ 210 | [ 0xe0, 0x14 ], 211 | [ 0xe1, 0x77 ], 212 | [ 0xe5, 0x1f ], 213 | [ 0xd7, 0x03 ], 214 | [ 0xda, 0x10 ], 215 | [ 0xe0, 0x00 ], 216 | [ 0xFF, 0x01 ], 217 | [ 0x04, 0x08 ], 218 | [ 0xff, 0xff ], 219 | ] 220 | 221 | SENSORADDR = 0x30 222 | PICBUFSIZE = 64 223 | -------------------------------------------------------------------------------- /ov2640_hires_constants.py: -------------------------------------------------------------------------------- 1 | 2 | # 800x600 removed to save memory 3 | 4 | OV2640_1024x768_JPEG = [ 5 | [0xff, 0x01], 6 | [0x11, 0x01], 7 | [0x12, 0x00], 8 | [0x17, 0x11], 9 | [0x18, 0x75], 10 | [0x32, 0x36], 11 | [0x19, 0x01], 12 | [0x1a, 0x97], 13 | [0x03, 0x0f], 14 | [0x37, 0x40], 15 | [0x4f, 0xbb], 16 | [0x50, 0x9c], 17 | [0x5a, 0x57], 18 | [0x6d, 0x80], 19 | [0x3d, 0x34], 20 | [0x39, 0x02], 21 | [0x35, 0x88], 22 | [0x22, 0x0a], 23 | [0x37, 0x40], 24 | [0x34, 0xa0], 25 | [0x06, 0x02], 26 | [0x0d, 0xb7], 27 | [0x0e, 0x01], 28 | [0xff, 0x00], 29 | [0xc0, 0xC8], 30 | [0xc1, 0x96], 31 | [0x8c, 0x00], 32 | [0x86, 0x3D], 33 | [0x50, 0x00], 34 | [0x51, 0x90], 35 | [0x52, 0x2C], 36 | [0x53, 0x00], 37 | [0x54, 0x00], 38 | [0x55, 0x88], 39 | [0x5a, 0x00], 40 | [0x5b, 0xC0], 41 | [0x5c, 0x01], 42 | [0xd3, 0x02], 43 | [0xff, 0xff], 44 | ] 45 | 46 | OV2640_1280x1024_JPEG = [ 47 | [0xff, 0x01], 48 | [0x11, 0x01], 49 | [0x12, 0x00], 50 | [0x17, 0x11], 51 | [0x18, 0x75], 52 | [0x32, 0x36], 53 | [0x19, 0x01], 54 | [0x1a, 0x97], 55 | [0x03, 0x0f], 56 | [0x37, 0x40], 57 | [0x4f, 0xbb], 58 | [0x50, 0x9c], 59 | [0x5a, 0x57], 60 | [0x6d, 0x80], 61 | [0x3d, 0x34], 62 | [0x39, 0x02], 63 | [0x35, 0x88], 64 | [0x22, 0x0a], 65 | [0x37, 0x40], 66 | [0x34, 0xa0], 67 | [0x06, 0x02], 68 | [0x0d, 0xb7], 69 | [0x0e, 0x01], 70 | [0xff, 0x00], 71 | [0xe0, 0x04], 72 | [0xc0, 0xc8], 73 | [0xc1, 0x96], 74 | [0x86, 0x3d], 75 | [0x50, 0x00], 76 | [0x51, 0x90], 77 | [0x52, 0x2c], 78 | [0x53, 0x00], 79 | [0x54, 0x00], 80 | [0x55, 0x88], 81 | [0x57, 0x00], 82 | [0x5a, 0x40], 83 | [0x5b, 0xf0], 84 | [0x5c, 0x01], 85 | [0xd3, 0x02], 86 | [0xe0, 0x00], 87 | [0xff, 0xff], 88 | ] 89 | 90 | OV2640_1600x1200_JPEG = [ 91 | [0xff, 0x01], 92 | [0x11, 0x01], 93 | [0x12, 0x00], 94 | [0x17, 0x11], 95 | [0x18, 0x75], 96 | [0x32, 0x36], 97 | [0x19, 0x01], 98 | [0x1a, 0x97], 99 | [0x03, 0x0f], 100 | [0x37, 0x40], 101 | [0x4f, 0xbb], 102 | [0x50, 0x9c], 103 | [0x5a, 0x57], 104 | [0x6d, 0x80], 105 | [0x3d, 0x34], 106 | [0x39, 0x02], 107 | [0x35, 0x88], 108 | [0x22, 0x0a], 109 | [0x37, 0x40], 110 | [0x34, 0xa0], 111 | [0x06, 0x02], 112 | [0x0d, 0xb7], 113 | [0x0e, 0x01], 114 | [0xff, 0x00], 115 | [0xe0, 0x04], 116 | [0xc0, 0xc8], 117 | [0xc1, 0x96], 118 | [0x86, 0x3d], 119 | [0x50, 0x00], 120 | [0x51, 0x90], 121 | [0x52, 0x2c], 122 | [0x53, 0x00], 123 | [0x54, 0x00], 124 | [0x55, 0x88], 125 | [0x57, 0x00], 126 | [0x5a, 0x90], 127 | [0x5b, 0x2C], 128 | [0x5c, 0x05], 129 | [0xd3, 0x02], 130 | [0xe0, 0x00], 131 | [0xff, 0xff], 132 | ] 133 | -------------------------------------------------------------------------------- /ov2640_lores_constants.py: -------------------------------------------------------------------------------- 1 | # 160x120, 176x144 removed to save memory 2 | 3 | OV2640_320x240_JPEG = [ 4 | [ 0xff, 0x01 ], 5 | [ 0x12, 0x40 ], 6 | [ 0x17, 0x11 ], 7 | [ 0x18, 0x43 ], 8 | [ 0x19, 0x00 ], 9 | [ 0x1a, 0x4b ], 10 | [ 0x32, 0x09 ], 11 | [ 0x4f, 0xca ], 12 | [ 0x50, 0xa8 ], 13 | [ 0x5a, 0x23 ], 14 | [ 0x6d, 0x00 ], 15 | [ 0x39, 0x12 ], 16 | [ 0x35, 0xda ], 17 | [ 0x22, 0x1a ], 18 | [ 0x37, 0xc3 ], 19 | [ 0x23, 0x00 ], 20 | [ 0x34, 0xc0 ], 21 | [ 0x36, 0x1a ], 22 | [ 0x06, 0x88 ], 23 | [ 0x07, 0xc0 ], 24 | [ 0x0d, 0x87 ], 25 | [ 0x0e, 0x41 ], 26 | [ 0x4c, 0x00 ], 27 | [ 0xff, 0x00 ], 28 | [ 0xe0, 0x04 ], 29 | [ 0xc0, 0x64 ], 30 | [ 0xc1, 0x4b ], 31 | [ 0x86, 0x35 ], 32 | [ 0x50, 0x89 ], 33 | [ 0x51, 0xc8 ], 34 | [ 0x52, 0x96 ], 35 | [ 0x53, 0x00 ], 36 | [ 0x54, 0x00 ], 37 | [ 0x55, 0x00 ], 38 | [ 0x57, 0x00 ], 39 | [ 0x5a, 0x50 ], 40 | [ 0x5b, 0x3c ], 41 | [ 0x5c, 0x00 ], 42 | [ 0xe0, 0x00 ], 43 | [ 0xff, 0xff ], 44 | ] 45 | 46 | OV2640_352x288_JPEG = [ 47 | [ 0xff, 0x01 ], 48 | [ 0x12, 0x40 ], 49 | [ 0x17, 0x11 ], 50 | [ 0x18, 0x43 ], 51 | [ 0x19, 0x00 ], 52 | [ 0x1a, 0x4b ], 53 | [ 0x32, 0x09 ], 54 | [ 0x4f, 0xca ], 55 | [ 0x50, 0xa8 ], 56 | [ 0x5a, 0x23 ], 57 | [ 0x6d, 0x00 ], 58 | [ 0x39, 0x12 ], 59 | [ 0x35, 0xda ], 60 | [ 0x22, 0x1a ], 61 | [ 0x37, 0xc3 ], 62 | [ 0x23, 0x00 ], 63 | [ 0x34, 0xc0 ], 64 | [ 0x36, 0x1a ], 65 | [ 0x06, 0x88 ], 66 | [ 0x07, 0xc0 ], 67 | [ 0x0d, 0x87 ], 68 | [ 0x0e, 0x41 ], 69 | [ 0x4c, 0x00 ], 70 | [ 0xff, 0x00 ], 71 | [ 0xe0, 0x04 ], 72 | [ 0xc0, 0x64 ], 73 | [ 0xc1, 0x4b ], 74 | [ 0x86, 0x35 ], 75 | [ 0x50, 0x89 ], 76 | [ 0x51, 0xc8 ], 77 | [ 0x52, 0x96 ], 78 | [ 0x53, 0x00 ], 79 | [ 0x54, 0x00 ], 80 | [ 0x55, 0x00 ], 81 | [ 0x57, 0x00 ], 82 | [ 0x5a, 0x58 ], 83 | [ 0x5b, 0x48 ], 84 | [ 0x5c, 0x00 ], 85 | [ 0xe0, 0x00 ], 86 | [ 0xff, 0xff ], 87 | ] 88 | 89 | OV2640_640x480_JPEG = [ 90 | [0xff, 0x01], 91 | [0x11, 0x01], 92 | [0x12, 0x00], 93 | [0x17, 0x11], 94 | [0x18, 0x75], 95 | [0x32, 0x36], 96 | [0x19, 0x01], 97 | [0x1a, 0x97], 98 | [0x03, 0x0f], 99 | [0x37, 0x40], 100 | [0x4f, 0xbb], 101 | [0x50, 0x9c], 102 | [0x5a, 0x57], 103 | [0x6d, 0x80], 104 | [0x3d, 0x34], 105 | [0x39, 0x02], 106 | [0x35, 0x88], 107 | [0x22, 0x0a], 108 | [0x37, 0x40], 109 | [0x34, 0xa0], 110 | [0x06, 0x02], 111 | [0x0d, 0xb7], 112 | [0x0e, 0x01], 113 | [0xff, 0x00], 114 | [0xe0, 0x04], 115 | [0xc0, 0xc8], 116 | [0xc1, 0x96], 117 | [0x86, 0x3d], 118 | [0x50, 0x89], 119 | [0x51, 0x90], 120 | [0x52, 0x2c], 121 | [0x53, 0x00], 122 | [0x54, 0x00], 123 | [0x55, 0x88], 124 | [0x57, 0x00], 125 | [0x5a, 0xa0], 126 | [0x5b, 0x78], 127 | [0x5c, 0x00], 128 | [0xd3, 0x04], 129 | [0xe0, 0x00], 130 | [0xff, 0xff], 131 | ] 132 | 133 | --------------------------------------------------------------------------------