0

I am doing a project using Arduino UNO, cc3000 WIFI chip, micro SD card shield, and a TTL serial camera in order to make a security system that will post a picture online (not enough processing power for video) when motion is detected on the camera.

Thankfully, the hardware works after a few shortcomings, but my program seems to be taking up 97% of the Flash storage.

Also, I am looking for a better way to transfer the image than saving it 32 bits at a time and then waiting about 10 sec so the HTTP request will send it to the server.

One thing I do know is that I have tested all the hardware and those functions are working. My problem is in the logic.

Any help appreciated! (Image is around 13KB and UNO only has 2kb of dynamic memory).

My full code is here: https://www.dropbox.com/s/arxa253mxwvqtg1/HomeProj.rtf?dl=0

void loop(void)
{
    cam.setMotionDetect(true);

    while (1) {
        if (cam.motionDetected()) {
            Serial.println("Motion!");

            cam.setMotionDetect(false);
            if (! cam.takePicture())
                Serial.println("Failed to snap!");
            else
                Serial.println("Picture taken!");

            uint16_t jpglen = cam.frameLength();
            Serial.print(jpglen, DEC);
            Serial.println(" byte image");

            char filename[13];
            strcpy(filename, "IMAGE00.JPG");
            for (int i = 0; i < 100; i++) {
                filename[5] = '0' + i/10;
                filename[6] = '0' + i%10;
                // create if does not exist, do not open existing, write, sync after write
                if (! SD.exists(filename)) {
                    break;
                }
            }

            File imgFile = SD.open(filename, FILE_WRITE);
            while(jpglen > 0) {
                uint8_t *buffer;
                uint8_t bytesToRead = min(32, jpglen);
                buffer = cam.readPicture(bytesToRead);
                imgFile.write(buffer, bytesToRead);

                //Send Request
                Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
                if (client.connected()) {
                    Serial.println("Connected!");
                    client.println("POST /upload HTTP/1.0");
                    client.println("From: Arduino");
                    client.println("Host: fierce-chamber-5675.herokuapp.com");
                    client.println("Content-Type: image/jpeg");
                    client.println("Content-Length: " + 32);
                    client.print("Connection: close");
                    client.println();
                    for(int i = 0; i < 32; i++) {
                        client.print(buffer[i], HEX);
                    }
                    client.println();
                } else {
                    Serial.println(F("Connection failed"));
                    return;
                }
                client.close();

                Serial.println(F("-------------------------------------"));
                jpglen -= bytesToRead;
            }
            imgFile.close();
            cam.resumeVideo();
            cam.setMotionDetect(true);
        }
    }
}

1 Answer 1

1

You are running a wireless TCP stack, an SD card interface, and a web camera with some sort of motion detection, on a less than $20 computer? I think you should congratulate yourself and move on to the next project.

I believe you are asking too much to add more to it. At $20 a pop, I would think about adding another UNO if you really do want to add more functionality. Let the 2 talk via serial, with one processing the video, the other processing the wireless. The TCP part uses a considerable amount of resources, both memory and processing power.

4
  • Dude its not $20, its $35. I ran out of pins and had to buy a micro SD card shield. Its tough getting enough money when you are a 14 yr old. But I get your point. Still, I want to try and get this project running because I want to install it in front of the house as a security system. Mostly just about saying, "I did that," and applying prior knowledge to real life application.
    – Kharrid
    Apr 16, 2015 at 21:56
  • 1
    sparkfun.com/products/12757
    – user6569
    Apr 17, 2015 at 19:11
  • Instead of using HTTP you could write your own TCP/IP server on the host. Good practical learning experience. You should be able to reduce the 10 second latency by avoiding the overhead of web. Google TCP sockets. I understand you resource concerns. My present Arduino project is at 94% capacity.
    – user6569
    Apr 17, 2015 at 19:17
  • The other thing is it is best to let your loop function get called from the Arduino software, instead of looping itself. That way housekeeping can take place. Move the setMotionDetect to setup. Maybe not doing it that way is leading to some additional delay?
    – user6569
    Apr 17, 2015 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.