Page 1 of 1

Time lapse setup

Posted: Mon Mar 30, 2015 6:04 pm
by DylanM
Hi, Since I'm not the best with script (unless its visual) I was wondering if someone could help me with my raps time-lapse build.
Setup:
two servos x and y axis
one camera
Arduino
raspi

I did some research and found that you can set a raspi pin to HIGH and that can tell the arduino to turn the servo but I was wondering first how to do the raps programming so that when a photo is about to be shot it sets the pin to HIGH and second how to make sure that the audio only turns the servos 5 degrees each time.

Thanks
Dylan

Re: Time lapse setup

Posted: Mon Mar 30, 2015 8:19 pm
by parkview
Hi Dylan,

I presume you have a RPi Camera? When doing a new project, I find it's good to break things down into sections and work on each section until it's working, then 'glue' them together so to speak.

Can you list out the steps, and what you have does so far, ie: can the RPi take a photo via Python scripting? How do you have the RPi communicating with the Arduino? Can you make a LED light up? Can you monitor a switch being turned on/off. Can you monitor a switch that then turns a LED on/off, all under Python control?

When you say a pin is going HIGH, do you mean the Arduino pin goes high and then the RPi see's that and then takes a RPi photo?

I don't understand what you mean by the audio part?

I presume your using the Arduino to control the servos?

Here are some RPi links for you to look into:


I haven't played around much with an Arduino, but happy to help out on the RPi side of things.

Re: Time lapse setup

Posted: Mon Mar 30, 2015 8:34 pm
by parkview
Hmm, rereading your initial post, you could do something like this:

  1. take a RPi camera photo
  2. raise RPi pin high (to notify Arduino that's the RPi has finished taking photo)
  3. Arduino sees the RPi pin go high
  4. Arduino moves servo X (if it needs to)
  5. Arduino moves server Y (if it needs to)
  6. Has any of the Servos reached their 180 degree limit (or are you using 360 deg. continuous servers?)
  7. Arduino raise one of it's pins high (to notify the RPi that it's finished moving the servos)
  8. RPi monitors the Arduino pin to see when it's ready to take another photo
  9. go back to step 1

Essentially, you have each device monitoring a different pin to see when it can do it's bit.

there are other ways of doing this, in that the RPi could communicate via the i2c bus, or USB, or Serial ports but that can get quite tricky.

Re: Time lapse setup

Posted: Tue Mar 31, 2015 10:27 pm
by parkview
this FREE magazine has a lot of interesting tutorials: http://www.raspberrypi.org/magpi/

Happy reading!

Re: Time lapse setup

Posted: Wed Apr 08, 2015 8:48 pm
by DylanM
My code so far is this:
#include <Servo.h>

Servo myservo;

int pos = 0;

void setup()
{
pinMode( 2 , INPUT);
pinMode( 13 , OUTPUT);
myservo.attach(9);
}

void loop()
{
for(pos = 0; pos <= 180; pos += 1);
int sensorVal = digitalRead(2);
{
if (sensorVal == HIGH) {
digitalWrite(13, LOW);
myservo.write(pos);
}
else {
digitalWrite(13, HIGH);
}
}
}

However the variable I have (which I copied and pasted because I thought it would work) makes the servo move all the way to 180 degrees instead of moving in increments of 1 degrees to 180 degrees (like the desc. said it would) each time pin 2 goes high.
So my real problem here is I don't understand how these variables work and I need a variable that goes in increments of 1 degrees each time a button is pressed.

Thanks
Dylan

Re: Time lapse setup

Posted: Wed Apr 08, 2015 10:04 pm
by parkview
Hi Dylan,

well done with the code so far. To help troubleshoot things, you could forget about the input/output pins for the moment, and just concentrate on getting the servo moving smoothly, perhaps moving from 0 to 180deg. with a 0.3-0.5 sec pause/delay between each step?

Once you have the servo motor moving properly, then you could integrate in the control and monitoring (in/out) pins. As I am not an Arduino programmer, I found these two links (amongst many) when I Googled: arduino servo

https://learn.adafruit.com/adafruit-arduino-lesson-14-servo-motors?view=all

http://arduino.cc/en/Reference/ServoWrite ; will this code work for you? Does the servo move to roughly 90 deg? Can you manually plug in other values to have to move to those?

Just thinking about it, you don't have a delay statement (http://playground.arduino.cc/Code/AvoidDelay) you could try adding in a delay(500) to see what happens. It could be that the code is running flat out, ie: moving from 0 to 180 as it should be, just very fast?

Try putting a print statement in on the RPi side, so you can track and count how many times it's running through a loop of raising the pin high and seeing the other pin going low etc.

another thought, you could try with no RPi in place, carefully manually pressing a button to see if the code works while the button lifts pin 2 high.

Maybe RPi is raising Pin 2 high, but the RPi isn't monitoring pin 13 correctly?

Re: Time lapse setup

Posted: Fri Apr 10, 2015 9:22 pm
by DylanM
Hi,

As you mentioned with the push button I have been working on that and I will give those links a go and add in the delay because I've seen in another code sample something similar and they had quite a few delays.

Re: Time lapse setup

Posted: Fri Apr 10, 2015 9:56 pm
by parkview
Bring it along on Sat. if your coming. Love to see it all :)

Re: Time lapse setup

Posted: Sun Apr 12, 2015 1:14 pm
by DylanM
Hi couldn't be at this weeks meeting but I should be at next months one. Unfortunately I managed to get bit by a mosquito carrying rossriver so I haven't been very mobile most of the beginning of this year. So far only finger joints have been affected and I've been quite tired but hopefully I should be back to doing most things next month. ;)

Re: Time lapse setup

Posted: Mon Apr 13, 2015 7:48 am
by parkview
All the best with the recovery and hope to see you at the next meeting!

Re: Time lapse setup

Posted: Tue Apr 14, 2015 3:43 pm
by Jubbp
Welcome the the club!!

It gets better over time.

Re: Time lapse setup

Posted: Thu Apr 16, 2015 3:46 pm
by seaton
DylanM wrote:Hi couldn't be at this weeks meeting but I should be at next months one. Unfortunately I managed to get bit by a mosquito carrying rossriver so I haven't been very mobile most of the beginning of this year. So far only finger joints have been affected and I've been quite tired but hopefully I should be back to doing most things next month. ;)


Hope you are feeling better soon, at least you can use that as an excuse to play with your Arduino and RPi :)