• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeJPEG CameraTaking Pictures with a pcDuino & a LinkSprite ...
Previous Next

Taking Pictures with a pcDuino & a LinkSprite JPEG Color Camera (TTL Interface)

Posted by: admin , November 17, 2013

[vc_row][vc_column width=”1/1″][vc_column_text]The original post can be found at: http://bradsmc.blogspot.com/2013/05/taking-pictures-with-pcduino-linksprite.html?m=1

Here is a very basic example showing how to use the LinkSprite JPEG Color Camera (TTL Interface) from Sparkfun with a pcDuino.

The user manual for the camera is available here.

Note (May 24, 2013): I have also gotten a TTL Serial JPEG Camera with NTSC Video from Adafruit. It is the same camera as the Linksprite Sparkfun (with some mnor differences in the board and the connector).  The material presented below also works with the Adafruit camera. Adafruit Learning systems has a tutorial on using the camera with an Arduino and a utility for testing the camera.  They also have code on their GitHub site that includes some python examples apparently intended for the Raspberry Pi.

10061-01c

Connections

The labels for the connections on the camera board are just above the connector.
Camera pcDuino
TV     Not Connected
RXD    Digital Pin 1 (TX)
TXD    Digital Pin 0 (RX)
GND    GND
VCC    5V
Note: If you have problems with getting serial I/O to work on the pcDuino’s 0 and 1 pins, try the setuart2 utility discussed in the pcDuino forum.

Python Code

The following code is designed to be run from the command line on the pcDuino. It just takes a picture and saves it to a file in the /tmp/ directory. The file name is made up of the current date and time (down to seconds).

import serial
import time
import datetime

# Initialize camera
serial = serial.Serial(“/dev/ttyS1”, baudrate=38400)
serial.write(b’\x56\0\x26\0′)
resp = “”
time.sleep(1)
while (serial.inWaiting() > 0):
data = serial.read()
resp += data
if “Init end\r\n” in resp:
print “Ready”
break

# Take picture
serial.write(b’\x56\0\x36\x01\0′)
resp = “”
time.sleep(2)
while (serial.inWaiting() > 0):
data = serial.read()
resp += data
if b’\x76\0\x36\0\0′ in resp:
print “Picture taken”
break

#Get JPG size
serial.write(b’\x56\0\x34\x01\0′)
resp = “”
time.sleep(1)
while (serial.inWaiting() > 0):
data = serial.read()
resp += data
if b’\x76\0\x34\0\x04\0\0′ in resp:
msb = serial.read()
lsb = serial.read()
print “Image file size: %d bytes” % (ord(msb) << 8 | ord(lsb))

# Write image to file
serial.write(b’\x56\0\x32\x0C\0\x0A\0\0\0\0\0\0%c%c\0\x0A’ % (msb,lsb))
time.sleep(3)
now = datetime.datetime.now()
filename = “%d.%02d.%02d.%02d.%02d.%02d.jpg” % \
(now.year,now.month,now.day,now.hour,now.minute,now.second)
resp = serial.read(size=5)
if b’\x76\0\x32\0\0′ in resp:
with open(“/tmp/” + filename, ‘wb’) as f:
while (serial.inWaiting() > 0):
data = serial.read()
f.write(‘%c’ % data)
print “Image written to /tmp/%s” % (filename)

If you are interested in changing the image size, see this post.

[/vc_column_text][/vc_column][/vc_row]

Tags: JPEG Camera, UART

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors