I got it working on with the SD card...I think there is a problem with python code given in the examples.
Thanks!
Moderators: adafruit_support_bill, adafruit
reset()
[b]time.sleep(2)[/b]
if (not getversion()): while (addr < bytes + 32):
command = readphotocommand + [(addr >> 24) & 0xFF, (addr >> 16) & 0xFF,
(addr >> 8) & 0xFF, addr & 0xFF]
command += [0, 0, 0, 32] # 32 bytes at a time
command += [2,0] # delay of 20ms (was 10 ms) <<<<<<<<<<<<<<<<<<<<<<
#print map(hex, command)
cmd = ''.join(map (chr, command))# python code for interfacing to VC0706 cameras and grabbing a photo
# pretty basic stuff
# written by ladyada. banned license
import serial
import time
BAUD = 38400
PORT = "/dev/ttyACM0"
TIMEOUT = 0.2
SERIALNUM = 0 # start with 0
COMMANDSEND = 0x56
COMMANDREPLY = 0x76
COMMANDEND = 0x00
CMD_GETVERSION = 0x11
CMD_RESET = 0x26
CMD_TAKEPHOTO = 0x36
CMD_READBUFF = 0x32
CMD_GETBUFFLEN = 0x34
FBUF_CURRENTFRAME = 0x00
FBUF_NEXTFRAME = 0x01
FBUF_STOPCURRENTFRAME = 0x00
getversioncommand = [COMMANDSEND, SERIALNUM, CMD_GETVERSION, COMMANDEND]
resetcommand = [COMMANDSEND, SERIALNUM, CMD_RESET, COMMANDEND]
takephotocommand = [COMMANDSEND, SERIALNUM, CMD_TAKEPHOTO, 0x01, FBUF_STOPCURRENTFRAME]
getbufflencommand = [COMMANDSEND, SERIALNUM, CMD_GETBUFFLEN, 0x01, FBUF_CURRENTFRAME]
def checkreply(r, b):
r = map (ord, r)
#print 'checkreply: completed map, len=', len(r)
#print 'r =', r
if (r[0] == 0x76 and r[1] == SERIALNUM and r[2] == b and r[3] == 0x00):
return True
print 'checkReply() failed'
return False
def reset():
cmd = ''.join (map (chr, resetcommand))
s.write(cmd)
reply = s.read(100)
r = list(reply)
if checkreply(r, CMD_RESET):
return True
print 'reset(): failure'
return False
def getversion():
cmd = ''.join (map (chr, getversioncommand))
s.write(cmd)
reply = s.read(16)
r = list(reply);
if checkreply(r, CMD_GETVERSION):
return True
return False
def takephoto():
cmd = ''.join (map (chr, takephotocommand))
s.write(cmd)
reply = s.read(5)
r = list(reply);
if (checkreply(r, CMD_TAKEPHOTO) and r[3] == chr(0x0)):
return True
return False
def getbufferlength():
cmd = ''.join (map (chr, getbufflencommand))
s.write(cmd)
reply = s.read(9)
r = list(reply);
if (checkreply(r, CMD_GETBUFFLEN) and r[4] == chr(0x4)):
l = ord(r[5])
l <<= 8
l += ord(r[6])
l <<= 8
l += ord(r[7])
l <<= 8
l += ord(r[8])
return l
return 0
readphotocommand = [COMMANDSEND, SERIALNUM, CMD_READBUFF, 0x0c, FBUF_CURRENTFRAME, 0x0a]
def readbuffer(bytes):
addr = 0
photo = []
while (addr < bytes + 32):
command = readphotocommand + [(addr >> 24) & 0xFF, (addr >> 16) & 0xFF,
(addr >> 8) & 0xFF, addr & 0xFF]
command += [0, 0, 0, 32] # 32 bytes at a time
command += [2,0] # delay of 20ms (was 10 ms)
#print map(hex, command)
cmd = ''.join(map (chr, command))
s.write(cmd)
reply = s.read(32+5)
r = list(reply)
if (len(r) != 37):
continue
#print r
if (not checkreply(r, CMD_READBUFF)):
print "ERROR READING PHOTO"
return
photo += r[5:]
addr += 32
return photo
######## main
s = serial.Serial(PORT, baudrate=BAUD, timeout=TIMEOUT)
reset()
time.sleep(2)
if (not getversion()):
print "Camera not found"
exit
print "VC0706 Camera found"
if takephoto():
print "Snap!"
bytes2read = getbufferlength()
print bytes2read, "bytes to read"
photo = readbuffer(bytes2read)
f = open("photo.jpg", 'w')
photodata = ''.join(photo)
f.write(photodata)
f.close()
#print length(photo)
PORT = "/dev/ttyACM0"
def checkreply(r, b):
r = map (ord, r)
#print 'checkreply: completed map, len=', len(r)
#print 'r =', r
if (r[0] == 0x76 and r[1] == SERIALNUM and r[2] == b and r[3] == 0x00):
return True
print 'checkReply(): failed, r=', r
return False
read(size=1)
Parameters:
size – Number of bytes to read.
Returns:
Bytes read from the port.
Read size bytes from the serial port. If a timeout is set it may return less characters as requested. With no timeout it will block until the requested number of bytes is read.
Changed in version 2.5: Returns an instance of bytes when available (Python 2.6 and newer) and str otherwise.
"if (r[0] == 0x76 and r[1] == SERIALNUM and r[2] == b and r[3] == 0x00):IndexError: list index out of range"
reset()
time.sleep(2) # added this line which 'fixed' the list index out of range.
if (not getversion()):
print "Camera not found"
exit
print "VC0706 Camera found"
['v', '\x00', '2', '\x00', '\x00', 'v', '\x00', '2', '\x00', '\x00', '\x12', '\x0b', 'Q', '\x04', 'Q', '\x04', '\x00', '\x00', '\xff', '\xdb', '\x00', '\x84', '\x00', '\x05', '\x03', '\x04', '\x04', '\x04', '\x03', '\x05', '\x04', '\x04', '\x04', '\x06', '\x05', '\x05', '\x06']
['\x08', '\r', '\x08', '\x08', '\x07', 'v', '\x00', '2', '\x00', '\x00', 'v', '\x00', '2', '\x00', '\x00', '\x07', '\x08', '\x0f', '\x0b', '\x0c', '\t', '\r', '\x12', '\x10', '\x13', '\x13', '\x12', '\x10', '\x12', '\x11', '\x14', '\x17', '\x1d', '\x18', '\x14', '\x15', '\x1b']
1.3.2.7.READ_FBUF
Command function :read image data from FBUF.
Command format :0x56+serial number+0x32+0x0C+FBUF type(1 byte)+control mode(1 byte)
+starting address(4 bytes)+data-length(4 bytes)+delay(2 bytes)
FBUF type:current frame or next frame
0:current frame
1:next frame
Control mode:the mode by which image data transfer
Bit0:0:data transfer by MCU mode
1:data transfer by DMA mode
Bit[2:1]:2'b11
Bit3: 1'b11
Starting address: the address in fbuf to store the image data.
Data-length:the byte number ready to read, it must be the multiple of 4.
Delay:the delay time between command and data, the unit is 0.01 millisecond.
def readbuffer(bytes):
addr = 0
photo = []
while (addr < bytes + 32):
command = readphotocommand + [(addr >> 24) & 0xFF, (addr >> 16) & 0xFF,
(addr >>& 0xFF, addr & 0xFF]
command += [0, 0, 0, 32] # 32 bytes at a time
command += [1,0] # delay of 10ms
command += [0x10,0] # delay of 40.96 ms)
def readbuffer(bytes):
addr = 0
photo = []
while (addr < bytes + 32):
command = readphotocommand + [(addr >> 24) & 0xFF, (addr >> 16) & 0xFF,
(addr >> 8) & 0xFF, addr & 0xFF]
command += [0, 0, 0, 32] # 32 bytes at a time
command += [0x10,0] # delay of 40.96 ms (was 10 ms)
# print 'cmd=', map(hex, command)
cmd = ''.join(map (chr, command))
s.write(cmd)
reply = s.read(32+5)
r = list(reply)
# print r
if (len(r) != 37):
# print 'Receive count error'
# print 'Command sent was: ', cmd
# print 'r is:', r
continue
if (not checkreply(r, CMD_READBUFF)):
print "ERROR READING PHOTO"
exit()
photo += r[5:]
addr += 32
print 'photo en=', len(photo)
return photoREADSIZE = 2048
def readbuffer(bytes):
addr = 0
photo = []
while (addr < bytes + READSIZE):
command = readphotocommand + [(addr >> 24) & 0xFF, (addr >> 16) & 0xFF,
(addr >> 8) & 0xFF, addr & 0xFF]
command += [0, 0, (READSIZE>>8) & 0xFF, READSIZE & 0xFF] # READSIZE bytes at a time
command += [0x10,0] # delay of 40.96 ms (was 10 ms)
# print 'cmd=', map(hex, command)
cmd = ''.join(map (chr, command))
s.write(cmd)
reply = s.read(READSIZE + 5)
r = list(reply)
# print r
if (len(r) != READSIZE + 5):
# print 'Receive count error'
# print 'Command sent was: ', cmd
# print 'r is:', r
continue
if (not checkreply(r, CMD_READBUFF)):
print "ERROR READING PHOTO"
exit()
photo += r[5:]
addr += READSIZE
print 'photo len=', len(photo)
return photo
Users browsing this forum: No registered users and 9 guests