USB API and Arduino for Camera Trap

Super great work you are all doing here! I have a project that I am doing right now in Panama where I am trying to make 360 Camera trap prototypes. We got the first up and going with the MADV camera because it was easy to control with two pins they had broken out that you can just short to turn the camera on and take photos, etc

But now i am trying to make one with the Theta V, but running into much more difficulties.

The basics we need are to:

  1. Turn on the camera (and at least be able to turn it off) given a response from an autonomous Arduino
  2. Trigger it to take a photo or record a video
  3. turn itself back off (at least to sleep mode)

I asked Theta support and they told me it couldn’t be done.
But after some hacking, i have some promising findings.

A) If i connect an arduino via an OTG cable set up as a Human Interface Device (HID), and send it a key stroke, it will wake up from sleep

B) If i run the HID plugin on the Theta V, i can completely control the shooting with an Arduino emulating a keyboard (It’s great!). BUT the camera will not automatically start up in Plugin Mode

C) if i connect the CA-3 remote shutter, it can make the camera take photos without any plugin over the USB, BUT the CA-3 cannot wake the camera up.

So I am able to do all the actions i need, but not all with the same device.

Does anyone know
A) how to send the USB Api triggers from an Arduino? (Teensy has USB serial support)
B) How to start up the camera in plugin mode?
or
C) What the CA-3 is sending to trigger the photo?

You can’t turn on the camera with the API. I need to leave for lunch. I’ll look at the rest of the questions later.

Ah, but I can turn the camera on from sleep mode by sending a virtual keypress over an Arduino hooked up the the otg cable. So I can turn it on with the Arduino, I just need to be able to then use the Arduino to send a message to tell if the trigger and take a photo

1 Like

Can you send a single command to the camera with a Wi-Fi API to have it go into plug-in mode?

https://developers.theta360.com/en/docs/v2.1/api_reference/commands/camera._plugin_control.html

Can you use a Raspberry Pi Zero?

There are more examples using the USB API with a Raspberry Pi. There are examples using Arduino on this forum using the WiFi API.

If you’re committed to Arduino, the THETA USB API is PTP. Try and use an Arduino PTP library. It may work.

https://forum.arduino.cc/index.php?topic=377915.0

Thanks for the info. I think i might have to end up going with the RPI, but it would be amazing if i could just go straight from the Arduino to just send a simple trigger because it could be super fast and super low power and i know it is physically doable!
But i just spoke with Oleg Mazurov, who wrote the PTP libraries, and it doesnt seem like ill be able to pull it off with an Arduino without extra hardware or a lot of coding to make it work with the Teensy

Although it may be possible to modify Oleg Mazurov’s code and example, I agree it may be a lot of work.

There’s many examples using the Raspberry Pi and USB to talk to the THETA. So, although there are problems with the Raspberry Pi, including clean shutdown, you can probably get something up quickly.

There’s a set of tutorials here:


Possible Serial Port Capability in the Future

On this thread, you can see that for hobbyist experiments, we can access the camera through the serial port. Note that this is not a good solution for production projects right now because it requires manual “permission setting” with something like Vysor. If you’re working on a potentially high-volume project, I can pass your requirements on to RICOH, which might help nudge them. Feel free to send me a DM, if this is a potentially high-volume camera sales project.

Bluetooth

This type of device connects to the THETA with Bluetooth. It’s theoretically possible to build something for Arduino, but there is no working example.

Using Sony MESH IoT Plug-in with RICOH THETA V

Current Status Assessment

  • Appears that there is no easy-example PTP code for Arduino
  • I can’t find any Bluetooth example code to work with the THETA Bluetooth API
  • WiFi will work from Arduino and is easy, but I think you want the stability of a USB connection
  • Raspberry examples work and you can power the THETA from the same USB cable that sends commands. The RPi can power the THETA for taking pictures indefinitely.
  • You can send WiFi API commands over the serial cable from the Arduino to a plug-in, but this is only for “technical prototypes”

Current Recommendation

In order to get something working, I would try the Raspberry Pi and the RICOH THETA USB API. Once you have it working, you can either fine-tune it on the RPi or try another platform.


If you want to play around with the serial port, there are many examples of taking a picture from the serial port. Here’s a snippet. There are full code examples. Be aware that this strategy will not work unless the “serial port” of the camera is enabled with Vysor.

