Show Posts
Pages: 1 [2]
16  Forum 2005-2010 (read only) / Interfacing / Re: Servo control - from Processing? on: July 22, 2007, 12:14:44 am
I gave that a shot. and it didn't work....  :-?
17  Forum 2005-2010 (read only) / Interfacing / Servo control - from Processing? on: July 21, 2007, 09:12:07 pm
Hello everyone,

Ok so I've been working all day but to no avail.....  

I'm attempting to control a servo motor via serial communication (characters sent from a simple Processing sketch)
Since I've never done this before I tried to use the LED example (that detects if the mouse cursor is over the square and if so, send power to the LED) as a starting point.  

I assumed that it would be as easy as changing the code to send a pulse to the servo as the serial reads a ASCI character, but I'm getting no movement.

The other problems occur when I attempt to run the Processing sketch - it sometimes disconnects the serial connection leaving error messages etc.

heres the code for the ARDUINO:

Code:
int outputPin = 13;
int val;

int minPulse = 1000;
int maxPulse = 2500;
int pulse = 0;

int lastPulse = 0;
int refreshTime = 20;



void setup()
{
  pinMode(outputPin, OUTPUT);
  pulse = maxPulse;
  Serial.begin (9600);
}

void loop()
{
  if (Serial.available()) {
    val = Serial.read();
    if (val == 'H') {
      pulse = minPulse;
    }
    if (val == 'L') {
      pulse = maxPulse;
    }
  }
 updateServo();
}


void updateServo()
{
   if (millis() - lastPulse >= refreshTime) {
    digitalWrite(outputPin, HIGH);
    delayMicroseconds(pulse);
    digitalWrite(outputPin, LOW);
    
    lastPulse = millis();
   }
}


heres the code for PROCESSING
Code:
import processing.serial.*;

Serial port;

void setup()
{
  size (200,200);
  noStroke();
  frameRate(10);
  
  println(Serial.list());
  
  port = new Serial(this, Serial.list()[0], 9600);
}

boolean mouseOverRect()
{
  return ((mouseX >= 50) && (mouseX <=150) &&(mouseY >= 50) && (mouseY <= 150));
}

