The photo is my camera output data 8-bit to 16-bit data by attaching to upgrading to a 2-byte hex
Then I'm not sure what to do to try to change the HEX code to an image file (BMP). The code is marked in red <https://lh3.googleusercontent.com/-v6Xc18X2hNg/VcwJebXb3eI/AAAAAAAAFEo/MSnmbY5U-6o/s1600/%2525C1%2525A6%2525B8%2525F1_%2525BE%2525F8%2525C0%2525BD.png> #include <stdio.h> #include <linux/i2c.h> #include <linux/i2c-dev.h> #include <sys/ioctl.h> #include <fcntl.h> #include <errno.h> #include <time.h> #include <sys/stat.h> #include <string.h> #include <unistd.h> int i2c_open(); int i2c_write(int handle, unsigned char* buf, unsigned int length); int i2c_write_byte(int handle, unsigned char val); int i2c_write_ignore_nack(int handle, unsigned char addr_w, unsigned char* buf, unsigned int length); int i2c_close(int handle); int delay_ms(unsigned int msec); void init_ov7670(); void wr_rst_on(); void wr_rst_off(); void rd_rst_on(); void rd_rst_off(); void rd_en_on(); void rd_en_off(); void wr_en_on(); void wr_en_off(); void rd_clk_hi(); void rd_clk_lo(); void t_rst_off(); void t_rst_on(); int vsync(); void read_data(); /*********************************************************************** *********************** i2c function ****************************** **********************************************************************/ int i2c_open(){ int file; char filename[16]; sprintf(filename, "/dev/i2c-1"); if((file=open(filename, O_RDWR))<0){ fprintf(stderr, "i2c_open error: %s\n", strerror(errno)); return(file); } if(ioctl(file, I2C_SLAVE, 0x21)){ fprintf(stderr, "i2c_open error: %s\n", strerror(errno)); return(file); } return(file); } int i2c_write(int handle, unsigned char* buf, unsigned int length){ if(write(handle, buf, length) != length){ fprintf(stderr, "i2c_write error: %s\n", strerror(errno)); return(-1); } return(length); } int i2c_write_byte(int handle, unsigned char val){ if(write(handle, &val, 1)!=1){ fprintf(stderr, "i2c_write_byte error: &s\n", strerror(errno)); return(1); } return(1); } int i2c_write_ignore_nack(int handle, unsigned char addr_w, unsigned char* buf, unsigned int length){ struct i2c_rdwr_ioctl_data msgset; struct i2c_msg msgs[1]; msgs[0].addr=addr_w; msgs[0].len=length; msgs[0].flags=0 | I2C_M_IGNORE_NAK; msgs[0].buf=buf; if(ioctl(handle, I2C_RDWR, (unsigned long)&msgset)<0){ fprintf(stderr, "i2c_write_ignore_nack error: %s\n", strerror(errno)); return(-1); } return(length); } int i2c_close(int handle){ if((close(handle))!=0){ fprintf(stderr, "i2c_close error: &s\n", strerror(errno)); return(-1); }return(0); } /************************************************************** * delay function * *************************************************************/ int delay_ms(unsigned int msec){ int ret; struct timespec a; if(msec>999){ fprintf(stderr, "delay_ms error: delay value needs to be less than 999\n"); } a.tv_nsec=((long)(msec))*1E6d; a.tv_sec=0; if((ret=nanosleep(&a, NULL))!=0){ fprintf(stderr, "delay_ms error: %s\n", strerror(errno)); } return(0); } /********************************************************************* * ov7670 function * ********************************************************************/ void wr_rst_on(void){ int fd_66=open("/sys/class/gpio/gpio66/value", O_WRONLY); if(fd_66 > 0){ write(fd_66, "0", 1); }else{ printf("Error: wr_rst_on\n"); } close(fd_66); } void wr_rst_off(void){ int fd_66=open("/sys/class/gpio/gpio66/value", O_WRONLY); if(fd_66 > 0){ write(fd_66, "1", 1); }else{ printf("Error: wr_rst_off\n"); } close(fd_66); } void rd_rst_on(void){ int fd_67=open("/sys/class/gpio/gpio67/value", O_WRONLY); if(fd_67 > 0){ write(fd_67, "0", 1); }else{ printf("Error: rd_rst_on\n"); } close(fd_67); } void rd_rst_off(void){ int fd_67=open("/sys/class/gpio/gpio67/value", O_WRONLY); if(fd_67 > 0){ write(fd_67, "1", 1); }else{ printf("Error: rd_rst_off\n"); } close(fd_67); } void rd_en_on(void){ int fd_69=open("/sys/class/gpio/gpio69/value", O_WRONLY); if(fd_69 > 0){ write(fd_69, "0", 1); }else{ printf("Error: rd_en_on\n"); } close(fd_69); } void rd_en_off(void){ int fd_69=open("/sys/class/gpio/gpio69/value", O_WRONLY); if(fd_69 > 0){ write(fd_69, "1", 1); }else{ printf("Error: rd_en_off\n"); } close(fd_69); } void wr_en_on(void){ int fd_68=open("/sys/class/gpio/gpio68/value", O_WRONLY); if(fd_68 > 0){ write(fd_68, "1", 1); }else{ printf("Error: wr_en_on\n"); } close(fd_68); } void wr_en_off(void){ int fd_68=open("/sys/class/gpio/gpio69/value", O_WRONLY); if(fd_68 > 0){ write(fd_68, "0", 1); }else{ printf("Error: wr_en_off\n"); } close(fd_68); } void rd_clk_hi(void){ int fd_22=open("/sys/class/gpio/gpio22/value", O_WRONLY); if(fd_22 > 0){ write(fd_22, "1", 1); }else{ printf("Error: rd_clk_hi\n"); } close(fd_22); } void rd_clk_lo(void){ int fd_22=open("/sys/class/gpio/gpio22/value", O_WRONLY); if(fd_22 > 0){ write(fd_22, "0", 1); }else{ printf("Error: rd_clk_lo\n"); } close(fd_22); } void t_rst_off(void){ wr_rst_off(); rd_rst_off(); } void t_rst_on(void){ wr_rst_on(); rd_rst_on(); } void rd_clk(void){ rd_clk_hi(); rd_clk_lo(); } void init_ov7670(){ int handle; unsigned char buf[1]; handle=i2c_open(); wr_rst_on(); rd_rst_on(); rd_en_off(); wr_en_off(); rd_clk_lo(); buf[0]=0x12; buf[1]=0x80; delay_ms(10); i2c_write(handle, buf, 2); i2c_close(handle); } unsigned char rgb[64][2]={ {0x00, 0x00}, {0x01, 0x40}, {0x02, 0x40}, {0x03, 0x06}, {0x90, 0x03}, {0x10, 0x00}, {0x0c, 0x00}, {0x0d, 0x00}, {0x0e, 0x61}, {0x11, 0x01}, {0x12, 0x14}, {0x13, 0xe7}, {0x14, 0x20}, {0x15, 0x00}, {0x16, 0x02}, {0x17, 0x16}, {0x18, 0x04}, {0x19, 0x02}, {0x1a, 0x7b}, {0x1e, 0x37}, {0x21, 0x02}, {0x22, 0x91}, {0x24, 0x75}, {0x25, 0x63}, {0x26, 0xa5}, {0x29, 0x07}, {0x32, 0x80}, {0x34, 0x11}, {0x3b, 0x42}, {0x3c, 0x78}, {0x3d, 0xc2}, {0x3e, 0x00}, {0x3f, 0x00}, {0x40, 0xd0}, {0x41, 0x38}, {0x4c, 0x00}, {0x55, 0x00}, {0x56, 0x40}, {0x69, 0x0c}, {0x6b, 0x60}, {0x70, 0x00}, {0x71, 0x00}, {0x72, 0x11}, {0x73, 0x00}, {0x74, 0x19}, {0x75, 0x05}, {0x76, 0xe1}, {0x77, 0x01}, {0x82, 0x00}, {0x8f, 0x00}, {0x90, 0x00}, {0x91, 0x00}, {0x92, 0x00}, {0x94, 0x04}, {0x95, 0x08}, {0x9d, 0x4c}, {0x9e, 0x3f}, {0xa2, 0x02}, {0xa4, 0x89}, {0xa5, 0x05}, {0xab, 0x07}, {0xb3, 0x82}, {0xc9, 0x60} }; void ov7670_rgb565(){ int i=0; int handle; unsigned char buf[1]; handle=i2c_open(); for(i=0; i<64; i++){ buf[0]= rgb[i][0]; buf[1]= rgb[i][1]; i2c_write(handle, buf, 2); delay_ms(10); } i2c_close(handle); } int vsync(){ char ch; int fd_61=open("/sys/class/gpio/gpio61/value", O_RDONLY); read(fd_61, &ch, 1); close(fd_61); return ch - '0'; } void read_data(){ char ch0, ch1, ch2, ch3, ch4, ch5, ch6, ch7; int fd_45=open("/sys/class/gpio/gpio45/value", O_RDONLY); int fd_44=open("/sys/class/gpio/gpio44/value", O_RDONLY); int fd_23=open("/sys/class/gpio/gpio23/value", O_RDONLY); int fd_26=open("/sys/class/gpio/gpio26/value", O_RDONLY); int fd_47=open("/sys/class/gpio/gpio47/value", O_RDONLY); int fd_46=open("/sys/class/gpio/gpio46/value", O_RDONLY); int fd_27=open("/sys/class/gpio/gpio27/value", O_RDONLY); int fd_65=open("/sys/class/gpio/gpio65/value", O_RDONLY); read(fd_45, &ch0, 1); read(fd_44, &ch1, 1); read(fd_23, &ch2, 1); read(fd_26, &ch3, 1); read(fd_47, &ch4, 1); read(fd_46, &ch5, 1); read(fd_27, &ch6, 1); read(fd_65, &ch7, 1); printf("%c%c%c%c%c%c%c%c\n", ch0, ch1, ch2, ch3, ch4, ch5, ch6, ch7); close(fd_45); close(fd_44); close(fd_23); close(fd_26); close(fd_47); close(fd_46); close(fd_27); close(fd_65); } void main(){ int v=0; int data=0; unsigned long k=0; init_ov7670(); delay_ms(10); ov7670_rgb565(); delay_ms(10); while(1){ while(!vsync()); t_rst_on(); rd_clk(); while(vsync()); wr_en_on(); t_rst_off(); while(!vsync()); wr_en_off(); rd_en_on(); for(k=0; k<153600; k++){ rd_clk(); read_data(); //printf("%d\n", data); } rd_en_off(); printf("==========================================================================\n"); } } And I Will know how accurate the data coming from the camera? What you should know to create a BMP ?? -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.