Wednesday, August 6, 2014

Arduino + Raspberry Pi + servo + camera

Arduinos were one of my purchases this summer. With our free time before school starts here in Pakistan, I've ripped through the whole tutorial book and started my first project.

I've got the Raspberrypi set up to take time-lapse photos, something that I wrote about a few months ago. Now I have an Arduino kit that came with servo-motors so I can add motion to my time-lapse.

I have two separate scripts running. The Arduino language looks like Java and if there are any differences, I can't spot them. I re-wrote some of the tutorial code for the servo:

#include <Servo.h> // servo library

Servo servo1; // servo control object

void setup()
{
servo1.attach(9);
}

void loop()
{
int position;

for(position = 0; position < 180; position += 1)
{
servo1.write(position); // Move to next position
delay(10000); // Short pause to allow it to move
}
}

I don't know Java very well, so the tutorials were great. The electric circuit side of the Arduino was easy thanks to Mr. Rutherford's 7th grade class. I've only spent an hour or two with Java, but you certainly don't need to learn it too in depth for simple projects like this.

So now I have a servo that is turning 1 degree every 10 seconds.

I adjusted my Pi's camera script to snap a picture every 10 seconds too. It is written in Python:

import os
import time

i = 0

while i <= 200:
imageNum = str(i)
os.system(“raspistill -o image%s.jpg”%(imageNum))
i += 1
time.sleep(10)

I do need to adjust the code to dump the pictures onto a usb drive...it would save me one step later, but the script is simple and works as is.

Here is the set-up.
(yup, the camera is upside-down...but it is easier to fix in post)








Yes, I am running the Pi off of a portable USB quick charger. These are marketed as phone chargers, and that is why I bought it. This little experiment shows that it has the power to run the Pi and the camera, but is probably not a great long term solution. The USB charger is also being charged... it is like a lil UPS system, which is necessary in a city where the power goes off every few hours due to 'load sharing' and the generator (we are lucky to have one) kicks in 2 minutes later.

The box is just that, an empty box. I attached the pi camera with two little screws and hooked it to the servo motor arm with a stripped twist tie.

To keep it steady, my pocket knife held it down.

Not too fancy, but I didn't have to buy or fabricate anything for the set up.


After hitting the 'upload' button once, I was able to unplug the Arduino from my computer. Every time I re-attached the battery, it started the code again (back at 0 degrees, headed for 180 over 30 minutes), I just had to start the Pi code quickly thereafter. I did that through VNC and snapped pictures of our living room. Test pictures are boring, but I want to check how it looks and how the timing is between the two scripts.
I'm also not going to post a time-lapse of a panorama of the living room while Janet and I read on the couches.

I adjusted the servo to move once a minute, aimed the whole mess out our window and ran it again. In case you were curious, but didn't want to do the math:
Servo turns 1 degree every 60000 mS so 60 seconds I believe
picture every 10 seconds = 6 at each degree.
180 degrees = 180 minutes = 3 hours of camera time.
180 degrees *6 = 1080 pictures
30 frames a second in digital videos = 36 seconds of video.


That video will be added tomorrow.  You may have caught  my bug, i <= 200
so I only got 201 pictures today:


Monday, August 4, 2014

Day 1 in Lahore...First 12 hours really.

We moved to Pakistan.

We were hired to work at Lahore American School back in December and now we are here.  We have done more in the past 12 hours than we did during the first week in Hanoi.  We were picked up early this morning (3:30am)  by our head of school and Sultan, who we have learned will be taking care of things like internet access(#1 priority) and all other settling in needs.

We arrived at our house in Swedish Flats and were greeted by Danny and Francis, who will be our house-hold staff and driver. We hired them over Skype with the help of a former principal, best decision we have made so far.
We had unpacked in an hour, set a few things out and then got our first taste of Star World programming in three weeks!  Masterchef Australia!  A nap later and Francis and Danny were back at noon to take us shopping.

It is because of their help that we are so settled in already.  We didn't need to learn anything about the city on our own, we stopped by LAS to get our id badges started, changed some money and went shopping.  El Fatid, the store, had everything and much more.  There is a lot more on offer at the stores than in Hanoi, and we were not in a store that caters to expats only like some of the specialty places in Hanoi.  We had carts full of food, cooking and kitchen supplies, towels and other things we needed.  4 guys manned the check out line and had everything bagged up with precision quickness.  We had paid for dishes upstairs earlier and everything was delivered to the car.  Yes, LAS set us up with a car.  I would have been completely confused and not trusted the system that I didn't understand. Luckily I just had to follow Francis's directions and everything went smoothly.

In many other countries stores over employee people.  This was the first time I've seen over-employment work to make everything more efficient.  

The beauty of having good staff: We are exhausted and pushing to stay awake til 9ish.  Lunch was made for us, Danny ran out to get hangers and a hamper and pin adapters, dinner is being prepared right now, so all of my old chores/duties of the house,  are no longer mine.  I get to blog and start working on a computer programming course for innovativepd.com (my film course is getting credited by HOL right now!)

So I have a few first impressions/thoughts so far.
1. Lots of mustaches, seriously, everyone has one.
2. Lots of guns (mossberg 500s, AKSUs, AK47s, MP5s, FNFALs) and with bullets which were missing in Hanoi.  Security at school is heavy, at our housing complex as well and at the money changers and on the roads.  Everyone seemed very comfortable with their guns, upholstered and looking well used.
3. Lots of big birds. I'll snap some pictures, they are everywhere.
4. Nice wide streets full of motorbikes and trees, no honking or driving against traffic so far.
5. Very long stares and friendly interactions.

TV here is great, lots of different news, Pakistani, Arabic and other things that I don't understand. Religious channels next to channels showing Lollywood (Lahore's Bollywood) music videos that are not too innocent, home shopping and cooking shows that must be live, they sure could use some editing (watched some one use a mixer for almost a minute this morning).  

Power drops out about once an hour (or every other hour) for a minute or three, that will be giving my Raspberry and hard drive set up fits.  The TV signal (cable) also drops every 30 to 84 minutes for a minute.

We were welcomed by one of our vice principals this afternoon and will head into school tomorrow with her to use the internet, and get a full tour...mostly to send home an email to let everyone know that we are fine.

I hear you " Where are all the pictures, you never type this much? "

I haven't taken any yet!  (Except these:

thanks for not understanding zippers, US gov. Employees.)

I'll rectify that soon though (the pictures, not the gov.).  I'll also be updating a lot more while we encounter all of the new things in our life.

Here is our house:


Donation for the Cause

"Can you make a donation?" Asked the office manager.
"Sure," replied an expat teacher. (Not me, I'm re-telling someone else's story from April ish 2014.

A few hours later the donation was returned.  It turns out that it was a mandatory collection of cash from all the Vietnamese staff, but expats were not supposed to be involved.

We hadn't been asked because it wasn't for a charity such as hurricane victims, it was a charity called The Vietnamese Government forgot to buy enough bullets. Not something they should have left off of the annual budget, but it confirmed all of stories of the guy's AKs and TT33s being empty.  The bullets and guns were being sent to arm the islanders who are close to the disputed Chinese oil rigs.  

If they sent the navy, it could be war, if the islanders harrass the Chinese and shoot at them, then the Vietnamese government isn't responsible.  Not a bad solution.... but really?  Donate for ammo?  I guess when your yearly budget is set, it is set.