mbed serial interface for the OV528 camera (uCAM TTL 120 from 4D systems).

Dependencies:   MODSERIAL

Dependents:   mbed_uCAM_TTL120_20141118

Library for interfacing the mbed to the OV528 jpeg engine camera from Omnivision. I tested this program using the uCAM TTL 120 from 4D systems, now obsolete.

/media/uploads/jebradshaw/pic0003.jpg

Above is a saved jpeg image from the camera at 480x640 resolution

/media/uploads/jebradshaw/fullsizerender.jpg

Camera and TFT screen setup

/media/uploads/jebradshaw/tft_closeup_60x80.jpg

Closeup of the TFT screen displaying a 60x80 pixel 16 bit color bitmap image. The RGB (565) pixel colors were reversed when read from the camera relative to the TFT screen so a bit mask and shift had to be applied when displaying the pixel color.

bit mask and shift

         int k=12;
         for(int i=0;i<60;i++){
                for(int j=0;j<80;j++){                    
                    //returned 16-bit color is 565(RGB)
                     pixel_col = (imageData[k] << 8);
                     k++;                       
                     pixel_col += imageData[k];
                     k++;
//                 fputc(((picture[k] >> 8) & 0xff), fp);     //write pixel high byte to file 
//                 fputc(picture[k] & 0xff, fp);                 //write low byte
                                        
                //swap R and B bits in returned pixel for TFT display
                int TFT_pix_col = 0;
                TFT_pix_col += (pixel_col & 0x001f) << 11;
                TFT_pix_col += (pixel_col & 0xf800) >> 11;
                TFT_pix_col += (pixel_col & 0x07e0);
                                        
                 TFT.pixel(j, i, TFT_pix_col);  //Do something with the pixel
                }
             }
