Programmed file transfers... is it possible? - page 2 - General Help and Assistance on using CHDK stable releases - CHDK Forum  

Programmed file transfers... is it possible?

  • 18 Replies
  • 9043 Views
Re: Programmed file transfers... is it possible?
« Reply #10 on: 19 / February / 2012, 19:00:24 »
Advertisements
Attached to this post is the full source of my project so far. Everything right now is controlled over serial. Make sure your serial terminal is setup at 115200 baud. Here are the commands I have implemented and working. Enter the character at the serial terminal.

C triggers a capture
Z zooms in one step, X zooms out one step
R puts the camera in record mode, P puts the camera in play mode. The initialization routine puts the camera in record mode by default.

Each command is followed by a 5-second delay. I think I need to add some camera status checking or something to make sure I'm not sending commands on top of each other or while the camera isn't ready.

It's a little messy and a little kludge-y right now. I'm still working on file transfers. What you see here in the source is what I've got. Hopefully though this will help.

Re: Programmed file transfers... is it possible?
« Reply #11 on: 14 / March / 2012, 01:21:01 »
Thanks so much nightmare75. I have a similar setup trying to control a SD4000IS. I got your code working but all I got from the serial response was:
Quote
Command received. Triggering capture!
CTransaction: Command block send error: 000D

I figure this is because I am not powering the VBUS with 5V. Did you have to supply the Arduino Pro Mini with 5V to the raw pins and then send that to the VBUS on the host shield? I have already soldered the boards together with the Arduino on top. The method calls for cutting the trace in the VBUS jumper pin. Did you have to do that then?

I really hate desoldering.

Again, thanks so much for the code!

Re: Programmed file transfers... is it possible?
« Reply #12 on: 14 / March / 2012, 22:36:15 »
Yes, I had to provide 5v to VBUS. I made the same mistake you did and soldered my Arduino on top of the host shield. I tried desoldering, but I ended up pulling some of the pads clean off of the Arduino board. These small Arduino boards are built cheaply and they are going to be tough to desolder. I ended up buying a new Arduino board. My USB host shield came out fine though.

I would make sure you know that that is the problem before you go desoldering things, though. When you start up the program, you should see some output in the serial terminal along the lines of PTP Init and some other miscellaneous initialization things (can't tell you exactly what, I don't have the stuff with me right now). It should also say Camera Connected at some point. That's when you know that the camera and the Arduino have shook hands and formed a PTP session.

Does your camera react at all when you run the program? My camera goes into a USB mode when it acknowledges the Arduino as a host, I'm assuming yours should as well. If it doesn't react at all when you connect the Arduino running a program, that would indicate to me either that everything is not connected right or that it needs to sense 5v on VBUS to acknowledge the host. I was led to believe that most cameras wouldn't care about getting 5v on VBUS since they are self powered, but mine needed it and yours also might.

Try running one of the example sketches out of the PTP library (PTPDevInfo is good and should work on basically any camera). If that doesn't work, it's probably worth trying the 5v VBUS mod on the host shield. Here's the link to the hardware manual in case you need it:

http://www.circuitsathome.com/usb-host-shield-hardware-manual

Small progress update, I have managed to get file transfers going. However, it takes about 11 minutes to transfer a 1.5 MB picture file and dump it to the serial terminal. The limiting factor, I think, is the speed of the Arduino. I'm not sure if there's any way to make file transfers go faster short of using a faster microproc or USB interface chip.

I also tried transferring a thumbnail, but a PTP request for any thumbnail returns a "no thumbnail exists" type error. I thought the thumbnail's existence was specified by the PTP spec, but maybe that isn't correct. My question then is this: is it possible to generate a thumbnail, either by PTP command or using Lua? A thumbnail image is going to be significantly smaller than a full 8MP image and I'm hoping it can be transferred quickly enough to meet my needs.

Any ideas?

Re: Programmed file transfers... is it possible?
« Reply #13 on: 15 / March / 2012, 06:57:49 »
I also tried transferring a thumbnail, but a PTP request for any thumbnail returns a "no thumbnail exists" type error. I thought the thumbnail's existence was specified by the PTP spec, but maybe that isn't correct. My question then is this: is it possible to generate a thumbnail, either by PTP command or using Lua? A thumbnail image is going to be significantly smaller than a full 8MP image and I'm hoping it can be transferred quickly enough to meet my needs.
Any ideas?

On some cameras it only works in Playback mode.
On other cameras it may not work at all.


Re: Programmed file transfers... is it possible?
« Reply #14 on: 16 / March / 2012, 00:59:45 »
Does your camera react at all when you run the program?

No. I did the same thing. I just ordered a new Arduino Pro Mini and a USB host shield and will try again. I tried loading the PTPDevInfo example, and nothing. I though that maybe I could just give the Vbus wires a 5 volt source and everything would work. I guess I learned that the Vbus is called a bus for a reason.

