Can't get VC0706 camera library working via ParticleSoftSerial on Photon

I’m trying to connect two PTC06 V3.1 cameras to a Photon using the Adafruit_VC0706 library.

I can get one working great via the serial RX/TX ports. I was hoping to get the second working using the ParticleSoftSerial library but I can’t get it to find the camera.

Here is a simple repro that is just trying to get a single camera working via ParticleSoftSerial with DeviceOS 3.3.0: photon-camera-test.ino · GitHub

Currently wired with Camera RX → WKP, Camera TX → A2 but I’ve swapped those as well.

Same sketch/camera works when connected to the hardware Serial1 pins.

Software Serial Output

0000004441 [app] INFO: ----------------- BEGIN ----------------- 
0000004656 [app] INFO: No camera found?

Hardware Serial output:

0000003407 [app] INFO: ----------------- BEGIN ----------------- 
0000003420 [app] INFO: Camera Found:
0000003738 [app] INFO: -----------------
VC0703 1.00
Ctrl infr exist
OV7720
525
0000003739 [app] INFO: -----------------
Image size: Motion detection is 0000004123 [app] INFO: OFF

Any tips on how to go about debugging this?

Have you tried a slower baudrate?
38400 is the default in the Adafruit_VC0706 library but this may be a stretch with ParticleSoftSerial.

I'd try to communicate with the camera directly and see how it replies.
Depending on that I'd plan my next steps.

BTW,

NewSoftSerial cameraconnection = NewSoftSerial(WKP, A2);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

should rather be

NewSoftSerial cameraconnection(WKP, A2);
Adafruit_VC0706 cam(&cameraconnection);

to avoid creation of intermediate/temporary objects.

Weirdly that WebIDE sketch is no longer compiling for me? I don’t think I even changed anything from when it worked to when it stopped working: https://gist.githubusercontent.com/edalquist/92648fe1fe210d71da5b1a2615894d11/raw/d692b77b53d19606106087f30d6612e0dd6c03bc/gistfile1.txt

In a local build I tried cam.begin(9600) with no luck.

When you say “try communicate with the camera directly” do you mean set up the NewSoftSerial connection and use those APIs to try sending commands and seeing what the response is?

Thanks for the coding tips, I don’t spend much time in the C++ world :slight_smile:

Edit: I tried 28800, 19200, and 9600 baud and none worked with the camera on the hardware serial port. I remember reading that the camera is only officially supported at 38400

The reason why your code doesn't compile anymore is shown here

lib/TTLCameraLibrary/src/Adafruit_VC0706.cpp:97:13: error: control reaches end of non-void function [-Werror=return-type]
   97 |   runCommand(VC0706_COMM_MOTION_CTRL, args, sizeof(args), 5);

There obviously is a function in that library that promises to return a value but fails to do so.

If you post a SHARE THIS REVISION link from Web IDE we can pinpoint the exact line of code. There are several VS0706 libraries and we don't know which one you're using.

In order to make the camera accept different baudrates you may have to preset it that way. I don't exactly know for this model but other devices can store the desired baudrate it should default to after cold boot.

Depending on your module you may even have the option to use SPI instead of UART - which would make things a lot simpler :wink:

BTW, the datasheet you linked to in your opening post talks about a default baudrate of 115200 which is definitely beyond the reach for ParticleSoftSerial.

Exactly!

The simplest test would be to send the reset command and see whether you get the correct ACK

Particle Web IDE for the build project.

Thanks for the pointers on debugging, I know what I’ll be doing this evening :slight_smile:

Miniature TTL Serial JPEG Camera with NTSC Video : ID 1386 : $35.95 : Adafruit Industries, Unique & fun DIY electronics and kits and Overview | TTL Serial Camera | Adafruit Learning System talk about the 38400 default baud but also mention that changing baud can be buggy. Maybe my dream of 2 cameras off one Photon is a bit much, an I2C version would be quite nice, maybe I need to go find a similar form factor camera that supports I2C with settable addresses instead.

Well, I’m getting some data back from the camera but it is corrupted, ex:

--- SEND ---
 0x56 0x0 0x26 0x0

--- READ ---
 0xFF 0x56 0x83 0x30 0x77
�V�0w
0000006714 [app] INFO: readResponse(5, 200) = 5 bytes in 0 ms

and

--- READ ---
 0x70 0x73 0x60 0x31 0x6E 0x30 0x70 0xD 0xA 0x83 0x74 0xF2 0xEC 0x20 0xE9 0x6E 0xE6 0x72 0x20 0xE5 0xF8 0xC9 0x73 0xF4 0xD 0xA 0x8F 0x56 0x77 0x37 0x72 0x70 0xD 0xA 0x35 0x32 0x35 0xD 0xA 0x89 0x6E 0xE9 0xF4 0x60 0xC5 0x6E 0xE4 0xD 0xA
ps`1n0p
�t�� �n�r ���s�
�Vw7rp
525
�n��`�n�

0000009621 [app] INFO: readResponse(100, 10) = 49 bytes in 10 ms

Which is obviously the info dump from the camera but just not coming through clearly.

I haven’t been able to change baud rates. The PDF documents the command to send but if I open the SoftSerial connection at anything other than 38400 initially I get no data back and the set baud rate command just gets gibberish back if I am connected at 38400.

I even tried a sequence of:

  1. serial.begin at 38400
  2. reset
  3. setBaud 19200
  4. serial.begin at 19200
  5. reset

after switching the serial api to 19200 it goes back to getting no data.

I realized in this project I’m going to end up needing to use a reed relay to only have the cameras powered on when I need to take a picture AND I don’t ever need both cameras at the same time.

I just verified that the cameras work if their RX/TX pins are both wired together to the hardware serial pins on the photon and I just have one powered on at a time. Super hacky but it may actually work

IIRC you can set the baudrate "permanently" so it should be possible to connect the camera to Serial1 to set and store the desired default baudrate.
After that you can detach the camera and reattach to your SoftSerial pins and start off at 19200.

Can you give that a try?

That Worked! It appears the new baud is honored even after a power cycle.

I did have to fix the Adafruit_VC0706 library, its setBaud19200 command was sending the wrong byte string vs what the PDF defines.

I’ll get this all cleaned up and post a summary of the steps after I get done with my actual job/work for the day :slight_smile:

4 Likes

Ok, more than just a day later but here is the pretty simple code for what I actually did:

Note that this is using my fork of the camera library: GitHub - edalquist/Particle-Photon-Adafruit-VC0706-Serial-Camera-Library: Library for VC0706-based Serial JPEG Cameras with Particle Photon modifications

I’ve published this as an actual Particle library for others to use.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.