Smartphone Controlled Timelapse Camera Using Raspberry Pi

So! SDCC is a great opportunity to show people just how MASSIVE nonprofit fan events can be. I wanted to show some friends what I couldn’t accurately describe in words or still shots. To do this in a function way I decided to make a timelapse body cam to see what I see when I walk around con. It needed to have on off control so I could stop recording if I decided to go to a panel. So the plan was to cobble something together from what I already have. In this case: A Pi Zero W, Pi mini camera, and external battery pack. The whole setup would be controlled by my phone on a wireless access point generated by the Raspberry Pi.

(Quick note: This means the RPi is generating a wireless signal that other devices can connect to. In this case a wpa secured connection my phone can hook into to control the pi and camera.)

Of course I decided this… The day before I was set to fly. Bonus points: I wasn’t taking my laptop because it’s heavy and I’m lazy. So, I had a night to pack and put together what should have been a simple project.

Spoiler: It was not and I was wrong. What followed instead was of course a comedy of errors which I’ll detail, and then follow up with what ACTUALLY worked out so you can hopefully replicate the end success without the chaos.

So! My friend got real hype about getting body cam timelapse, so he pulled out some quick links he thought might make it a trivial task!

They are as follows:

https://learn.adafruit.com/digital-free-library/configure-access-point

https://www.raspberrypi.org/blog/piui-control-your-pi-with-your-phone/

https://computers.tutsplus.com/tutorials/creating-time-lapse-photography-with-a-raspberry-pi–cms-20794

I want to preface by saying there is nothing WRONG with these articles. In truth I never made it to article three, and the first two – while useful primers on wireless access points – are out of date.

First hilarious failure: You can control an RPi through any network it’s connected to without needing a monitor and keyboard on the RPi. A Zero W has a built in wireless port, and no other connection. I would have to turn this OFF in order to change it to an access point. A Zero also does not have a full size HDMI port and I don’t own an adapter.

Cue Rea frantically dissecting his 3D printer’s brain because it was an RPi3. An RPi3 is bigger, but it has two networking ports and a full hdmi port. This meant I could control it while the wireless port on it was turned off.

From the photos, you can tell the big Pi 3B has an ethernet port on it, which is necessary for the initial setup. It also has two ribbon cable ports, one marked camera, and one marked display. The Pi Zero W has on the other hand, no ethernet port and one ribbon cable slot. Both have wi-fi chips on them though, so both can make a wireless access point, and all pieces are the same, so you can swap an SD card image between the two with no real problems for hardware that’s common between both boards.

Great! Now to follow my guides! Except… they’re outdated and don’t work. And suddenly the system isn’t even acknowledging it has a wireless port. My first instinct is that I royally fucked something. So! RPis are a nice platform because you can wipe the OS and start again in about ten minutes.

So I wipe the SD card and re-image an OS onto the system. Then I… try again and it does it again. I can’t figure out why it’s doing this, and between the two attempts and cobbling everything together it’s now almost nine. So I call in the big guns.

The big guns are my brother in trash and owner of possumtrash.com . He is FAR more competent on network stuff, so I ping him. Over text he can’t really diagnose the system, so he wants to set up the Pi to SSH in.

(Note: SSH is a secure shell connection routine to let you access and control one computer through another. I had already been locally using ssh to set up the system through the RPi3s second network port.)

Now! A local SSH is easy. Local meaning everything is on the same network/wifi. However, he lives about thirty minutes away with his lovely wife and three cats and two dogs. This means more work is required. I’ve never set up a non-local ssh. It is spooky and a whole new undertaking on its own.

A network ssh involves opening up ports on your router to the greater internet. It is generally not a good idea, because the internet is full of scripts constantly trying to ping on open ports. Port 22 is especially spooky because that is a general computer data port for ssh. IF you open something for SSH it’s important to have the proper security measures in place.

Have nonstandard login info for the computer system and router, as well as ssh access keys. In this instance, I was opening ssh for one particular system, the RPi. So I gave it a set address and made a second user for nonlocal ssh.

This is where we get into access keys. Access keys are a handshake of sorts to prevent randos from getting into your system. You make a private and public key. The server – in this case the RPi – gets the public key, and he uses the private key to show he can get in. Sorta like in prohibition movies how they flash their lapel pin to get into the speakeasy.

So! I get the key, put it in the new user folder .ssh and forward port 22 to the RPi, effectively opening it up for the spooks of the internet.

It doesn’t work. Hilariously I forgot I had masked the house internet to stupid extremes, half by accident and half on purpose. The original house owners I’m renting from have a router, but it is Bad, so I hardlined my router into it so I could do RPi networking more easily.

