/*
RoboShutta
Version 1
For Arduino Trinket by Adafruit
Code for controlling a servo-driven shutter on a pinhole camera via a cable
from a distance. Simplicity and reliability are paramount. Such a remote /
automatically controlled shutter-equiped camers, mounted on GoPro (or similar)
hardware shall be collectively termed a GoSlo camera system.
Lacking proper PWM output, a clever hack is utilized to update the
position of the servo arm via an interupt. This should have minimal
impact on functionality, but similar code could be easily written
for other Arduino (semi-) ompatibles.
Suitable camera applications are:
http://www.thingiverse.com/thing:577223
http://www.thingiverse.com/thing:495230
Servo-ready parts for these cameras are pending on Thingiverse.com
created 02/21/2015
by Todd Schlemmer theschlem@gmail.com
SOURCES:
Adapted from TrinketKnob/SoftServo by Adafruit
RESOURCES:
https://learn.adafruit.com/downloads/pdf/introducing-trinket.pdf
https://learn.adafruit.com/trinket-gemma-servo-control/overview
http://www.akeric.com/blog/?tag=arduino
This sketch allows for remote control of a servo-driven pinhole camera shutter.
Required library is the Adafruit_SoftServo library
available at https://github.com/adafruit/Adafruit_SoftServo
The standard Arduino IDE servo library will not work with 8 bit
AVR microcontrollers like Trinket and Gemma due to differences
in available timer hardware and programming. We simply refresh
by piggy-backing on the timer0 millis() counter
All circuitry is housed in a case with the 6-12V battery pack, and connected to the
shutter servo via a standard 3-wire servo cable(s). Servos can be controlled by
connecting mutiple cables, many meters in length.
Handheld remote
power switch
safety switch -momentary (unable to open shutter if not depressed)
shutter switch -toggle
status LED tied to PIN1, used for status, debugging, error purposes
CIRCUITRY:
******** diagrams and pinouts ***********************
Trinket Arduino Compatible
By Adafruit
MINI USB
________
_____| |_____
| _ | || || | _ |
| (_) | || || | (_) |
| _ | ====== | _ |
Green LED | [G] |________| [R] | red status LED
(power) | |
BAT + | O [] [] [] || O | USB 5V+
| || |
GND - | O =[]= [] O | #0 SERVOPIN
| =[]= |
#4 | O O | #1 (red LED) LEDPIN
| _u_u_u_ |
SAFETYPIN #3 | O | | O | #2 SHUTTAPIN
| | | |
RESET | O |_______| O | 5 V+ (regulated from BAT)
| _ n n n _ |
| (_) | | (_) |
|_ |_[]_| _____|
\____________/
Reset switch
Servo Plug
_______________
| __ _ |
Ground | [__] _] |==brown wire============
| __ _ |
5V + | [__] _] |==orange wire===========
| __ _ |
Signal | [__] _] |==yellow wire===========
|_______________|
******** ARDUINO Wiring ***************************************
BAT & GND wired to battery pack through power switch
Pin #0 to servo signal
Pin #1 to status LED
Pin #2 from shutta switch (toggle 1=open 0=closed)
Pin #3 from safety switch (momentary)
*/
// ***************** Declarations and Initializations *******************
//int VariableName = 2; //comment
//#include <Library.h> // some library module
#include <Adafruit_SoftServo.h> // SoftwareServo (works on non PWM pins)
#define SERVO1PIN 0 // Servo control line (orange) on Trinket Pin #0
#define LEDPIN 1 // Status LED wired to Pin #1
#define SHUTTAPIN 2 // Toggle switch (shutter control) on Trinket Pin #2 (Analog 1)
#define SAFETYPIN 3 // Momentary pushbutton on Trinket Pin #3
Adafruit_SoftServo myServo1, myServo2; //create TWO servo objects
int OpenedValue = 102; // Servo position for opened shutter, determined experimentally with ShuttaSetup
int ClosedValue = 23; // Servo position for closed shutter, determined experimentally with ShuttaSetup
int servoPos; // variable for servo position
// **************************************************
void setup()
{
// Set up the interrupt that will refresh the servo for us automagically
OCR0A = 0xAF; // any number is OK
TIMSK |= _BV(OCIE0A); // Turn on the compare interrupt (below!)
pinMode(LEDPIN, OUTPUT);
pinMode(SHUTTAPIN,INPUT);
myServo1.attach(SERVO1PIN); // Attach the servo to pin 0 on Trinket
CloseShutta();
digitalWrite(LEDPIN, HIGH);
delay(1000);
digitalWrite(LEDPIN, LOW);
}
// **************************************************
void loop()
{
Start: // label used to break out of routine if necessary
if (digitalRead(SHUTTAPIN))
{
OpenShutta();
}
else
{
CloseShutta();
}
}
// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
// Called by the microcontroller every 2 milliseconds
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect)
{
// this gets called every 2 milliseconds
counter += 1;
// every 20 milliseconds, refresh the servos!
if (counter >= 5)
{
counter = 0;
myServo1.refresh();
}
}
// subroutine OpenShutta *******************************
void OpenShutta()
{
servoPos = OpenedValue;
myServo1.write(servoPos); // tell servo to go to position
digitalWrite(LEDPIN, HIGH);
delay(200); // waits 1500ms for the servo to reach the position
}
// subroutine CloseShutta *******************************
void CloseShutta()
{
servoPos = ClosedValue;
myServo1.write(servoPos); // tell servo to go to position
digitalWrite(LEDPIN, LOW);
delay(200); // waits 1500ms for the servo to reach the position
}
/* subroutine LEDdebug *******************************
Used to demonstrate some small value for debugging purposes
by flashing Pin1 LED some number of times.
*/
void LEDdebug(int number)
{
for (int i=1; i <= number; i++)
{
digitalWrite(LEDPIN, HIGH);
delay(500);
digitalWrite(LEDPIN, LOW);
delay(500);
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
The formatting is slightly crowded, but you should be able to cut and paste into the Arduino IDE and preserve formatting.
Are you sure? yes | no