ArduCAM USB Camera Python SDK Guide V1.3
ArduCAM USB Camera Python SDK Guide V1.3
ArduCAM USB Camera Python SDK Guide V1.3
User Guide
Rev 1.3, Oct 2018
ArduCAM USB Camera Python SDK User Guide
Table of Contents
1 Introduction ............................................................................................................................. 3
2 USB SDK Library ................................................................................................................... 3
3 Demo Code ............................................................................................................................... 3
4 ArduCAM APIs ....................................................................................................................... 3
4.1 Data Structures ................................................................................................................ 3
4.1.1 ArduCamCfg Data Structure Members ................................................................ 3
4.2 Function ........................................................................................................................... 4
4.2.1 General Function..................................................................................................... 5
4.2.1.1 Py_ArduCam_autoopen(cfg )......................................................................... 5
4.2.1.2 Py_ArduCam_scan() ....................................................................................... 5
4.2.1.3 Py_ArduCam_open( cfg,index) ...................................................................... 5
4.2.1.4 Py_ArduCam_close( handle ) ......................................................................... 6
4.2.1.5 Py_ArduCam_getSensorCfg( handle ) .......................................................... 6
4.2.1.6 Recommend Operation Procedure ................................................................ 6
4.2.2 Image Capture Function......................................................................................... 6
4.2.2.1 Py_ArduCam_beginCaptureImage(handle ) ................................................ 6
4.2.2.2 Py_ArduCam_captureImage( handle ) ......................................................... 6
4.2.2.3 Py_ArduCam_endCaptureImage( handle ) .................................................. 6
4.2.2.4 Recommend Operation Procedure ................................................................ 6
4.2.3 Image Read Function .............................................................................................. 6
4.2.3.1 Py_ArduCam_availableImage( handle ) ....................................................... 6
4.2.3.2 Py_ArduCam_readImage( handle)................................................................ 7
4.2.3.3 Py_ArduCam_del( handle ) ............................................................................ 7
4.2.3.4 Py_ArduCam_flush( ArduCamHandle useHandle ).................................... 7
4.2.3.5 Recommend Operation Procedure ................................................................ 7
4.2.4 Sensor Register Access Function ............................................................................ 7
4.2.4.1 Py_ArduCam_writeSensorReg( handle, regAddr, val ) ............................... 7
4.2.4.2 Py_ArduCam_readSensorReg(handle, regAddr )........................................ 7
4.2.5 User Data Access Function ..................................................................................... 7
4.2.5.1 Py_ArduCam_writeUserData( handle,u16Addr, u8Len,data ) ................... 7
4.2.5.2 Py_ArduCam_readUserData( handle, u16Addr, u8Len ) ........................... 7
4.2.6 Camera Board Configuration ................................................................................ 8
4.2.6.1 Py_ArduCam_setboardConfig( handle, u8Command, u16Value, u16Index,
u32BufSize, data ) ........................................................................................................... 8
4.2.7 External Trigger ...................................................................................................... 8
4.2.7.1 Py_ArduCam_setMode(handle,mode) .......................................................... 8
4.2.7.2 Py_ArduCam_isFrameReady(handle) .......................................................... 8
4.2.7.3 Py_ArduCam_softTrigger(handle) ................................................................ 8
4.2.7.4 Py_ArduCam_getSingleFrame(handle,time_out=1500) .............................. 8
4.2.7.5 Recommend Operation Procedure ................................................................ 8
5 Vendor Command Code ....................................................................................................... 10
5.1 USB2.0 Vendor Command Code .................................................................................. 10
1 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
2 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
1 Introduction
This user guide describes the detail software operation of ArduCAM USB camera shield
based on Python SDK library. The latest SDK library and examples can be downloaded from the
https://github.com/arducam.
3 Demo Code
The demo code is provided in source code form to help user to understand the operation the
ArduCAM USB camera and Python SDK library. The demo code located in Python folder which
supports both Python2 and Python3.
4 ArduCAM APIs
There are a set of API functions that access to the ArduCAM USB camera hardware.
4.1 Data Structures
There is important data structures used by the SDK library for the camera configuration.
4.1.1 ArduCamCfg Data Structure Members
u32CameraType: unsigned long, reserved for future use.
u32Height: unsigned long, the height of the video stream
u32Width: unsigned long, the width of the video stream
u8PixelBytes: unsigned char, the number of bytes of one pixel
u8PixelBits: unsigned char, the bits depth per pixel
emI2cMode: enum type i2c_mode, I2C protocol for the sensor
u32I2cAddr: unsigned long, I2C slave address for the sensor
u16Vid: unsigned short, the vendor code of the camera
usbType: unsigned char, USB camera version
emImageFmtMode: enum type format_mode,Image format
u32Size: unsigned long, The size of the received data, mainly used for JPG
data
Example:
cfg = {"u32CameraType":0x4D091031,
"u32Width":1280,"u32Height":964,
"usbType":0,
"u8PixelBytes":1,
"u16Vid":0,
"u32Size":0,
"u8PixelBits":8,
"u32I2cAddr": "0x20",
"emI2cMode":3,
"emImageFmtMode":0,
3 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
"u32TransLvl":64 }
The SDK library support 4 different I2C modes. For example I2C_MODE_8_8 is for 8bits
register and 8bits register value, I2C_MODE_8_16 is for 8bits register and 16bits register value.
ArducamSDK. I2C_MODE_8_8 =0
ArducamSDK.I2C_MODE_8_16 = 1
ArducamSDK.I2C_MODE_16_8 = 2
ArducamSDK.I2C_MODE_16_16 = 3
The SDK library support 7 different Image format modes.
ArducamSDK.FORMAT_MODE_RAW = 0
ArducamSDK.FORMAT_MODE_RGB = 1
ArducamSDK.FORMAT_MODE_YUV = 2
ArducamSDK.FORMAT_MODE_JPG =3
ArducamSDK.FORMAT_MODE_MON = 4
ArducamSDK.FORMAT_MODE_RAW_D = 5
ArducamSDK.FORMAT_MODE_MON_D = 6
4.2 Function
Function diagram:
4 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
ArduCam_autoopen
ArduCam_scan
ArduCam_close
ArduCam_getSensorCfg
ArduCam_beginCaptureImage
ArduCam_endCaptureImage
Function ArduCam_availableImage
ArduCam_readImage
Image Read Function
ArduCam_del
ArduCam_flush
ArduCam_writeSensorReg
Register Access Function
ArduCam_readSensorReg
ArduCam_writeUserData
5 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
Multiple Cameras:
scan …… …... ……
N
Y
beginCaptureImage captureImage End? endCaptureImage
6 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
Y
availableImage Exist? readImage del
N
7 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
8 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
Y
setMode(EXT…) isFrameReady? getSingleFrame
Delay
9 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
10 www.ArduCAM.com
ArduCAM USB Camera Python SDK User Guide
6 Error Code
The error code of the SDK library is defined in the following table.
ArducamSDK.USB_CAMERA_NO_ERROR = 0x0000
ArducamSDK.USB_CAMERA_USB_CREATE_ERROR = 0xFF01
ArducamSDK.USB_CAMERA_USB_SET_CONTEXT_ERROR = 0xFF02
ArducamSDK.USB_CAMERA_VR_COMMAND_ERROR = 0xFF03
ArducamSDK.USB_CAMERA_USB_VERSION_ERROR = 0xFF04
ArducamSDK.USB_CAMERA_BUFFER_ERROR = 0xFF05
ArducamSDK.USB_CAMERA_NOT_FOUND_DEVICE_ERROR = 0xFF06
ArducamSDK.USB_CAMERA_I2C_BIT_ERROR = 0xFF0B
ArducamSDK.USB_CAMERA_I2C_NACK_ERROR = 0xFF0C
ArducamSDK.USB_CAMERA_I2C_TIMEOUT = 0xFF0D
ArducamSDK.USB_CAMERA_USB_TASK_ERROR = 0xFF20
ArducamSDK.USB_CAMERA_DATA_OVERFLOW_ERROR = 0xFF21
ArducamSDK.USB_CAMERA_DATA_LACK_ERROR = 0xFF22
ArducamSDK.USB_CAMERA_FIFO_FULL_ERROR = 0xFF23
ArducamSDK.USB_CAMERA_DATA_LEN_ERROR = 0xFF24
ArducamSDK.USB_CAMERA_FRAME_INDEX_ERROR = 0xFF25
ArducamSDK.USB_CAMERA_USB_TIMEOUT_ERROR = 0xFF26
ArducamSDK.USB_CAMERA_READ_EMPTY_ERROR = 0xFF30
ArducamSDK.USB_CAMERA_DEL_EMPTY_ERROR = 0xFF31
ArducamSDK.USB_CAMERA_SIZE_EXCEED_ERROR = 0xFF51
ArducamSDK.USB_USERDATA_ADDR_ERROR = 0xFF61
ArducamSDK.USB_USERDATA_LEN_ERROR = 0xFF62
ArducamSDK.USB_BOARD_FW_VERSION_NOT_SUPPORT_ERROR = 0xFF71
11 www.ArduCAM.com