uCAM III-application (including TCP- and HTTP transfer)

I’m using the uCAM III from 4D Systems on a Particle Electron. The end goal is to take two pictures a day, and upload them to a webserver, For the time being though, I have limited my efforts to just taking a picture locally and sending it over serial.

I use this Arduino library. Note that although it is designed for the uCAM II, there is backward compatibility so whatever code works on the II should also work on the III. Please note that my understanding of electronics and coding is pretty limited; I made an attempt with running this library in the Particle IDE, and found that the #include ‘SoftwareSerial.h’’ in the .h file is invalid with Particle products.

However, I could use some guidance on how to proceed from here. A lot of the commands in the .cpp and .h files are serial commands, and my understanding of things is too limited to really know how to mitigate this after taking the #include SoftwareSerial.h out

1 Like

I’m short on free time lately but the camera operates over UART serial, that’s how it receives commands and sends the picture data back.

@ScruffR @peekay123 @rickkas7 may be able to help us out here as far as how to handle the SoftwareSerial on the Electron.

1 Like

I found this Particle ucam2 library.

1 Like

I have written a ParticleSoftSerial library that should be able to substitute Arduino's SoftwareSerial for baud rates up to about 38400. With one of the latest features added in 0.8.0 to reduce interrupt latency even 57600 should and 115200 may be possible (when I get time to incorporate that).
Since this library is interrupt driven, you are limited to pins that are interrupt enabled and available for RX.

But having said that, SoftwareSerial is mainly meant to be used when there is no (free) HW serial interface. If you have, use that. It's just that much more reliable - especially at higher baud rates.

1 Like

So by including ScruffR’s library, the .cpp and .h files compile just fine now. Not sure if it actually works or not, but at least it compiles.

Now to set up a test .ino file…

This is what I have at the moment: https:/go.particle.io/shared_apps/5aa18db9a96412101b000016
Right now it’s outputting some compiling errors (UCAMII, camera, stateTime and mySerial don’t name a type)

your class is named:

class UCAMII {

you are trying to instantiate and object with a different spelling:

uCAMII camera;

your setup() function appears to have mismatched curly braces…

void setup() {
    mySerial.begin(38400);
    Serial.begin(38400);
    Time.zone(-8);
    if (camera.init()) {
        camera.takePicture();
        mySerial.print("Image size: ");
        mySerial.println(camera.imageSize, DEC);
        mySerial.print("number of packages: ");
        mySerial.println(camera.numberOfPackages(), DEC);

        while ( bytes = camera.getData() ) {
            for (x = 0; x < bytes; x++) {
                mySerial.print("0x");
                mySerial.print(camera.imgBuffer[x], HEX);
                mySerial.print(" ");
                }
            mySerial.println("");
            }
        mySerial.println("done downloading");
        }
    }
    stateTime = millis();
    mySerial.println("setup complete");
}
3 Likes

Oh right of course!

Well, it all compiles just fine now, so I will try and see what I can get out of this now.

EDIT: For now just a red SOS-code (one blink; hard fault, so assume the code is not yet on par)

I have this right now: https:/go.particle.io/shared_apps/5aa2d22ba96412ec6600156d

Compiles fine, when it runs it shows the SOS-code for a Hard Fault (bad code I assume).

@ScruffR He switched the Arduino example code that used Arduino’s SoftwareSerial to the ParticleSoftSerial which did get the library to compile.

But what you recommended is to skip using the SoftwareSerial completely if you have an extra hardware serial port available because it’s more reliable.

Since the Electron has 2 UART ports he should be able to skip using the SoftwareSerial library and go for the more reliable hardware serial port correct?

I don’t have any free time to sit down and mess with this and I don’t have the camera but if you have some free time could you take a look at the latest code he shared and let us know what you think is best for trying to get it to work on the Electron?

@Vitesze Have you tried this library from last year that says it’s working with the camera module + Photon to see if it runs fine?

2 Likes

Yes I included the ParticleSoftSerial requirement and replaced SoftwareSerial commands with ParticleSoftSerial commands. Thanks for all the help, not sure how I can make it worth everyone’s time, but whatever comes out of this project I will publish it on the forum afterwards as I think it’d be a very interesting application for the Electron.

I have briefly looked through that library, but I will work on it some more now

I don't think you need the software serial library at all and can go for the more reliable hardware serial on the Electron. Need ScruffR's advice on that though.

I don't see any reason this can't work the way we're wanting it to though, just will take some time to work through all this.

That makes sense, I should read some more about the serial stuff on the Electron though so I understand everything better.

If you would like to mess with this yourself as well, I can send you an uCAM III :slight_smile: Mine arrived within 4 days.

I could have a look, but without the hardware especially the mentioned SOS panic won’t be easily found :blush:

Kind offer, but if @ScruffR is open to helping out it may be better to send him a camera to work with.

1 Like

@Vitesze I had a chance to take a look at that uCam2 library that was supposed to work on the Photon.

I altered this library removings parts that we don’t need for now.

The code will attempt to take a snapshot and then a full picture when you pull pin D1 high to 3.3v so try that and watch what the serial output says about successfully taking the picture or not.

If it says it successfully takes the picture then we will need to change the code where attempts to send the picture data to a IP address so it does what we want it to do.

1 Like

Thanks! Will look at it today :slight_smile:

I have written a completely new uCamIII library which should also support uCamII (just some advanced functions aren’t supported by the II).
One major difference to the Arduino uCamII library is that mine is not tied to any serial interface but can be used with any of the HW interfaces and ParticleSoftSerial too.

If you could try the uCamII and the Webserver example on a Photon, I’m open to suggestions how to improve it.
Electrons can’t easily be used as Webservers (due to “non-routable” local IP), so currently on Electrons the demo can only stream the taken image to USB Serial where you need to dump the stream into a file (or any other sink) to further process it.
Next step will be a TCP transfer sample that can also be used to receive the data wirelessly from an Electron.

5 Likes

Great work!

This can finally be a reality :slight_smile: @Dave

image

I received the camera also and its images are good enough to be useful.

I’ll give your code a try on the Photon.

What I’m wondering is if we could store the picture data on an Electron in a variable array instead of pushing it to a SD card for storage. Even if there is enough room to store only 1 picture that would be fine, I know memory is limited.

Then we could use @rickkas7 FTP library to upload that picture data array to an FTP server which I know works because I’ve tested it in the past with success.

What are the possibilities of this?

2 Likes

I had a look at @rickkas7's FTP endeavour but his assertion about FTP being a "bitchy" protocol with lots of overhead, made me decide to rather go for a simpler demo more along his line of this

or any other TCPClient -> node server route.

My sample just stuffs the image in a static array of 160x120x2 = 38400 byte (max size for raw images produced by uCamIII - even 640x480 JPG won't be as big as that).
But with bigger projects that might not be the way to go.

3 Likes

@ScruffR Just tried the Photon demo and it’s really simple and works every time! :tada::camera::tada:

Really nice that this can be setup and you can just call the function remotely to have the picture taken and displayed on a local browser.

Less overhead on the Electron would be ideal, although I’m not sure how much overhead we would be talking when just uploading these images using his FTP library.

Looking forward to trying your Electron sample program :slight_smile: