ATTiny85 and servo's

534 views
Skip to first unread message

Benjamin Crowe

unread,
Mar 26, 2014, 7:40:09 PM3/26/14
to notti...@googlegroups.com
Hello,

I am currently trying to shrink an Arduino project I am currently working on by using a ATTiny85 and I am running into issues with the servo I am trying to attach to it, would anyone be able to lend a hand working this out? I am using the SoftwareServo library, though every time I upload the sketch to the ATTiny it throws up a error saying it is out of sync.

Any ideas or suggestions would be great.

Thanks
Ben

jfowkes

unread,
Mar 27, 2014, 3:15:20 AM3/27/14
to notti...@googlegroups.com
If your program complies but doesn't upload, the problem isn't with your code or the servo library.

What are you using the program the ATTINY? What is the precise error message you're getting?

Benjamin Crowe

unread,
Mar 27, 2014, 4:47:50 AM3/27/14
to notti...@googlegroups.com
I am using an Arduino Uno in ISP mode to program the ATTINY, I decided to go back to using IDE 1.0.0 which seems to upload fine now, must of missed something out last night whilst tired, though the main issue I have now is that the servo won't rotate a full 180 degrees of motion, it seems to get stuck at one of the extremes then just pulses. Here is the code I am using:-

#include <SoftwareServo.h> 

SoftwareServo myservo;   


void setup() 
  myservo.attach(0);  

void loop() 
 
  myservo.write(10);   
 SoftwareServo::refresh();   
  delay(1000);                          
 
myservo.write(179);       
 SoftwareServo::refresh();
  delay(1000);                           


Any help on this would be appreciated.

Ben


On 27 March 2014 07:15, jfowkes <james...@gmail.com> wrote:
If your program complies but doesn't upload, the problem isn't with your code or the servo library.

What are you using the program the ATTINY? What is the precise error message you're getting?

--
You received this message because you are subscribed to the Google Groups "Nottingham Hackspace - Nottinghack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nottinghack...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jfowkes

unread,
Mar 27, 2014, 5:15:44 AM3/27/14
to notti...@googlegroups.com
If you read the introduction to the SoftwareServo page (http://playground.arduino.cc/ComponentLib/Servo#.UzPrz_l_utY), you'll see the following:

"you must call the SoftwareServo::refresh() method at least once every 50ms or so to keep your servos updating."

Can you see where the problem lies?

Benjamin Crowe

unread,
Mar 27, 2014, 5:19:05 AM3/27/14
to notti...@googlegroups.com
#include <SoftwareServo.h> 

SoftwareServo myservo;   


void setup() 
  myservo.attach(0);  

void loop() 
 
  myservo.write(10);   
 SoftwareServo::refresh();   
  delay(1000);                          
 
myservo.write(179);       
 SoftwareServo::refresh();
  delay(1000);                           

SoftwareServo::refresh(50); //I take it this is the problem I had I wasn't refreshing the servo so, is that the reason why it was getting stuck??



jfowkes

unread,
Mar 27, 2014, 5:24:40 AM3/27/14
to notti...@googlegroups.com
Not quite. The refresh method doesn't need to be given a number. But look at how long you are delay()ing for between refreshes...

Chris ((drazziweht)) Cain

unread,
Mar 27, 2014, 7:59:14 AM3/27/14
to notti...@googlegroups.com
>Any help on this would be appreciated

Try this....



 #include <SoftwareServo.h> 
SoftwareServo myservo;   
int loopcount ;


void setup() 
 {
    myservo.attach(0);  
     loopcount = 0;
 
 
void loop() 
  
  switch(loopcount) {
     case 1:
             myservo.write(10);
     break ;

     case 50:  // 1 second (50 * 20 msec)
             myservo.write(179);
     break ;

   case 100:   // 2 seconds
           loopcount = 0;
    break ;
   }
 loopcount++ ;
 SoftwareServo::refresh();
 // loop every 20ms
 delay(20) ;



Benjamin Crowe

unread,
Mar 27, 2014, 8:40:02 AM3/27/14
to notti...@googlegroups.com
Thanks Chris I will give it a go.



jfowkes

unread,
Mar 27, 2014, 10:01:30 AM3/27/14
to notti...@googlegroups.com
If you just copy-and-paste Chris's code, make you you understand what it does and why it works!

Little point using an answer without understanding it.
Reply all
Reply to author
Forward
0 new messages