Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Arduino MegaServo library doesn't work on: February 16, 2013, 09:40:38 am
You are right, I  put the MegaServo library in the sketch directory. 

MegaServo library wasn't updated for the new IDE 1. But I replaced in MegaServo.cpp  #include <WProgram.h> with  #include <Arduino.h> and it compiles.
2  Using Arduino / Programming Questions / Arduino MegaServo library doesn't work on: February 16, 2013, 09:24:39 am
Arduino MegaServo library doesn't work.
I downloaded the MegaServo library from http://playground.arduino.cc/Code/MegaServo  in arduino-1.0.1\libraries\MegaServo if I add the library shows this errors.
Why?

Quote
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp: In function 'void handle_interrupts(servoTimer_t, volatile uint16_t*, volatile uint16_t*)':
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:96: error: 'LOW' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:96: error: 'digitalWrite' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:103: error: 'HIGH' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:103: error: 'digitalWrite' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:107: error: 'clockCyclesPerMicrosecond' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp: At global scope:
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:169: error: 'boolean' does not name a type
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp: In constructor 'MegaServo::MegaServo()':
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:205: error: 'clockCyclesPerMicrosecond' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp: In member function 'uint8_t MegaServo::attach(int, int, int)':
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:219: error: 'OUTPUT' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:219: error: 'pinMode' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:226: error: 'isTimerActive' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp: In member function 'void MegaServo::write(int)':
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:247: error: 'byte' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:247: error: expected `;' before 'channel'
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:248: error: 'channel' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:251: error: 'map' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:258: error: 'clockCyclesPerMicrosecond' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp: In member function 'int MegaServo::read()':
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:273: error: 'map' was not declared in this scope
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp: In member function 'int MegaServo::readMicroseconds()':
D:\Program Files\arduino-1.0.1\libraries\MegaServo\MegaServo.cpp:280: error: 'clockCyclesPerMicrosecond' was not declared in this scope
3  Using Arduino / Sensors / Can Arduino Mega 1280 get input from more than 16 potentiometers? on: February 08, 2013, 03:53:15 am
Can Arduino Mega 1280 get input from more than 16 potentiometers?

The Arduino Mega 1280 has 16 analog inputs, can the digital in/out be used to get data from potentiometers?

I need to get data from 25 potentiometers.

4  Using Arduino / Programming Questions / Re: Program doesn't loop with Serial using switch and case on: October 22, 2012, 06:00:56 am
marco_c thank you for the help, the program works as expected, I will use the code to control several servomotors.

For those who have the same problem here is the full code:
Code:
#include <Servo.h>

unsigned long serialdata;
int inbyte;
int pinNumber;
int digitalState;
int led = 13;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int pinNumber;
  int digitalState;

  switch(getSerial())
  {
  case 1:
    {
      pinNumber = getSerial();
      digitalState = getSerial();
      Serial.print("Pin: ");
      Serial.print(pinNumber);
      Serial.print("; S: ");
      Serial.println(digitalState);
     
      pinMode(pinNumber, OUTPUT);
      if(digitalState==1){
        digitalWrite(pinNumber, HIGH);
          break;
      }
     
      if(digitalState==0){
        digitalWrite(pinNumber, LOW);
          break;
      }
     
      break;
    }
  }
}

int getSerial()
{
  int d = 0;
  int b;

  while (b != '/')
  {
    b = Serial.read();
   
    if (b == -1)  // no char available
    {
      delay(1);  // just long enough to get a char in?
    }
    else if ((b >= '0') && (b <= '9'))
    {
      d = (d * 10) + (b - '0');
    }
  }

  return d;
}

To send data use 1/13/1/
 where the first 1/ is the case 1
 13 is the pin number
 the last 1 is the digitalState
5  Using Arduino / Programming Questions / Re: Program doesn't loop with Serial using switch and case on: October 22, 2012, 05:06:49 am
The first command 1/13/33/ gets executed but the next commands it doesn't.
If I send 1/13/44/ to turn off the led, nothing happens only "1" is printed, the pin number and the state don't get printed and the led doesn't turn off
6  Using Arduino / Programming Questions / Re: Program doesn't loop with Serial using switch and case on: October 22, 2012, 04:47:10 am
The result with led or the real pin number 13 is the same, I am using "pinNumber" to see the send data.

The print sends good data: "pin number 13 state 33 end", only once.
After that only "1" that is generated by getSerial() when the program requests the function

7  Using Arduino / Programming Questions / Program doesn't loop with Serial using switch and case on: October 22, 2012, 04:18:38 am
Hi

I got an Arduino Mega, the program bellow should change the state of an led according with the received data.
If I send 1/13/33/ with the Serial Monitor it turns ON the LED, but if I send 1/13/44/ it doesn't turn OFF  the LED, it gets stuck.

Code:
#include <Servo.h>

unsigned long serialdata;
int inbyte;
int pinNumber;
int digitalState;
int led = 13;
void setup()
{
  pinMode(led, OUTPUT);  
  Serial.begin(9600);

}

void loop()
{
  getSerial();
  switch(serialdata)
  {
  case 1:
    {
           getSerial();
          pinNumber = serialdata;
          getSerial();
          digitalState = serialdata;
          Serial.print(" pin number ");
          Serial.print(pinNumber);
          Serial.print(" state ");
          Serial.print(digitalState);
          Serial.print("end\n");
          
          if (digitalState==33)
          {            
            digitalWrite(led, HIGH);
          }
          if (digitalState==44)
          {
            digitalWrite(led, LOW);
          }
          break;
        }
        
     }
    }
  
long getSerial()
{
Serial.println(1);
  serialdata = 0;

 while (inbyte != '/')
  {
    inbyte = Serial.read();
 
    if (inbyte > 0 && inbyte != '/')
    {
    
      serialdata = serialdata * 10 + inbyte - '0';
    }
  }
  inbyte = 0;
  return serialdata;
}
8  Using Arduino / Programming Questions / Difference between 0 and 90 degrees is not 90 degrees on: June 15, 2011, 04:42:18 pm
I got a big problem the difference between 0 and 90 degrees is not 90 degrees for my servos. To get the servo horn parallel to a surface servo needs to rotated at 22 "servo" degrees and to get it is perpendicular it needs to rotate at 101 degrees(servo)

I got several hitec servos and they behave in a similar way,  I tried several programs and the behavior is exactly the same. I am using the servo library, and the problem persists with an external power supply.
9  Using Arduino / Project Guidance / Re: Computer screen flickers while servo motors are moving on: June 06, 2011, 10:31:55 am
Is this a problem? Can this damage the PC or Arduino if I continue to use it?
10  Using Arduino / Project Guidance / Re: Computer screen flickers while servo motors are moving on: June 05, 2011, 01:24:03 pm
I used a PC 400 Watts ATX power supply, and it supply's ~5v to the servos
11  Using Arduino / Project Guidance / Re: Computer screen flickers while servo motors are moving on: June 05, 2011, 01:05:50 pm
I got connected 6 Hitec servos 2x HS-805BB, and 4x HS-322HD. The Arduino is connected to a PC so it can receive servos commands
12  Using Arduino / Project Guidance / Computer screen flickers while servo motors are moving on: June 05, 2011, 09:13:42 am
My computer screen flickers while servo motors are moving, the servo motors are powered by an external power supply the grounds are connected.

I am thinking that there is some type of feedback from the arduino going through the USB.
13  Using Arduino / Programming Questions / Re: Controlling multiple servos through serial on: June 04, 2011, 07:40:07 pm
Using conditions if the servo get into the right position and stay there, but when the program starts all the servo go dangerously fast at 120 degrees, and delay has no effect on the movements speed.

The last version published here doesn't get to 41 because it is "simpler", the first version should get to 41
14  Using Arduino / Programming Questions / Re: Controlling multiple servos through serial on: June 04, 2011, 06:16:31 pm
I made the code simpler and added 3 objects, but how to write a value to a specified servos while maintaining the other servo position?

Code:
 
 #include <Servo.h>
Servo myservo1;
Servo myservo2;
Servo myservo3;

void setup() {

  int i;
  for (i=0;i<20;i++) {
    pinMode(i,INPUT);
    digitalWrite(i,0);
  }
  Serial.begin(9600);
  
  
        myservo1.attach(9);
       myservo2.attach(10);
       myservo3.attach(11);
}



void loop() {
  
 static int  s   = -1;    /* state                          */
  static int  pin = 9;    /* generic pin number             */
  int  val =  0;           /* generic value read from serial */


  if (Serial.available() >0) {
    val = Serial.read();
    
    switch (s) {



      case 41:  
      /*  writing position*/



         myservo1.write(val);
      
      
      s=-1;  /* we are done with this so next state is -1    */
      break;
          
      


    } /* end switch on state s                               */

  } /* end if serial available                               */
  
} /* end loop statement                                      */


15  Using Arduino / Programming Questions / Controlling multiple servos through serial on: June 04, 2011, 05:38:05 pm
Hi

I want to control several servos  through serial port but I can control only one servo at a time, I know that an servo object needs to be created for each servo and then attached to a pin, but how to send to each servo a different value.

case 41 does the position writing, the rest communicates with a program.
What needs to change to control several servos? The command through serial is   write(pin,val) when a servo position is set and another is send the first servo loose its position, and the second servo goes into position.

Code:
   #include <Servo.h>
Servo myservo;

void setup() {

  int i;
  for (i=0;i<20;i++) {
    pinMode(i,INPUT);
    digitalWrite(i,0);
  }
  Serial.begin(9600);
}



void loop() {
 
  /* variables declaration and initialization                */
 
  static int  s   = -1;    /* state                          */
  static int  pin = 9;    /* generic pin number             */
  int  val =  0;           /* generic value read from serial */
  int  agv =  0;           /* generic analog value           */
  int  dgv =  0;           /* generic digital value          */

  if (Serial.available() >0) {
    val = Serial.read();
   
    switch (s) {

      /* s=-1 means NOTHING RECEIVED YET ******************* */
 case -1:     

      /* calculate next state                                */
      if (val>47 && val<58) {
/* the first received value indicates the mode       
           49 is ascii for 1, ... 90 is ascii for Z         
           s=0 is change-pin mode
           s=10 is DI;  s=20 is DO;  s=30 is AI;  s=40 is AO;
           s=50 is servo status; s=60 is aervo attach/detach; 
           s=70 is servo read;   s=80 is servo write         
           s=90 is query script type (1 basic, 2 motor)         
                                                             */                                                             
        s=10*(val-48);
      }
      break; /* s=-1 (initial state) taken care of       */
 
     
      /* s=0 or 1 means CHANGE PIN MODE                      */



      case 41:   
      /*  writing position*/


        myservo.attach(pin);
         myservo.write(val);
     
     
      s=-1;  /* we are done with this so next state is -1    */
      break;
     
     
     
     
     
     
     
     
     
      case 90:
      if (val==57) {
        /* if string sent is 99  send script type via serial */
        Serial.println(1);
      }
      s=-1;  /* we are done with this so next state is -1    */
      break; /* s=90 taken care of                           */

    } /* end switch on state s                               */

  } /* end if serial available                               */
 
} /* end loop statement                                      */


Pages: [1] 2