{"action":"created","issue":{"url":"https://api.github.com/repos/ArduCAM/Arduino/issues/80","repository_url":"https://api.github.com/repos/ArduCAM/Arduino","labels_url":"https://api.github.com/repos/ArduCAM/Arduino/issues/80/labels{/name}","comments_url":"https://api.github.com/repos/ArduCAM/Arduino/issues/80/comments","events_url":"https://api.github.com/repos/ArduCAM/Arduino/issues/80/events","html_url":"https://github.com/ArduCAM/Arduino/issues/80","id":173655595,"number":80,"title":"Arducam RevC shield _occasionally_ fails to load a valid jpeg","user":{"login":"aldobranti","id":9655839,"avatar_url":"https://avatars.githubusercontent.com/u/9655839?v=3","gravatar_id":"","url":"https://api.github.com/users/aldobranti","html_url":"https://github.com/aldobranti","followers_url":"https://api.github.com/users/aldobranti/followers","following_url":"https://api.github.com/users/aldobranti/following{/other_user}","gists_url":"https://api.github.com/users/aldobranti/gists{/gist_id}","starred_url":"https://api.github.com/users/aldobranti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldobranti/subscriptions","organizations_url":"https://api.github.com/users/aldobranti/orgs","repos_url":"https://api.github.com/users/aldobranti/repos","events_url":"https://api.github.com/users/aldobranti/events{/privacy}","received_events_url":"https://api.github.com/users/aldobranti/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-08-28T16:45:41Z","updated_at":"2016-12-09T07:24:08Z","closed_at":null,"body":"I have a revC on a Mega2560 with OV5642 \n\nAbout 1/3 of the time it fails to record a valid jpeg file ( see attached )\n\n![00000002](https://cloud.githubusercontent.com/assets/9655839/18035039/d53af196-6d44-11e6-8e54-c2fe50c9503d.JPG)\n\nlooking at the leading bytes of this it clearly doesnt start with an FFD8 group so it seems like we hadn't synchronised up with the start of the jpeg format -- some kind of timing issue ? Why does it sometimes catch a valid jpeg and sometimes it does not ? \n\nmy setup\n`//Check if the camera module type is OV5642\n  myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid);\n  myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid);\n  if ((vid != 0x56) || (pid != 0x42)) {\n    Serial.print(\"Can't find OV5642 module! vid=0x\"); Serial.print(vid, HEX); Serial.print(\" pid=0x\"); Serial.println(pid, HEX);\n    //while (1);\n  } else\n    Serial.println(\"OV5642 detected\");\n\n  myCAM.set_format(JPEG);\n  Serial.println(\"Changed to jpeg capture mode\");\n  myCAM.InitCAM();\n  Serial.println(\"initialized the OV5642 module \");\n\n  myCAM.OV5642_set_JPEG_size(OV5642_1920x1080);\n\n  myCAM.set_bit(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);\n\n  myCAM.clear_fifo_flag();\n  myCAM.write_reg(ARDUCHIP_FRAMES, 0x00);\n`\nthe above code was developed out of the back of issue #72\n\nhere is my capture code \n\n`//Flush the FIFO\n  Serial.println(\"click it: flush\");\n  myCAM.flush_fifo();\n  //Clear the capture done flag\n  Serial.println(\"click it: fifo flag\");\n  myCAM.clear_fifo_flag();\n  //Start capture\n  Serial.println(\"click it: capt start\");\n  myCAM.start_capture();\n  Serial.println(\"capturing\");\n  boxState = capturing;\n  // Wait for the capture to finish in loop().\n`\n\nand here is my storing code, looking for the capture done in loop()\n\n`if ( myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK) ) boxState = storing ;`\n\nand writing to the onboard sd card\n\n`  //Parse JPEG data from FIFO\n  while ( (temp != 0xD9) | (temp_last != 0xFF)  ) {\n    temp_last = temp;\n    temp = myCAM.read_fifo();\n    //Write image data to buffer if not full\n    if (i < 256)\n      buf[i++] = temp;\n    else {\n      //Write 256 bytes image data to file\n      //Serial.print(\"*\");\n      outFile.write(buf, 256); buffCnt++;\n      i = 0;\n      buf[i++] = temp;\n    }\n\n  }\n  //Serial.print(\"finished (?) temp=0x\"); Serial.print(temp, HEX); Serial.print(\" temp_last=0x\"); Serial.println(temp_last, HEX);\n  //Write the remaining bytes in the buffer\n  if (i > 0)\n    outFile.write(buf, i);\n  //Close the file\n  outFile.close();\n`\n"},"comment":{"url":"https://api.github.com/repos/ArduCAM/Arduino/issues/comments/265950513","html_url":"https://github.com/ArduCAM/Arduino/issues/80#issuecomment-265950513","issue_url":"https://api.github.com/repos/ArduCAM/Arduino/issues/80","id":265950513,"user":{"login":"Fred54","id":9302012,"avatar_url":"https://avatars.githubusercontent.com/u/9302012?v=3","gravatar_id":"","url":"https://api.github.com/users/Fred54","html_url":"https://github.com/Fred54","followers_url":"https://api.github.com/users/Fred54/followers","following_url":"https://api.github.com/users/Fred54/following{/other_user}","gists_url":"https://api.github.com/users/Fred54/gists{/gist_id}","starred_url":"https://api.github.com/users/Fred54/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fred54/subscriptions","organizations_url":"https://api.github.com/users/Fred54/orgs","repos_url":"https://api.github.com/users/Fred54/repos","events_url":"https://api.github.com/users/Fred54/events{/privacy}","received_events_url":"https://api.github.com/users/Fred54/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T07:24:08Z","updated_at":"2016-12-09T07:24:08Z","body":"I am also having this same problem. I am using a Arducam F Rev.C+ Camera Module Shield with OV2640 for Arduino UNO. https://www.amazon.com/Arducam-Camera-Module-Arduino-Mega2560/dp/B013OBUJ0W/ref=cm_cd_al_qh_dp_t\r\n\r\n It seems there should be a better way than opening a hex editor and fixing each image.\r\n\r\nAll of the demos that give me JPEGs have the same problem. The one that creates a BMP works fine and working with the program that sends an image straight to windows works fine.\r\n\r\nIs there a way to fix the demos to work correctly?\r\n![1](https://cloud.githubusercontent.com/assets/9302012/21041011/45e5c008-bd9d-11e6-8b93-306b0f195a75.JPG)\r\n"}}
{"actor":{"display_login":"Fred54"}}