Help with porting an Arduino library


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


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.


I found this Particle ucam2 library.


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.


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:
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() {
    if (camera.init()) {
        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(camera.imgBuffer[x], HEX);
                mySerial.print(" ");
        mySerial.println("done downloading");
    stateTime = millis();
    mySerial.println("setup complete");


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:

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?


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.


@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.


Thanks! Will look at it today :slight_smile: