Electronic Brick - Serial CMOS Camera

Hi,

Is there any further info on this. The data sheet is a bit sparse.
Specifically, I want to read without JPEG compression.
Is this possible? Also, is there a definition of commands that might allow
me to do this and anything else the sensor is capable of?

Thanks

Hi,

Maybe you can try to use aduino/seeeduino Mega seeedstudio.com/depot/music- … th=104_109 + Electronic Brick - Serial CMOS Camera.

There is a demo code on the Electronic Brick - Serial CMOS Camera website. SerialCamera -> SerialCamera_Mega
You also need to download the SD card lib from this link. code.google.com/p/fat16lib/downl … p&can=2&q=
Connect like this: plug Music Shield to the Mega, the mega’s SPI pins are compatible with Music Shield’s SPI pins.
aduino/seeeduino Mega -------------- Electronic Brick - Serial CMOS Camera
RX1 ------ TX(white wire)
TX1 ----- RX(yellow wire)
GND ------ GND(black wire)
VCC ----- VCC(red wire)

The picture will be save in the SD card as its name is pic00, pic01 etc.

Please let me know if you need more help.
Regards.

Hi,

Sorry, I obviously failed to make myself clear.
From what I understand the camera has 3 sets of commands:

  1. Read a VGA frame
  2. Read a QVGA frame
  3. Read a programable frame.
    All 3 command sets invoke jpeg compression.
    Is this correct?

What I would like to do is read a frame without jpeg compression.
Is there a command set that would achieve this?

The data sheet of the sensor and it’s command set would be very useful.

I have just received that camera and wrote code to capture an image, using Linux and an FTDI card (actually porting the relevant parts from the demo code to Linux).

There are 3 documented commands:

  1. Capture VGA (640x480) image.
  2. capture QVGA (320x240) image.
  3. Send data-block (starting at byte, block-size bytes).

Results are pretty nice, but very slow. Receiving a 320x240 image in 64 byte blocks took me 6 seconds in average. Larger block size makes it faster, but it’s not practical if I want to use a microcontroller (block size if limited by the available ram). Also, it may not be practical to decode jpeg on an 8 bit microcontroller.

Searching LSDC030M01 on the internet I see hints that the camera supports lower res (160x120) and also different baus rates. I could not find any documents that explain how it can be done.

I am having trouble getting a response from my electronic brick camera. I’ve tested the camera with an oscilloscope. The correct values are transmitted to the camera, but there is nothing being received.
Did you have a similar problem, or know how to troubleshoot by an chance?
Also, what is the LED for?

Here is my code:

int main()
{
int i;
int b=0;
char buf[3];

system(“stty -F /dev/ttyS2 ispeed 115200 cs8 -cstopb -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke -parenb”);

// open serial port connected to camera
openPort();

// initialize camera and request version info
byteTx(0x55);
byteTx(0x41);
byteTx(0x52);
byteTx(0x54);
byteTx(0xCA);
byteTx(0x00);
byteTx(0x00);
byteTx(0x00);
byteTx(0x00);
byteTx(0x00);
byteTx(0x00);
if (read(fd, buf, 3) != -1)
{
printf(“SUCCESS”);
printBuf(buf);
}

while(1)
{
byteTx(0x55);
byteTx(0x41);
byteTx(0x52);
byteTx(0x54);
byteTx(0xCA);
byteTx(0x00);
byteTx(0x00);
byteTx(0x00);
byteTx(0x00);
byteTx(0x00);
byteTx(0x00);
if (read(fd, buf, 3) != -1)
{
printf(“SUCCESS”);
printBuf(buf);
}

  b = 0;
}

// print network information
printBuf(buf);

// close serial port connected to GSM module
closePort();
}

/**

  • byteTx()
  • Transmits a byte to the camera over the serial interface.
  • @arg value the 8-bit value to be transmitted.
  • @return void
    */

void byteTx(char value)
{
char* buffer;
buffer = &value;
write(fd, buffer, 1);
//printf(“value sent: %x \n”, *buffer);
}