Committer:
jebradshaw
Date:
Wed Nov 26 16:57:13 2014 +0000
Revision:
3:85db6ea8c0a4
Parent:
2:f80257456c6e
uCAM_TTL120 Library; -Improved cam_read() function with numbytes check and timeout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jebradshaw 0:fcc0eaeeb35c 1 // uCAM TTL(120) jpeg camera class for mbed
jebradshaw 0:fcc0eaeeb35c 2 // J. Bradshaw 20141106
jebradshaw 0:fcc0eaeeb35c 3
jebradshaw 0:fcc0eaeeb35c 4 #include "mbed.h"
jebradshaw 1:a33d709303c6 5 //define larger buffers for return packets
jebradshaw 1:a33d709303c6 6 #define MODSERIAL_DEFAULT_RX_BUFFER_SIZE 1024
jebradshaw 1:a33d709303c6 7 #define MODSERIAL_DEFAULT_TX_BUFFER_SIZE 1024
jebradshaw 1:a33d709303c6 8 #include "MODSERIAL.h"
jebradshaw 0:fcc0eaeeb35c 9
jebradshaw 0:fcc0eaeeb35c 10 #ifndef uCAM_TTL120_H
jebradshaw 0:fcc0eaeeb35c 11 #define uCAM_TTL120_H
jebradshaw 0:fcc0eaeeb35c 12
jebradshaw 0:fcc0eaeeb35c 13 //uCAM command defines, page 8 of uCAM manual
jebradshaw 0:fcc0eaeeb35c 14 #define uCAM_INITIAL 0xAA01
jebradshaw 0:fcc0eaeeb35c 15 #define uCAM_GET_PICTURE 0xAA04
jebradshaw 0:fcc0eaeeb35c 16 #define uCAM_SNAPSHOT 0xAA05
jebradshaw 0:fcc0eaeeb35c 17 #define uCAM_SET_PACKAGE_SIZE 0xAA06
jebradshaw 0:fcc0eaeeb35c 18 #define uCAM_SET_BAUD_RATE 0xAA07
jebradshaw 0:fcc0eaeeb35c 19 #define uCAM_RESET 0xAA08
jebradshaw 0:fcc0eaeeb35c 20 #define uCAM_DATA 0xAA0A
jebradshaw 0:fcc0eaeeb35c 21 #define uCAM_SYNC 0xAA0D
jebradshaw 0:fcc0eaeeb35c 22 #define uCAM_ACK 0xAA0E
jebradshaw 0:fcc0eaeeb35c 23 #define uCAM_NAK 00xAA0F
jebradshaw 0:fcc0eaeeb35c 24 #define uCAM_LIGHT 0xAA13
jebradshaw 0:fcc0eaeeb35c 25
jebradshaw 0:fcc0eaeeb35c 26 /**
jebradshaw 0:fcc0eaeeb35c 27 * uCAM_TTL120 Class.
jebradshaw 0:fcc0eaeeb35c 28 */
jebradshaw 0:fcc0eaeeb35c 29
jebradshaw 0:fcc0eaeeb35c 30 class uCAM_TTL120{
jebradshaw 0:fcc0eaeeb35c 31 public:
jebradshaw 0:fcc0eaeeb35c 32 /**
jebradshaw 0:fcc0eaeeb35c 33 * Constructor.
jebradshaw 0:fcc0eaeeb35c 34 * @param tx - Serial port transmit pin
jebradshaw 0:fcc0eaeeb35c 35 * @param rx - Serial port recieve pin
jebradshaw 0:fcc0eaeeb35c 36 */
jebradshaw 0:fcc0eaeeb35c 37 uCAM_TTL120(PinName tx, PinName rx);
jebradshaw 0:fcc0eaeeb35c 38 int uCAM_read(char *str, int numchars, float timeout);
jebradshaw 0:fcc0eaeeb35c 39
jebradshaw 0:fcc0eaeeb35c 40 void uCAM_Command_Send(int command,char p1,char p2,char p3,char p4);
jebradshaw 2:f80257456c6e 41 int uCAM_GetACK(int command);
jebradshaw 0:fcc0eaeeb35c 42 int uCAM_Connect(void);
jebradshaw 0:fcc0eaeeb35c 43 void uCAM_FlushBuffer(void);
jebradshaw 0:fcc0eaeeb35c 44 int uCAM_send_INITIAL_80x60_16RAW(void);
jebradshaw 0:fcc0eaeeb35c 45 int uCAM_send_INITIAL_80x60_2RAW(void);
jebradshaw 0:fcc0eaeeb35c 46 int uCAM_send_INITIAL_128x128_4RAW(void);
jebradshaw 0:fcc0eaeeb35c 47 int uCAM_send_SNAPSHOT(void);
jebradshaw 3:85db6ea8c0a4 48 int uCAM_send_GET_PICTURE_80x60_16COL_RAW(FILE *fp);
jebradshaw 0:fcc0eaeeb35c 49 int uCAM_send_GET_PICTURE_80x60_2GRAY_RAW(void);
jebradshaw 0:fcc0eaeeb35c 50 int uCAM_send_GET_PICTURE_128x128_4GRAY_RAW(void);
jebradshaw 0:fcc0eaeeb35c 51
jebradshaw 3:85db6ea8c0a4 52 void uCAM_TakePic_RAW_16COLOR_80x60(FILE *fp);
jebradshaw 0:fcc0eaeeb35c 53 void uCAM_TakePic_RAW_2GRAY_80x60(void);
jebradshaw 0:fcc0eaeeb35c 54 void uCAM_TakePic_RAW_4GRAY_128x128(void);
jebradshaw 0:fcc0eaeeb35c 55
jebradshaw 3:85db6ea8c0a4 56 int uCAM_get_jpeg(FILE *fp);
jebradshaw 2:f80257456c6e 57
jebradshaw 0:fcc0eaeeb35c 58 void uCAM_set_baud(void);
jebradshaw 0:fcc0eaeeb35c 59
jebradshaw 0:fcc0eaeeb35c 60 char picture[10000];
jebradshaw 1:a33d709303c6 61 MODSERIAL _cam;
jebradshaw 0:fcc0eaeeb35c 62 private:
jebradshaw 0:fcc0eaeeb35c 63 Timer *timerCam;
jebradshaw 0:fcc0eaeeb35c 64 };
jebradshaw 0:fcc0eaeeb35c 65
jebradshaw 0:fcc0eaeeb35c 66 #endif /* uCAM_TTL120_H */