Skip to content

Commit c471ce1

Browse files
committed
Initial commit.
0 parents  commit c471ce1

9 files changed

+560
-0
lines changed

CODE_OF_CONDUCT.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [http://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: http://contributor-covenant.org
74+
[version]: http://contributor-covenant.org/version/1/4/

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Tony DiCola for Adafruit Industries
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.

README.rst

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
Introduction
3+
============
4+
5+
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-vc0706/badge/?version=latest
6+
:target: https://circuitpython.readthedocs.io/projects/vc0706/en/latest/
7+
:alt: Documentation Status
8+
9+
.. image :: https://img.shields.io/discord/327254708534116352.svg
10+
:target: https://discord.gg/nBQh6qu
11+
:alt: Discord
12+
13+
VC0706 serial TTL camera module. Allows basic image capture and download of
14+
image data from the camera over a serial connection. See examples for demo
15+
of saving image to a SD card (must be wired up separately).
16+
17+
Dependencies
18+
=============
19+
This driver depends on:
20+
21+
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
22+
23+
Please ensure all dependencies are available on the CircuitPython filesystem.
24+
This is easily achieved by downloading
25+
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
26+
27+
Usage Example
28+
=============
29+
30+
See examples/snapshot.py.
31+
32+
Contributing
33+
============
34+
35+
Contributions are welcome! Please read our `Code of Conduct
36+
<https://github.com/adafruit/Adafruit_CircuitPython_vc0706/blob/master/CODE_OF_CONDUCT.md>`_
37+
before contributing to help this project stay welcoming.
38+
39+
API Reference
40+
=============
41+
42+
.. toctree::
43+
:maxdepth: 2
44+
45+
api

adafruit_vc0706.py

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2017 Tony DiCola for Adafruit Industries
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
13+
# all 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
21+
# THE SOFTWARE.
22+
"""
23+
`adafruit_vc0706`
24+
====================================================
25+
26+
VC0706 serial TTL camera module. Allows basic image capture and download of
27+
image data from the camera over a serial connection. See examples for demo
28+
of saving image to a SD card (must be wired up separately).
29+
30+
* Author(s): Tony DiCola
31+
"""
32+
import busio
33+
34+
35+
_VC0706_SERIAL = const(0x00)
36+
_VC0706_RESET = const(0x26)
37+
_VC0706_GEN_VERSION = const(0x11)
38+
_VC0706_SET_PORT = const(0x24)
39+
_VC0706_READ_FBUF = const(0x32)
40+
_VC0706_GET_FBUF_LEN = const(0x34)
41+
_VC0706_FBUF_CTRL = const(0x36)
42+
_VC0706_DOWNSIZE_CTRL = const(0x54)
43+
_VC0706_DOWNSIZE_STATUS = const(0x55)
44+
_VC0706_READ_DATA = const(0x30)
45+
_VC0706_WRITE_DATA = const(0x31)
46+
_VC0706_COMM_MOTION_CTRL = const(0x37)
47+
_VC0706_COMM_MOTION_STATUS = const(0x38)
48+
_VC0706_COMM_MOTION_DETECTED = const(0x39)
49+
_VC0706_MOTION_CTRL = const(0x42)
50+
_VC0706_MOTION_STATUS = const(0x43)
51+
_VC0706_TVOUT_CTRL = const(0x44)
52+
_VC0706_OSD_ADD_CHAR = const(0x45)
53+
54+
_VC0706_STOPCURRENTFRAME = const(0x0)
55+
_VC0706_STOPNEXTFRAME = const(0x1)
56+
_VC0706_RESUMEFRAME = const(0x3)
57+
_VC0706_STEPFRAME = const(0x2)
58+
59+
VC0706_640x480 = const(0x00)
60+
VC0706_320x240 = const(0x11)
61+
VC0706_160x120 = const(0x22)
62+
63+
VC0706_MOTIONCONTROL = const(0x0)
64+
VC0706_UARTMOTION = const(0x01)
65+
VC0706_ACTIVATEMOTION = const(0x01)
66+
67+
VC0706_SET_ZOOM = const(0x52)
68+
VC0706_GET_ZOOM = const(0x53)
69+
70+
_CAMERA_DELAY = const(10)
71+
72+
73+
class VC0706:
74+
75+
_COMMAND_HEADER = bytearray(3)
76+
77+
def __init__(self, rx, tx, baudrate=38400, timeout=250, buffer_size=100):
78+
self._uart = busio.UART(tx, rx, baudrate=baudrate, timeout=timeout)
79+
self._buffer = bytearray(buffer_size)
80+
self._frame_ptr = 0
81+
if not self._run_command(_VC0706_RESET, bytes([0x00]), 5):
82+
raise RuntimeError('Failed to get response from VC0706, check wiring!')
83+
84+
@property
85+
def version(self):
86+
"""Return camera version byte string."""
87+
# Clear buffer to ensure the end of a string can be found.
88+
self._send_command(_VC0706_GEN_VERSION, bytes([0x01]))
89+
readlen = self._read_response(self._buffer, len(self._buffer))
90+
return str(self._buffer[:readlen], 'ascii')
91+
92+
@property
93+
def image_size(self):
94+
"""Get the current image size, will return a value of VC0706_640x480,
95+
VC0706_320x240, or VC0706_160x120.
96+
"""
97+
if not self._run_command(_VC0706_READ_DATA, bytes([0x4, 0x4, 0x1, 0x00,
98+
0x19]), 6):
99+
raise RuntimeError('Failed to read image size!')
100+
return self._buffer[5]
101+
102+
@image_size.setter
103+
def image_size(self, size):
104+
"""Set the image size to a value of VC0706_640x480, VC0706_320x240, or
105+
VC0706_160x120.
106+
"""
107+
if size not in (VC0706_640x480, VC0706_320x240, VC0706_160x120):
108+
raise ValueError('Size must be one of VC0706_640x480, VC0706_320x240, or VC0706_160x120!')
109+
return self._run_command(_VC0706_WRITE_DATA, bytes([0x05, 0x04, 0x01,
110+
0x00, 0x19, size & 0xFF]), 5)
111+
112+
@property
113+
def frame_length(self):
114+
"""Return the length in bytes of the currently capture frame/picture.
115+
"""
116+
if not self._run_command(_VC0706_GET_FBUF_LEN, bytes([0x01, 0x00]), 9):
117+
return 0
118+
frame_length = self._buffer[5]
119+
frame_length <<= 8
120+
frame_length |= self._buffer[6]
121+
frame_length <<= 8
122+
frame_length |= self._buffer[7]
123+
frame_length <<= 8
124+
frame_length |= self._buffer[8]
125+
return frame_length
126+
127+
def take_picture(self):
128+
"""Tell the camera to take a picture. Returns True if successful.
129+
"""
130+
self._frame_ptr = 0
131+
return self._run_command(_VC0706_FBUF_CTRL, bytes([0x1,
132+
_VC0706_STOPCURRENTFRAME]), 5)
133+
134+
def read_picture_into(self, buf):
135+
"""Read the next bytes of frame/picture data into the provided buffer.
136+
Returns the number of bytes written to the buffer (might be less than
137+
the size of the buffer). Buffer MUST be a multiple of 4 and 100 or
138+
less. Suggested buffer size is 32.
139+
"""
140+
n = len(buf)
141+
if n > 256 or n > (len(self._buffer)-5):
142+
raise ValueError('Buffer is too large!')
143+
if n % 4 != 0:
144+
raise ValueError('Buffer must be a multiple of 4! Try 32.')
145+
args = bytes([0x0C, 0x0, 0x0A, 0, 0, (self._frame_ptr >> 8) & 0xFF,
146+
self._frame_ptr & 0xFF, 0, 0, 0, n & 0xFF,
147+
(_CAMERA_DELAY >> 8) & 0xFF, _CAMERA_DELAY & 0xFF])
148+
if not self._run_command(_VC0706_READ_FBUF, args, 5):
149+
return 0
150+
if self._read_response(self._buffer, n+5) == 0:
151+
return 0
152+
self._frame_ptr += n
153+
for i in range(n):
154+
buf[i] = self._buffer[i]
155+
return n
156+
157+
def _run_command(self, cmd, args, resplen, flush=True):
158+
if flush:
159+
self._read_response(self._buffer, len(self._buffer))
160+
self._send_command(cmd, args)
161+
if self._read_response(self._buffer, resplen) != resplen:
162+
return False
163+
if not self._verify_response(cmd):
164+
return False
165+
return True
166+
167+
def _read_response(self, result, numbytes):
168+
return self._uart.readinto(result, numbytes)
169+
170+
def _verify_response(self, cmd):
171+
return self._buffer[0] == 0x76 and self._buffer[1] == _VC0706_SERIAL \
172+
and self._buffer[2] == cmd & 0xFF and self._buffer[3] == 0x00
173+
174+
def _send_command(self, cmd, args=None):
175+
self._COMMAND_HEADER[0] = 0x56
176+
self._COMMAND_HEADER[1] = _VC0706_SERIAL
177+
self._COMMAND_HEADER[2] = cmd & 0xFF
178+
self._uart.write(self._COMMAND_HEADER)
179+
if args is not None and len(args) > 0:
180+
self._uart.write(args)

api.rst

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
.. If you created a package, create one automodule per module in the package.
3+
4+
.. automodule:: adafruit_vc0706
5+
:members:

0 commit comments

Comments
 (0)