/**

  • byteRx()
  • Reads a byte from the camera over the serial interface.
  • @arg buffer a character pointer to the buffer which will
  •  store the received data.
    
  • @arg nbytes an int expressing the number of bytes to read.
  • @arg iter an int expressing the number of times to receive
  •  nbytes.
    
  • @return int - how many bytes were read
    /
    int byteRx(char
    buffer, int nbytes, int iter)
    {

int i;
int bytesRead = 0;

printf(“about to read…\n”);

for(i = 0; i < iter; i++)
{
if((bytesRead = read(fd, buffer, nbytes)) == ERROR)
{
printf(“error reading\n”);
return bytesRead;
}
buffer = buffer + nbytes;
printf(“read\n”);
}

return bytesRead;

}

/**

  • openPort()
  • Opens ttyS2 port to write to camera.
  • @return -1 if port failed to open and 0 if port successfuly opens
    */
    int openPort()
    {
    fd = open("/dev/ttyS2", O_RDWR | O_NONBLOCK);

if (!fd)
{
printf(“File failed to open \n”);
return 0;
}

printf(“File successfully opened with descriptor, fd = %d.\n”, fd);
return fd;
}

/**

  • closePort()
  • Closes serial port to the camera.
  • @return 1 if successful, -1 if failed.
    */
    int closePort()
    {
    if(!close(fd))
    {
    printf(“file successfully closed \n”);
    return 1;
    }

else
return -1;
}

/**

  • printBuf()
  • prints all the elements of a character array to the command line
  • @arg buffer a character array that contains stored data
  • received from camera
  • @return void
    */
    void printBuf(char
    buffer)
    {
    int i;
    for(i = 0; i < BUF_LENGTH; i++)
    {
    printf("%c", buffer[i]);
    buffer[i] = 0;
    }
    printf("\n");
    }

It looks like you are using Linux. The attached code has worked for me some time ago
(Change cmdtry to either cmdVGA or cmdQVGA to get VGA or QVGA pictures).

Why can’t I attach a C source file ?

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termio.h>
#include <unistd.h>

int capture(int port, int file);
int readCamSaveToFile(int port, int file, int size);

int main(int argc, char **argv) {
	struct termios termios;

	if(argc != 3) {
		fprintf(stderr, "Usage %s SerialPort OutputFile.jpg\n", argv[0]);
		exit(1);
	}

	int port = open(argv[1], O_RDWR|O_EXCL/*|O_NONBLOCK*/);

	if(port < 0) {
		perror(argv[1]);
		exit(1);
	}

	if(tcgetattr(port, &termios)) {
		perror("tcgetattr");
		exit(1);
	}

	cfmakeraw(&termios);
	cfsetospeed(&termios, B115200);
	cfsetispeed(&termios, B115200);
	
	if(tcsetattr(port, TCSANOW, &termios)) {
		perror("TCGETS");
		exit(1);
	}

	int file = open(argv[2], O_CREAT|O_TRUNC|O_WRONLY, 0666);
	if(file < 0) {
		perror(argv[2]);
		exit(1);
	}

	int res = capture(port, file);

	exit(res);
}

#define PIC_BUF_LEN 4096
#define SHIFT_BIT 12

unsigned char cmdtry[] = {
  0x55,0x41,0x52,0x54,0xCA,0x00,0x00,0x00,0xff,0x00,0x00};