About your transfer speed, that is slow. At 115200 baud, that should work out to 14.4KB/s. Even with overhead, you should be able to transfer that file in around 2 minutes. Odd.

Re: Programmed file transfers... is it possible?
« Reply #15 on: 20 / March / 2012, 20:27:47 »
Nightmare75, I have a quick question. I am about to attempt this again with a new Arduino and USB Host Shield. The instructions on the Circuits@Home site say to cut a trace in the board. How do you know when you have successfully cut the trace? I am a little nervous about doing this.

Another thing. For faster transfer speeds to might want to consider something like the Raspberry Pi (when it is finally available). Since it is a fast little computer I am sure you will get much better speeds and there is software like gPhoto2 that can call PTP commands.

Thanks for the feedback.

Re: Programmed file transfers... is it possible?
« Reply #16 on: 20 / March / 2012, 21:25:46 »
Nightmare75, I have a quick question. I am about to attempt this again with a new Arduino and USB Host Shield. The instructions on the Circuits@Home site say to cut a trace in the board. How do you know when you have successfully cut the trace? I am a little nervous about doing this.

I'm fortunate enough to have a workspace with a bunch of useful equipment, including a microscope. I cut my trace and verified that it was cut by looking at it under the microscope. Failing that, I don't know. The trace is small and it isn't very deep and it didn't take much pressure to cut it. I'm not sure if there's anything underneath it, but I wouldn't worry too much about applying too much pressure. Sorry I can't be anymore helpful than that.

Another thing. For faster transfer speeds to might want to consider something like the Raspberry Pi (when it is finally available). Since it is a fast little computer I am sure you will get much better speeds and there is software like gPhoto2 that can call PTP commands.

While I'd love to, I don't have the time to wait for a Raspberry Pi to become available. It also takes more power to run than my Arduino, which is important because I'm going to be running the system on batteries. I'm fairly sure the bottleneck on the transfer is the Arduino itself. It's only an 8 MHz processor. I haven't done any real hard looking at it, but my guess is that 8 MHz is too slow.

On some cameras it only works in Playback mode.
On other cameras it may not work at all.

Thanks for the suggestion. It looks like the thumbnail only exists on my camera if you're in playback mode. However, when I'm in playback mode, I get some strange behavior when I request a list of file handles. Most of the time, when I request file handles, the lens retracts, the screen shuts off, and the camera stops responding to button presses, including the power button. I then have to pop the battery to get the camera to shut off. The camera doesn't completely lock up though, as I'm still able to request file information and transfer the thumbnail off of the camera. The camera appears to still be responding to some software requests from the Arduino, but not all. After it shuts off the screen, it will still do file operations, but it won't go back to record mode or anything like that.

I'm able to transfer thumbnails off the camera and it's actually fairly quick, something like 10 seconds for one thumbnail. That's definitely something I can work with. The problem is that the process for requesting the thumbnails makes me unable to take anymore pictures until I manually reset the camera.

Any ideas on why this might be happening? Is it a camera thing, a CHDK thing, or is it something with my code/my PTP implementation?

Re: Programmed file transfers... is it possible?
« Reply #17 on: 26 / April / 2012, 19:47:29 »
I'm going to post my final code release here. The project I was working on was a success and it is ending with the school year. I was able to successfully trigger captures and transfer photos using an Arduino, and with the help of an Xbee radio, I'm able to do so wirelessly from about 150 feet away.

The attached code should be looked at as an example more than anything. It was written to do what I specifically needed done. The program watches the serial port for single characters and performs commands based on what character was entered. Picture transfers are done by dumping the bytes I get from the camera straight to the serial port. A Windows program then collects the bytes from the Arduino and turns them into an image. I didn't write that part of the project and as such I can't give any real details of how it was done. I'm pretty sure that functionality is built into the Windows Forms library in C#, but don't quote me on that.

The code attached relies on the PTP and USB Host Shield libraries from www.circuitsathome.com. I used the Arduino IDE version 0023 while building this. I understand that newer versions of the IDE have made some changes and the code may not be 100% compatible, though it shouldn't take much effort to make it compatible.

I will no longer have the camera or the Arduino, so I won't be able to do any more development on this. However, I am still subscribed to this thread, so I should (hopefully!) be able to answer questions about it, should they arise. I'm afraid my code isn't terribly well commented (sorry!), so I wouldn't be surprised if some questions come up.

I hope some people find this useful. As it turns out, interfacing and Arduino with CHDK isn't terribly difficult because most of the difficult code has been written already (i.e. the PTP library).


Re: Programmed file transfers... is it possible?
« Reply #18 on: 28 / April / 2012, 10:36:50 »
Many thanks for that.

It is of great interest but, of course, I just don't have the time to try it right now.

Check the forum occasionally, especially your personal messages.


David

 

Related Topics