PDA

View Full Version : [Just For Fun] Dimension Engineering Pico and Battleswitch code



mannyr7
03-23-2010, 08:50 PM
After literally scouring the internet for examples on how to use the D.E. Picoswitch and Battleswitch, I could never get them to work!!! I just chalked it up to both units being DOA, par for the course...:sad: So I migrated to the DF Robots Single relay which works great! Just send it a Hi or Lo from your mcu, no problem.
So I came home today bored, and thought about those useless pwm relays sitting in the junk box. Reading the product description, it hit me! These are intended to be controlled from R/C transmitters and are used much like servos. Only problem now, what is the correct pulse width to turn these things off and on??? So, with a lil experiment using my SB Freeduino, a 10K pot, and my wrongly maligned picoswitch, I extracted the correct on/off values by slowly turning the pot and watching the terminal window. 1400 microsecond max for off, and 1580 microsec minimum to turn on. Further experimentation revealed 2200 microseconds is around the max and yields the best performance for switching a motor on. Enjoy, and I hope this can help someone else.

This first one is a modified sketch to print the values from a potentiometer, but instead of moving a servo, we'll turn on a relay!


// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
// modified by 'MannyR7' Ramirez
#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int pulse; // variable to show pulse width

void setup()
{
Serial.begin(9600); // begins serial communication with the computer
myservo.attach(12); // attaches the servo on pin 12 to the servo object
}

void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
pulse = map(val, 0, 179, 750, 2250); // get a pulse width for current pot position
myservo.write(val); // sets the servo position according to the scaled value
Serial.print("degrees ");
Serial.print(val);
Serial.print(" pulse" );
Serial.println(pulse);
delay(15); // waits for the servo to get there
}


This next one is a simple program to demonstrate the functionality.


// Dimension Engineering Picoswitch Demo
// by 'MannyR7' Ramirez
// https://sites.google.com/site/mannysrobotpage/
#include <Servo.h>
Servo picoswitch;
int gunTime = 4; // number of seconds to leave trigger on

void setup()
{
picoswitch.attach(12);
Serial.begin(9600);
}

void loop()
{
picoswitch.write(1400);
Serial.print("Cease Fire!\n");
delay(1000); // waits for a second
picoswitch.write(2200);
Serial.print("Fire!\n");
for (int i=1; i <= gunTime; i++)
{
delay(1000); // waits for a second
Serial.print(i);
Serial.print("\n");
}
}



http://www.youtube.com/watch?v=xhhv3dGbOpw