int     ThetaAPI_Post_takePicture(void)
{
  int iRet=0;
  
  iTakePicStat = TAKE_PIC_STAT_BUSY;
  
  String strSendData = String("{\"name\": \"camera.takePicture\" }");
  String strJson = ExecWebAPI("POST", "/osc/commands/execute", strSendData, HTTP_TIMEOUT_NORMAL);
    
  iRet = strJson.length();
  if ( iRet != 0 ) {
    char sJson[iRet+1];
    strJson.toCharArray(sJson,iRet+1);
    StaticJsonBuffer<200> jsonBuffer;
    JsonObject& root = jsonBuffer.parseObject(sJson);
    if (!root.success()) {
      //Serial.println("ThetaAPI_Post_takePicture() : parseObject() failed.");
      iRet=-1;
    } else {
      const char* sState  = root["state"];
      String strState = String(sState);
      //Serial.print("ThetaAPI_Post_takePicture() : state[" + strState + "], " );
      if ( strState.equals("error") ) {
        const char* sErrorCode = root["error"]["code"];
        const char* sErrorMessage = root["error"]["message"];
        //Serial.println("Code[" + String(sErrorCode) + "], Message[" + String(sErrorMessage) + "]");
        iTakePicStat = TAKE_PIC_STAT_DONE;
        iRet=-1;
      } else {  //inProgress
        const char* sId = root["id"];
        strTakePicLastId = String(sId);
        //Serial.println("id[" + strTakePicLastId + "]");
        iRet=1;
      }
    }
  }
  
  return iRet;
}

Wow really appreciate this very thorough info!
I agree that for now it does seem like the rpi is the way to go. I might play around with that serial a little bit more just because I’m curious, but yeah we’ll likely just try to do the Rpi USB commands and connect some sensors to the pi

Thanks so much, will keep you posted!

1 Like

Able to get into the system with Vysor, and i can see the developer option i should choose to send those fake wifi commands, but anytime i choose anything other than PTP or Audio Source, the system just switches immediately back to PTP
odd!
(again, i should probably just be getting the RPi going, but this is a tricky enigma!)

You need to run a plug-in on the THETA V to handle the serial communication

The screen below is shown after the Arduino device is plugged into the THETA. The Vysor connection is with WiFi.

image

Another example (not Arduino), but shows serial plug-in.

This is what we’re using

i have given up on the Arduino approach and have been thrashing through getting a Pi zero w going on it all day. Im getting close :slight_smile:

I can make the camera take photos and videos remotely
but the only thing i still cannot do is wake it up from sleep.

I could do this with an Arduino emulating a keyboard and send a simple keystroke. Does anyone know of a simple easy way to either

  1. use ptpcam or gphoto just to wake up the theta?
  2. use the RPi to send a simple keyboard stroke to the usb of the theta? (this wakes it up when an arduino does it)

also side note:
when you are hooking up the Pi Zero to the Theta, it appears to make a difference how you connect the OTG cable

That is, for me, i HAD to have the otg cable connected to the pi, and a regular USB cable to the theta for it to work (it was the opposite with an Arduino)

1 Like

Ahhh dang, i think i have finally reached the final dead end.

I don’t think there is a way to
A) Remotely wake up the theta
and then
B) trigger it to take photos

in any kind of autonomous (especially low-power) way

In my mind i could have used the Keyboard stroke trick + the PTP of the rpi, BUT the OTG cable needs to be connected the opposite way for both of these approaches (which is bizarre to me, i always thought the OTG cable was just the 4 wires going to a different header, but for some magic reason it seems to make a difference!)

Has anyone successfully woken up the camera with a Pi-zero’s bluetooth, and then triggered it for photos?

ahhh i might have to abandon the Theta as a possible camera for this, which is too bad because it definitely seems feasible, but there are strange road blocks at every corner it seems :frowning:

Have you tried this:

https://developers.theta360.com/en/docs/v2/usb_reference/property/sleep_mode.html

1 Like

I have tried this, it does not do anything unfortunately. I can GET the report of it is in sleep mode, but i cannot SET the mode

1 Like

Thanks for checking and reporting back.

I use Theta V with raspberry pi. Gphoto works fine except for the shutterspeed ( you need to compile).
Theta wakes up when the raspberry pi starts and you can use the power off for theta. I think (i will try) a reboot of the pi will wakes up the theta V.

2 Likes

@Hugues, thanks for this insight.

@quitmeyer, you should check out the project FOX SEWER ROVER by Hugues. It might be useful in your classes as well.

Neat robots!
and that’s great to know that the RPI turning on can wake up the camera

i wonder what kind of signal it is getting from it that does it, and if I can emulate

For the camera trap i probably won’t be able to wait the boot time for the RPI
so this is what i am up to now

Good ol servo pressing a button

2 Likes

Cool video! Does the length of the button press with the servo matter? Can you control that?

oh totally, this was just a quick test, i can control every bit of it very easy.
Basically i will have the Teensy send a virtual mouse click to wake up the Theta, and also have the servo move slightly to trigger it
i should be able to go from Sensor reading at PIR to photo captured in 1/2 a second (the goal against other camera traps right now)

1 Like