unsigned char cmdVGA[] = {
  0x55,0x41,0x52,0x54,0xCA,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char cmdQVGA[] = {
  0x55,0x41,0x52,0x54,0xCA,0x00,0x00,0x00,0xFF,0x00,0x00};
unsigned char cmdGetDat[] = {
  0x55,0x41,0x52,0x54,0xC7,0x00,0x00,0x00,0x00,0x00,0x00};

int capture(int port, int file) {
	unsigned char replyBuf[3];

	if(write(port, cmdtry, sizeof(cmdtry)) != sizeof(cmdtry)) {
		perror("write cmdVGA");
		return 1;
	}

	if(read(port, replyBuf, sizeof(replyBuf)) != sizeof(replyBuf)) {
		perror("read cmdVGA reply");
		return 1;
	}

	unsigned long picTotalLen = (replyBuf[0] << 16) | (replyBuf[1] << 8) | replyBuf[2];
	printf("picTotalLen = %lu\n", picTotalLen);

	//read pic data from camera and write to file in SD card
	unsigned long count = picTotalLen >> SHIFT_BIT;
	unsigned long tail = picTotalLen & (PIC_BUF_LEN - 1); 
	unsigned long addr = 0;
	cmdGetDat[5] = 0;
	cmdGetDat[6] = 0;
	cmdGetDat[7] = 0;
	cmdGetDat[8] = PIC_BUF_LEN >> 16;
	cmdGetDat[9] = PIC_BUF_LEN >> 8;
	cmdGetDat[10] = (PIC_BUF_LEN & 0xff);

	for(int i = 0; i < count; i++){		//get and save count*PIC_BUF_LEN data
		write(port, cmdGetDat, sizeof(cmdGetDat));
		if(readCamSaveToFile(port, file, PIC_BUF_LEN))
			return 1;
		addr += PIC_BUF_LEN;
		cmdGetDat[5] = addr >> 16;
		cmdGetDat[6] = addr >> 8;
		cmdGetDat[7] = addr & 0xff;
	}

	cmdGetDat[8] = tail >> 16;
	cmdGetDat[9] = tail >> 8;
	cmdGetDat[10] = tail;//get reset of the pic data
	write(port, cmdGetDat, sizeof(cmdGetDat));
	if(readCamSaveToFile(port, file, tail))
		return 1;


	return 0;
}

int readCamSaveToFile(int port, int file, int size) {
	unsigned char dataBuf[PIC_BUF_LEN];

	while(size > 0) {
		int n = read(port, dataBuf, size);
		if(n <= 0) {
			perror("read dataBuf");
			return 1;
		}
		write(file, dataBuf, n);

		size -= n;
	}

	return 0;
}

Hello, i’m searching for the exact same answers.

Since there is nothing else on the market at the moment (working on 5v cam module with easy API) i bought this one.
But i hoped to find the answers in the meantime on the exact same questions:

  • How do you switch to the QQVGA ?
  • How do you disable JPEG and get the frames RAW?

I know that the (chinese) reseller only gives the complete API/datasheet when you buy there stuff, and since seeedstudio bought a lot of those cam modules, could you please give us the complete manual/datasheet of the camera protocol?

This thing can do so much more, and i need it :slight_smile:

I guess i can put (another) cam module in the trash again :frowning:
Without the info i can’t do anything with this - except for using it as an overpayed webcam of some sort :stuck_out_tongue:

Wished i went directly for the more expensive modules on the web that do deliver support and an API… :frowning:

I quite agree. A potentially very useful camera spoiled by no meaningful documentation or support

Hey, guys, seems you are so :imp: there. Sorry for the inconvenience brought.

On the documentation, you can find that there are two commands for capturing different type of pic.

Sorry to tell you that the module does not support the RAW data output. Maybe in the future we will provide one with that function.

For the datasheet of Serial Camera all we have is what you see now. We translated it from the Chinese version, and add an Arduino demo code. If that is not enough for you guys, please tell us where should we improve.

All the best,

Steve

Hello Steve Chang, and thanks for your reply.

But the reason i’m :imp: has to do with my quest to get a camera module were i can process the RAW image on the fly.
In the description of this module it states that it is possible to get it RAW (and in QVGA or less) this is exactly what i need.

Also getting it over UART is a nice feature.
I figured that this would be a OV6620 cam module (since it powered by 5v) with the needed interface pre-soldered in a ‘brick’. Just like the CMUcam or other popular cam modules on the market.

But since the documentation is lacking a LOT of features (i really think that there is a lot more possible) we can’t do anything with it - except for capturing an image and send it to a sdcard … but why would i pay so much money for something that simple - you can buy a snap-cam for a few bucks.

So there must be a bigger use for this ‘brick’ - could you please contact your reseller again and ask for the complete technical document for this ‘brick’ ?
I almost know for sure that you can set a lot of registery options - also RAW and QVGA etc…

I agree with cybertim. There has to be more options than what we are provided with. It’s quite pricey for just 3 commands :frowning:

Also, what is the max current draw of the device?