ATtiny servo library

Buona sera,
Da qualche giorno sto provando ad utilizzare alcune librerie per muovere motori servo con la mia ATtiny 85.

Per ora ho provato la servo8bit, scaricato lo zip e caricato come una normale Liberia.
Caricata, nessun errore, ma non muove nulla.

La seconda, SoftwareServo, vuole la Liberia :
#include <WProgram.h>
Anche utilizzando #include "Arduino.h" continua a richiedere WProgram.h .

Qualcuno può aiutarmi?

Se ti continua a chiedere la WProgram.h è perché da qualche parte c'è ancora ... cerca dentro a tutti i sorgenti e modificali.

Guglielmo

P.S.: Immagino comunque che tu abbia già lavorato con gli ATtiny85 ed abbia installato il "core" opportuno per quest'ultimi, vero ?

gpb01:
P.S.: Immagino comunque che tu abbia già lavorato con gli ATtiny85 ed abbia installato il "core" opportuno per quest'ultimi, vero ?

YEs i did!

Se ti continua a chiedere la WProgram.h è perché da qualche parte c'è ancora ... cerca dentro a tutti i sorgenti e modificali.

Yes, modificato ora aggiungendo al sorgente:

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

Non mi da più nessun errore, ma continua comunque a non muovere il servo...

Allego il mio breve programma di test:

#include <SoftwareServo.h>

SoftwareServo myservo; 

int pos = 0;    

void setup() {
  myservo.attach(1); // pin 6 ATtiny 
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Non uso i servo, comunque prova a mettere un link alla libreria SoftwareServo, che vediamo se ci sono delle note o altro ... ::slight_smile:

Guglielmo

In questo momento sto provando la libreria SoftwareServo, con questo sketch:

#include <SoftwareServo.h>

SoftwareServo myservo; 

int pos = 0;
  
void setup() {
 //myservo.setMinimumPulse(720);   // set the duration of the 0 degree pulse in microseconds
 //myservo.setMaximumPulse(2200);  // set the duration of the 180 degree pulse in microseconds
  myservo.attach(1); // pin 6 ATtiny 
}

void loop() {
  for (pos = 0; pos <= 5; pos += 1) { // goes from 0 degrees to 5 degrees
    // in steps of 1 degree
      myservo.write(pos);           // tell servo to go to position in variable 'pos'
    delay(15);  
    SoftwareServo::refresh();
  }
  
  for (pos = 5; pos >= 0; pos -= 1) { // goes from 5 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);           
    SoftwareServo::refresh();
  }
}

Il servo si muove, solo in senso orario, ma continua senza fermarsi MAI.
Dallo sketch dovrebbe tornare indietro dopo 5 passi.

Non intuisco a cosa serva SoftwareServo::refresh(); , se non lo inserisco non si muove nulla.
Eppure mi pare di capire, dalla pagina suddetta, che serva per far rimanere il servo in quella posizione, impedendogli di tornare alla posizione di partenza (come molti servo fanno e CREDO anche il mio).

Vedo che nella libreria è accluso un esempio ...
... ha provato a vedere se con quello le cose funzionano come l'esempio prevede, o hai problemi anche li ?

Guglielmo

Ho provato il primo esempio, con il potenziometro su A1 ed il servo sull'1 ma continua a girare solo in un verso.
Se sposto il potenziometro rallenta o velocizza l'accelerazione.... cosa che non torna nel codice.

Appena posso provo la libreria Servo8Bit .

SoftwareServo: Oltre che la libreria é stravecchia (del ottobre 2008) sei sicuro che la libreria sia adatta per il ATtiny85?

Libreria Servo8Bit: se leggi é una libreria proprio per il Tiny 45 e 85:
"Servo8Bit.cpp - Interrupt driven Servo library for the Attiny45 and Attiny85 that uses an 8 bit timer."

Poi per favore usa i tag CODE per lo sketch (icona </>) e non quote.

Ciao Uwe

Ho preso l'esempio di Servo8bit, modificandolo per farlo funzionare:

#include "Servo8Bit.h"

void mymydelay(uint16_t milliseconds);  //forward declaration to the mydelay function
Servo8Bit myServo;
void setup() {
  myServo.attach(1);

}

int test()
{
    myServo.write(0);   //rotate to the 0 degree position
    mydelay(2000);        //wait 2 seconds

    myServo.write(180); //rotate to the 180 degree position
    mydelay(2000);        //wait 2 seconds

    myServo.write(90);  //rotate to the center (90 degree) position
    mydelay(2000);        //wait 2 seconds


    //sweep the servo
    while(1)
    {
        for(int pos = 0; pos < 180; pos++)  // goes from 0 degrees to 180 degrees
        {                                   // in steps of 1 degree
            myServo.write(pos);             // tell servo to go to position in variable 'pos'
            mydelay(15);                      // waits 15ms for the servo to reach the position
        }

        for(int pos = 180; pos > 1; pos--)  // goes from 180 degrees to 0 degrees
        {
            myServo.write(pos);             // tell servo to go to position in variable 'pos'
            mydelay(15);                      // waits 15ms for the servo to reach the position
        }
    }
}

void mydelayMicroseconds(uint16_t us)
{
#if F_CPU >= 16000000L
    // for the 16 MHz clock on most Arduino boards

    // for a one-microsecond mydelay, simply return.  the overhead
    // of the function call yields a mydelay of approximately 1 1/8 us.
    if (--us == 0)
        return;

    // the following loop takes a quarter of a microsecond (4 cycles)
    // per iteration, so execute it four times for each microsecond of
    // mydelay requested.
    us <<= 2;

    // account for the time taken in the preceeding commands.
    us -= 2;
#else
    // for the 8 MHz internal clock on the ATmega168

    // for a one- or two-microsecond mydelay, simply return.  the overhead of
    // the function calls takes more than two microseconds.  can't just
    // subtract two, since us is unsigned; we'd overflow.
    if (--us == 0)
        return;
    if (--us == 0)
        return;

    // the following loop takes half of a microsecond (4 cycles)
    // per iteration, so execute it twice for each microsecond of
    // mydelay requested.
    us <<= 1;

    // partially compensate for the time taken by the preceeding commands.
    // we can't subtract any more than this or we'd overflow w/ small mydelays.
    us--;
#endif

    // busy wait
    __asm__ __volatile__ (
        "1: sbiw %0,1" "\n\t" // 2 cycles
        "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
    );
}//end mydelayMicroseconds


void mydelay(uint16_t milliseconds)
{
    for(uint16_t i = 0; i < milliseconds; i++)
    {
        mydelayMicroseconds(1000);
    }
}//end mydelay

void loop() {
  test();
  }

Ma comunque non muove assolutamente nulla :frowning:

Scusa, metti anche uno schema dei collegamenti che hai, incluse alimentazione, ecc. che sicuramente aiuta ...

Guglielmo

Eccolo!

Tengo fede all'ultimo esempio caricato, Servo8bit, che però non da alcun segno di vita.