However I hadn’t forwarded port 22 from the other router, so it never even made it to my router. So I went into the spooky basement and hard swapped some cables so there router didn’t block me.

It still didn’t work.

He talks to my system by talking to my external IP address. Unbeknownst to me, taking out the old router changed my IP. So I get him the new router IP.

Success! It is now ten o’clock and he begins troubleshooting. I sit on my thumbs and then start packing.

At nearly eleven he loses ssh connection. I lose ssh connection. Neither of us can talk to the RPi and we don’t know why. We both have work the next morning, so he calls it a night. I contemplate flashing a clean OS again.

Instead I rip up my playstation hdmi cable and plug the thing into my TV, as it is my only other monitor. It boots up, fails to load the wifi server, but it IS trying. A little more poking shows that following the guide was shutting off ALL network ports, not just the wireless one we were trying to turn into an access point.

At nearly midnight my buddy (who should have been sleeping) sends me a link for a different networking guide. I have been ripping up and slowly repairing the systems that were failing, and also re-enabled network ports. The link he sent is:

Final Tutorial Used

This is the one that ultimately works, but at the time I couldn’t make it work either. In the middle I had installed a camera control web interface to take care of the timelapse portion:

Camera Web Interface

Which created a web interface. The web interface worked, but wouldn’t show the camera feed. I gave up about 2 AM and went to bed.

The next morning I take my packed bags for con and a mass of RPi testing gear and cables to work with me. I mentioned the RPi to other coworkers, who got real excited and decided to take a look. They spent a good hour futzing with it before realizing the issue was… A typo in the config file. They introduced another typo while fixing mine and took another half hour to figure that out.

The camera still doesn’t work, but the access point does! At this point my buddy gets into work, and I share the pain by gifting it to him to figure out the camera. I then proceed to send him about five links to possible fixes and ten suppositions of what the error is.

Another hour goes by and he realizes… We were putting it in the wrong ribbon cable slot. There were no software issues with the camera.

About five of us stand around for a bit feeling very dumb.

Time to move everything from the RPi3 to the Zero W! This part is relatively painless. The entire system memory and operating system is on a microSD card, so I take the card from the RPi3 and plug it into the Zero. The camera we were testing with is bigger than the one I wanted to use, but should be compatible from a driver perspective, so I hook the smaller one into the Zero camera ribbon cable port.

Turn it on and…

SUCCESS

There are no compatibility issues and the system plays perfectly! Of course, I flew with it without a proper case, so I cobbled something together out of a base 3D printed case I had on hand and scotch tape and receipts…

If you want your own, simpler instructions and a parts list is below. Feel free to ask if you have any questions, cause as you can see, even folks that are paid for this kinda stuff make an absolute mess of it.

Parts List

  • Raspberry Pi Zero W or Raspberry Pi 3
  • Raspberry Pi camera (I used this one)
  • microSD card with at least 8GB
  • External battery (like this)

This quick guide is for peeps who want to be a little more hands on and get into the system guts. To start with, for these tutorials I recommend having a monitor and keyboard to plug into your Pi, or else is gets a little hairy.

First thing is first, initial Pi Setup. First you download the Raspbian Stretch Lite image from here. And use an SD card imager like Win32DiskImager to flash the image to an SD card. This will erase everything on the card currently, so make sure there’s nothing you still want on it. Once that’s done, you need to go into the boot drive it shows up as. (Don’t mind the disk size discrepancy, the SD card partitioned into two drives. One that’s the readable boot, and one that Windows thinks it has to format.)

Go into the boot file and add a blank file called ssh with no file extension on it. You might need to turn on file extension visibility if you haven’t ever done that before. This just turns on ssh, which you’ll want anyway and is a default step whenever I make a new RPi SD card. Take that SD card and stick it in the Pi.

At this point you take your lovely camera and its ribbon cable (if your camera has a USB plug in, you have the wrong camera) and hook it into the Raspberry Pi camera port. An RPi3 has two ribbon ports, so make sure you put it in the right one (it’s labeled camera).

Now you can hook it up to power, a monitor, and a keyboard and you can watch the system boot up. It will ask for login info. Standard login is username: pi password: raspberry. I’d recommend changing that for security reasons. At this point you’re in the pi and ready to follow the Web Interface Tutorial.

Web Interface and Timelapse Tutorial

Once you got that working happy and good to go, you follow the Access Point tutorial.

Wireless Access Point Tutorial

Wambam you have made your very own system! If you get hung up somewhere or feel lost, feel free to ping me. My hope is to help total Pi noobs start playing with them, so really don’t be afraid to ask!

Published by

Reakain

Your friendly raccoon frand

Leave a comment