void draw()
{
  background(#222222);
  if(mouseOverRect())
  {
    fill(#BBBBB0);
    port.write('H');
  }
  else
  {
    fill(#666660);
    port.write('L');
  }
  rect(50,50,100,100);
}


If anyone has some insight on Serial Servo control, I would greatly appreciate it.
Cheers

- Nick
18  Forum 2005-2010 (read only) / Troubleshooting / Re: program resetting automatically?? on: September 12, 2007, 01:58:02 pm
yes, those motors should most likely have their own power supply


the funny thing is I was running this machine the exact same way with one of the older Arduino's and it ran fine - the new ten thousand must be a bit different somehow.

anyways, thanks for the reply - prob seems to be solved

cheers
19  Forum 2005-2010 (read only) / Troubleshooting / Re: program resetting automatically?? on: September 11, 2007, 10:11:50 pm
ok theres a good possibility the problem has been solved ....

I've been powering the motors with a wall wart connected through the board (alos powering the board itself)...

I went out and picked up a more powerful power supply (more amperage)
this seems to have worked - I've been watching it run for about 15 minutes now and it hasnt yet reset....

given the problem at hand, does this solution seem to be a viable one, or is this a strange occurrence?
20  Forum 2005-2010 (read only) / Troubleshooting / Re: program resetting automatically?? on: September 11, 2007, 08:33:40 pm
ok heres the jist of the code (not the whole but you get the idea)

Code:
// nb 090307 b
//----------------------------------------------------------------o


int SERVOa = 12;
int SERVOb = 11;
int SERVOc = 10;
int SERVOd = 9;
int SERVOe = 8;
int SERVOf = 7;
int SERVOg = 6;
int SERVOh = 5;
int SERVOi = 4;

int MIN_PULSE = 500;
int MAX_PULSE = 2000;
int DELTA = 1800;

//int pulse_width = 0;
int lastPulse;
//int refreshTime = 20;

long randNumber;


//----------------------------------------------------------------o


void setup()
{
  int i;
  pinMode(SERVOa, OUTPUT);
  pinMode(SERVOb, OUTPUT);
  pinMode(SERVOc, OUTPUT);
  pinMode(SERVOd, OUTPUT);
  pinMode(SERVOe, OUTPUT);
  pinMode(SERVOf, OUTPUT);
  pinMode(SERVOg, OUTPUT);
  pinMode(SERVOh, OUTPUT);
  pinMode(SERVOi, OUTPUT);
  

  Serial.begin(9600);
  
  for (i=0; i<10; i++)
  {
    digitalWrite(SERVOa, HIGH);
    delayMicroseconds((MIN_PULSE + MAX_PULSE)/2);
    digitalWrite(SERVOa, LOW);
    delay(20);
  }

 Serial.println("servo's at midpoints");

  delay(2000);
}


//----------------------------------------------------------------oooo 1

void servo1()

{
  int i;
  int pulse_width;
//  int lastPulse;

  
  randNumber = random(500, 2000);
//  delay(5000);
  
  pulse_width = randNumber;
  Serial.print(lastPulse, DEC);
  Serial.print("servo1_");
  Serial.println(pulse_width, DEC);
  
  
  for (i=0; i<100; i++)
 {
      digitalWrite(SERVOa, HIGH);
      delayMicroseconds(pulse_width);
      digitalWrite(SERVOa, LOW);
      delay(20);

        lastPulse = pulse_width;
  }
}

//----------------------------------------------------------------oooo first three


void threeservos1()

{
  int i;
  int pulse_width;
//  int lastPulse;
 
  
  randNumber = random(500, 2000);
//  delay(5000);
  
  pulse_width = randNumber;
//  Serial.print(lastPulse, DEC);
  Serial.print("a c f_");
  Serial.println(pulse_width, DEC);
  
  
  for (i=0; i<60; i++)
 {
      digitalWrite(SERVOa, HIGH);
      digitalWrite(SERVOc, HIGH);
      digitalWrite(SERVOf, HIGH);


      delayMicroseconds(pulse_width);


      digitalWrite(SERVOa, LOW);
      digitalWrite(SERVOc, LOW);
      digitalWrite(SERVOf, LOW);


      delay(20);

        lastPulse = pulse_width;
  }
}
 
 //----------------------------------------------------------------oooo all up
 
void allup()
{
 
  int i;
  
  for (i=0; i<10; i++)
  {
    digitalWrite(SERVOa, HIGH);
    digitalWrite(SERVOb, HIGH);
    digitalWrite(SERVOc, HIGH);
    
    delayMicroseconds(MIN_PULSE);
    
    digitalWrite(SERVOa, LOW);
    digitalWrite(SERVOb, LOW);
    digitalWrite(SERVOc, LOW);
 
    delay(20);
  }
  Serial.println("line one up");
  delay(2000);
  
   for (i=0; i<10; i++)
  {
    digitalWrite(SERVOd, HIGH);
    digitalWrite(SERVOe, HIGH);
    digitalWrite(SERVOf, HIGH);
    
    delayMicroseconds(MAX_PULSE);
    
    digitalWrite(SERVOd, LOW);
    digitalWrite(SERVOe, LOW);
    digitalWrite(SERVOf, LOW);
 
    delay(20);
  }
  Serial.println("line two up");
  delay(2000);
  
  
   for (i=0; i<10; i++)
  {
    digitalWrite(SERVOg, HIGH);
    digitalWrite(SERVOh, HIGH);
    digitalWrite(SERVOi, HIGH);
    
    delayMicroseconds(MIN_PULSE);
    
    digitalWrite(SERVOg, LOW);
    digitalWrite(SERVOh, LOW);
    digitalWrite(SERVOi, LOW);
 
    delay(20);
  }
  Serial.println("line three up");
  delay(2000);


}
  
 
 //----------------------------------------------------------------o
 
 void loop()
 {
   int i, c;
  
   if (Serial.available())
   {
     c = Serial.read();
     if ((c == 'a'))
     {
       allup();
       delay(10000);
     }
   }
    
   threeservos1();
   threeservos2();
   threeservos3();
   threeservos2();
   threeservos3();
   threeservos1();
   threeservos3();
  
  
  
}



ok so what it will do is run through the loop , and stop for a few seconds (about 7 sec. / enough time for the board to reload) and then go back to void setup.....

 :-?
21  Forum 2005-2010 (read only) / Troubleshooting / program resetting automatically?? on: September 11, 2007, 07:06:34 pm
Hi guys,

So I just unwrapped my brand new Decimilia and I'm having this one problem with it (mind you I tested my other new Decimilia board with the exact same code - no problems with that one)

the program is resetting automatically and starting over after it runs the loop once or twice....

whats going on here?


(I've tried placing a 10k resistor between RX and TX to see if that would help but to no avail)
22  Forum 2005-2010 (read only) / Interfacing / 10k thermistor .. reading backwards? on: March 29, 2008, 12:53:29 pm
Hello guys,

I seem to be stumped a bit on a seemingly simple problem ... my thermistors are reading backwards.  For example, if I add heat, the printed value decreases ....

anyone out there have this happen to them?
any suggestions?
thanks in advance!

I've been working with a couple pieces of code .. one real simple for debugging the sensor .. the other I found online and is a bit too long to post but both have the same problem...

Code:
int T1 = 0;    
int ledPin = 13;  

      

void setup() {
  pinMode(ledPin, OUTPUT);  
  Serial.begin(9600);
}

void loop() {
  val = analogRead(T1);    
  digitalWrite(ledPin, HIGH);
  delay(val);
  digitalWrite(ledPin,LOW);  
  Serial.println(val,DEC);
  
  }


23  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and lots of servos on: September 21, 2007, 04:19:24 pm
and here is for the "receiver" board to run the other 9 servos:  [full version wouldn't fit so I cut it down a bit , but you get the idea...]

I know these could be cleaned up but its a start - good luck



Code:
/*----------------------------------------------------------------oooo
nick bruscia
091307
homeostat v 1.3
board 2 (receiver)
/----------------------------------------------------------------oooo */


int SERVOa = 12;
int SERVOb = 11;
int SERVOc = 10;
int SERVOd = 9;
int SERVOe = 8;
int SERVOf = 7;
int SERVOg = 6;
int SERVOh = 5;
int SERVOi = 4;

int MIN_PULSE = 500;
int MAX_PULSE = 2000;



int lastPulse;

int lastFunc;
int lastFunc2;

int received;


long randNumber;
long randFunction;
long randFunction2;



//----------------------------------------------------------------oooo

void setup()
{
  int i;
  pinMode(SERVOa, OUTPUT);
  pinMode(SERVOb, OUTPUT);
  pinMode(SERVOc, OUTPUT);
  pinMode(SERVOd, OUTPUT);
  pinMode(SERVOe, OUTPUT);
  pinMode(SERVOf, OUTPUT);
  pinMode(SERVOg, OUTPUT);
  pinMode(SERVOh, OUTPUT);
  pinMode(SERVOi, OUTPUT);
  
  Serial.begin(9600);
  randomSeed(analogRead(0));

  
//---------------------------------------------o
// copy for each servo to reset their positions to the top (see sender code)

 for (i=0; i<10; i++)
  {
    digitalWrite(SERVOa, HIGH);
    delayMicroseconds(MAX_PULSE);
    digitalWrite(SERVOa, LOW);
    delay(20);
  }

// etc etc....

    

  Serial.println("servo's at highpoints");

  delay(2000);
}




//----------------------------------------------------------------oooo 10 (copy this for 9 servos (up to servo18) changing function name an which servo to call

void servo10()
{
  int i;
  int pulse_width;
  int function;
  
  randNumber = random(500, 2000);
  pulse_width = randNumber;
  function = 12;

 
   for (i=0; i<100; i++)
  {
    digitalWrite(function, HIGH);
    delayMicroseconds(pulse_width);
    digitalWrite(function, LOW);
    
    delay(20);
    
    lastPulse = pulse_width;
    lastFunc = function;
  }
}




//----------------------------------------------------------------oooo

void cluster()
{
  int i;
  int pulse_width;
  int function;
  
  pulse_width = lastPulse + 200;
  function = lastFunc + 1;
  
  
  for (i=0; i<100; i++)
  {
    digitalWrite(function, HIGH);
    delayMicroseconds(pulse_width);
    digitalWrite(function, LOW);
    
    delay(20);
    
  }
}
  
 

//----------------------------------------------------------------oooo

void loop()

{
     while (Serial.available() > 0)
     received = Serial.read();
 
       if (received == 10)
       {
         servo10();
         cluster();
       }
       if (received == 11)
       {
         servo11();
         cluster();
       }
       if (received == 12)
       {
         servo12();
         cluster();
       }
       if (received == 13)
       {
         servo13();
         cluster();
       }
       if (received == 14)
       {
         servo14();
         cluster();
       }
       if (received == 15)
       {
         servo15();
         cluster();
       }
       if (received == 16)
       {
         servo16();
         cluster();
       }
       if (received == 17)
       {
         servo17();
         cluster();
       }
       if (received == 18)
       {
         servo18();
         cluster();
       }
      
  }
  


24  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and lots of servos on: September 21, 2007, 04:12:24 pm
Will all 12 of the servos need to run at the exact same time? Or will they be going on and off in intervals (for instance, 1 moves, then 3 move, then 2 move ... etc ....)?

I just recently completed a project that runs 18 servos from two Decimilia boards, which were networked via serial communication between the two.  At any given time however, the maximum amount of servos running at the same time was 3.  I had an external power supply for each board - each powering 9 servos from 5V.  The power supplies were providing about 1000 MA each which was necessary.

The machine ran very well, and is currently functioning in a gallery as part of an exhibit for hours and hours on end.

heres the code for the "sender" board:

Code:
/*----------------------------------------------------------------oooo
nick bruscia
091307
homeostat v 1.3
board 1 (sender)
/----------------------------------------------------------------oooo */


int SERVOa = 12;
int SERVOb = 11;
int SERVOc = 10;
int SERVOd = 9;
int SERVOe = 8;
int SERVOf = 7;
int SERVOg = 6;
int SERVOh = 5;
int SERVOi = 4;

int MIN_PULSE = 500;
int MAX_PULSE = 2000;


int lastPulse;

int lastFunc;
int lastFunc2;

long randNumber;
long randFunction;
long randFunction2;



//----------------------------------------------------------------oooo

void setup()
{
  int i;
  pinMode(SERVOa, OUTPUT);
  pinMode(SERVOb, OUTPUT);
  pinMode(SERVOc, OUTPUT);
  pinMode(SERVOd, OUTPUT);
  pinMode(SERVOe, OUTPUT);
  pinMode(SERVOf, OUTPUT);
  pinMode(SERVOg, OUTPUT);
  pinMode(SERVOh, OUTPUT);
  pinMode(SERVOi, OUTPUT);
  
  Serial.begin(9600);
  randomSeed(analogRead(0));

  
//---------------------------------------------o
// pull servos to their respective maximums

 for (i=0; i<10; i++)
  {
    digitalWrite(SERVOa, HIGH);
    delayMicroseconds(MIN_PULSE);
    digitalWrite(SERVOa, LOW);
    delay(20);
  }
    
  for (i=0; i<10; i++)
  {  
    digitalWrite(SERVOb, HIGH);
    delayMicroseconds(MIN_PULSE);
    digitalWrite(SERVOb, LOW);
    delay(20);
  }
  
  for (i=0; i<10; i++)
  {  
    digitalWrite(SERVOc, HIGH);
    delayMicroseconds(MIN_PULSE);
    digitalWrite(SERVOc, LOW);
    delay(20);
  }
  
  for (i=0; i<10; i++)
  {  
    digitalWrite(SERVOd, HIGH);
    delayMicroseconds(MAX_PULSE);
    digitalWrite(SERVOd, LOW);
    delay(20);
  }
  
  for (i=0; i<10; i++)
  {  
    digitalWrite(SERVOe, HIGH);
    delayMicroseconds(MAX_PULSE);
    digitalWrite(SERVOe, LOW);
    delay(20);
  }
  
  for (i=0; i<10; i++)
  {
    digitalWrite(SERVOf, HIGH);
    delayMicroseconds(MAX_PULSE);
    digitalWrite(SERVOf, LOW);
    delay(20);
  }
  
  for (i=0; i<10; i++)
  {
    digitalWrite(SERVOg, HIGH);
    delayMicroseconds(MIN_PULSE);
    digitalWrite(SERVOg, LOW);
    delay(20);
  }
  
  for (i=0; i<10; i++)
  {
    digitalWrite(SERVOh, HIGH);
    delayMicroseconds(MIN_PULSE);
    digitalWrite(SERVOh, LOW);
    delay(20);
  }
  
  for (i=0; i<10; i++)
  {
    digitalWrite(SERVOi, HIGH);
    delayMicroseconds(MIN_PULSE);
    digitalWrite(SERVOi, LOW);
    delay(20);
  }
  Serial.println("servo's at highpoints");

  delay(2000);
}




//----------------------------------------------------------------oooo

void randservo()

{
  int i;
  int pulse_width;
  int function;
  int function2;
  

  randNumber = random(500, 2000);
  randFunction = random(1, 19);

  pulse_width = randNumber;
  function2 = randFunction2;
  
//-------------------------o

  if (randFunction >= 0 && randFunction <= 9)
  {
    randFunction2 = random(4, 13);
    
    for (i=0; i<100; i++)
    {
      digitalWrite(function2, HIGH);
      delayMicroseconds(pulse_width);
      digitalWrite(function2, LOW);
      
      delay(20);

        lastPulse = pulse_width;
        lastFunc2 = function2;
    }
  }
  else if (randFunction >= 10 && randFunction <= 18)
  {
    Serial.print(randFunction, BYTE);
  }
  
}



//----------------------------------------------------------------oooo

void randservo2()

{
  int i;
  int pulse_width;
  int function;
  int function2;
  

  pulse_width = lastPulse - 300;
  function2 = lastFunc2 + 1;
  
//-------------------------o
    
    for (i=0; i<100; i++)
    {
      digitalWrite(function2, HIGH);
      delayMicroseconds(pulse_width);
      digitalWrite(function2, LOW);
      
      delay(20);
    }
}



//----------------------------------------------------------------oooo the simple loop
 
 void loop()
 {
  randservo();
  randservo2();
 }
  
25  Forum 2005-2010 (read only) / Interfacing / Re: servo positioning on: July 07, 2007, 03:18:15 pm
ok so the much easier way to do what I needed to do was to simply send a specific pulse to determine the servo location - I now know its pretty easy to translate that into degrees that servo is moving.

the code - slightly modified version of Tom Igoe's
pretty simple stuff

  
Code:

int servoPin = 13;    
//int servoPin1 = 12;
int minPulse = 500;  
int maxPulse = 2500;  
int pulse = 0;      

// the time in milliseconds of last pulse
int lastPulse = 0;  
int refreshTime = 20;

int analogValue = 0;  
int analogPin = 2;    

void setup() {
  pinMode(servoPin, OUTPUT);  
//  pinMode(servoPin1, OUTPUT);
  pulse = minPulse;          
  Serial.begin(9600);
}

void loop() {
  analogValue = analogRead(analogPin);  
  
  // length of pulse determines the servo position
  if (analogValue <= 50) pulse = minPulse;
  //if (analogValue >= 21 && analogValue <= 499) pulse = 0;
  if (analogValue >= 500 && analogValue <= 550) pulse = 1500;
  //if (analogValue >= 551 && analogValue <= 999) pulse = 0;
  if (analogValue >= 1000 && analogValue <= 1023) pulse = maxPulse;
  
  // for continuous motion alongside of potentiomter
  //pulse = (analogValue / 10) * 19 + 500;

  //Serial.print(minPulse, DEC);
  //Serial.print(maxPulse, DEC);
  Serial.println(analogValue, DEC);  
  

  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin, HIGH);  
    digitalWrite(servoPin1, HIGH);
    delayMicroseconds(pulse);      
    digitalWrite(servoPin, LOW);    
    digitalWrite(servoPin1, LOW);
    // save the time of the last pulse
    lastPulse = millis();          
  }
}

26  Forum 2005-2010 (read only) / Interfacing / Re: servo positioning on: July 06, 2007, 06:31:20 pm
great reply - I really appreciate it.

I'll dig a bit deeper into the code you supplied to see if I can get something started - thanks again for the info!
27  Forum 2005-2010 (read only) / Interfacing / servo positioning on: July 05, 2007, 06:50:55 pm
Hello everyone - I'm new here so first I'd like to introduce myself.

My name is Nick - I'm an architecture graduate student using physical computing to investigate interactive spaces and responsive materials and how they apply to architectural concepts and future construction methods.



Ok my question - I'm building a little prototype and will eventually need 18 servos running independently responding to various analog input -

right now I just need to move one, or two motors to three specific locations - min, middle , and max.  I'm using a simple potentiometer and 180 degree servos.
I've gotten the servo to run alongside of the potentiometer, but I'd rather see it only move when specific values are hit (eg, potentiometer is at midway - the servo runs from min to mid rotation and stops)



heres some code that doesn't seem to work.... nothing moves!   I was hoping you guys could share some insight to maybe illuminate things I may be doing incorrectly - as well as possibly offer places to get some source code that works so I could manipulate it and learn more of arduino coding - I'm new to the platform!  Cheers and thanks in advance!


int servoPin = 12; // Control pin for servo motor
int minPulse = 500; // Minimum servo position
int maxPulse = 2500; // Maximum servo position
int pulse = 0; // Amount to pulse the servo
int analogValue = 0;
int analogPin = 2;
int myVar = 0;


void newline(void);
void pulsout( int servoPin, int pulse);
void turnServo(int angle);


void setup() {
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pulse = minPulse; // Set the motor position value to the minimum
beginSerial(9600);
}

void loop() {


// read analog input from 'analogPin'
analogValue = analogRead(analogPin);
// calculate the input relative to the input range and angle range
myVar = (analogValue * 180)/1023;
// change the analog reading to the wanted range (between 500 to 2500)
//myVar = minPulse + (analogValue * 2);
turnServo( myVar );
// turn servo to the 50 degrees mark


turnServo(50);
delay(500);
turnServo(5);
delay(500);
turnServo(150);
delay(500);
turnServo(5);
delay(500);
turnServo(20);
delay(500);
turnServo(90);
delay(500);

}

// brings servo motor to the wanted angle (between 0 to 180 degrees)
void turnServo(int angle) {
int i;

// this loop is done in order to turn the servo motor to the wanted angle
for( i=1; i;)


pulse = (i*2500)/180;

pulse += 500+((2000/180)*i);

pulsout( servoPin, pulse);

}


void pulsout( int servoPin, int pulse) {

digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
delay(20); // 20 millisecond delay is needed between pulses

}

// newline function -> prints out new line (\n) as well as a carriage return (\c);
void newline() {
printNewline();
printByte(13);
}




28  Forum 2005-2010 (read only) / Frequently-Asked Questions / one wire readings / can someone decipher? on: September 18, 2007, 04:36:24 pm
Hey guys,

I was hoping to come across one or two of you who have some experience using one wire temp sensors - and could help me decipher these results ... I know T is the temp reading however, it couldn'e possibly be correct - is there some sort of conversion?

28 F8 9D 46 1 0 0 D4 read rom
 
49 1 4B 46 7F FF 7 10 F6 read scratchpad  T =  36 version: 1
Pages: 1 [2]