Author Topic: Servo Library not supported? [Solved - see here for Servo example!]  (Read 25928 times)

runberde

  • Newbie
  • *
  • Posts: 5
Upon receiving my digispark I have been playing around with what I could do with it. I decided to play with the Servo library in Arduio. It doesn't work... I get this error:

C:\Users\runberde\Desktop\Digispark Ready - Arduino 1.03\libraries\Servo\Servo.cpp:105: error: cannot convert 'volatile uint8_t*' to 'volatile uint16_t*' for argument '2' to 'void handle_interrupts(timer16_Sequence_t, volatile uint16_t*, volatile uint16_t*)'
C:\Users\runberde\Desktop\Digispark Ready - Arduino 1.03\libraries\Servo\Servo.cpp: In function 'void initISR(timer16_Sequence_t)':
C:\Users\runberde\Desktop\Digispark Ready - Arduino 1.03\libraries\Servo\Servo.cpp:151: error: 'TCCR1A' was not declared in this scope
C:\Users\runberde\Desktop\Digispark Ready - Arduino 1.03\libraries\Servo\Servo.cpp:152: error: 'TCCR1B' was not declared in this scope
C:\Users\runberde\Desktop\Digispark Ready - Arduino 1.03\libraries\Servo\Servo.cpp:159: error: 'TIFR1' was not declared in this scope
C:\Users\runberde\Desktop\Digispark Ready - Arduino 1.03\libraries\Servo\Servo.cpp:160: error: 'TIMSK1' was not declared in this scope

thoughts anyone?!
« Last Edit: January 16, 2013, 04:21:13 pm by runberde »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #1 on: January 16, 2013, 01:42:15 pm »

Edit: This did not work - read on

The servo library will need to be ported to work with the Attiny85

This might work: http://www.cunningturtle.com/attiny4585-servo-library/
« Last Edit: January 22, 2013, 12:32:47 pm by digistump »

runberde

  • Newbie
  • *
  • Posts: 5
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #2 on: January 16, 2013, 02:34:03 pm »
OK, so now it compiles but when I upload the code and hook up a servo, nothing happens. It jitters at startup and then nothing after the 5 seconds load time. My code looks like this:

// Sweep
// by BARRAGAN
// This example code is in the public domain.


#include
 
Servo8Bit myServo;  // create servo object to control a servo
           
 
   
 
void setup()
{
  myServo.attach(0);  // attaches the servo on pin 0 to the servo object
}
 
 
void loop()
{
myServo.write(180);    //turn to position 180 degrees
delay(1000);
myServo.write(0);      //turn to position 0 degrees
delay(1000);

}

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #3 on: January 16, 2013, 03:22:59 pm »
Looks like this was built for 8Mhz clocks only - the Digispark runs at 16.5Mhz (arduino at 16Mhz) - I\'ll take a look, should be an easy change

runberde

  • Newbie
  • *
  • Posts: 5
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #4 on: January 16, 2013, 03:31:07 pm »
Cool...looking to build a small robotic arm that controls a pencil on a piece of paper!!! I

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #5 on: January 16, 2013, 03:36:18 pm »

NOTE - READ ON - THIS DID NOT WORK

Try this fork - I added 16mhz support and then told it to use it for 16.5mhz, it should be close enough...

https://github.com/digistump/Servo8Bit
« Last Edit: January 22, 2013, 12:30:25 pm by digistump »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #6 on: January 16, 2013, 03:36:47 pm »
BTW: Servo8Bit.cpp is the only file that changed

runberde

  • Newbie
  • *
  • Posts: 5
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #7 on: January 16, 2013, 03:50:28 pm »
OK, just so we cover all of the bases here. What I did to be sure of things as follows:

1. deleted previous library folder for Servo8Bit
2. re-dowloaded the newest version (with the digistump corrections)
3. added that folder (unzipped) to my libraries folder and used it in the following code:


#include  //import 8bit servo library

Servo8Bit myServo;  //servo class object called myServo

void setup()
{
  myServo.attach(0);  //servo attached to pin 0
}

void loop()
{
  myServo.write(0);
  delay(500);
  myServo.write(45);
  delay(500);
}

still nothing!!! I don\'t know library files enough to be able to make corrections/ changes myself. I just know how to poach off of others hard work :)  !!!

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #8 on: January 16, 2013, 04:11:18 pm »

THIS ONE DOESN'T WORK EITHER - almost there - read on

Try this one: http://playground.arduino.cc/ComponentLib/servo

With this code:
Code: [Select]
#include <SoftwareServo.h>

SoftwareServo servo;

void setup()
{
 
  servo.attach(0);

}

void loop()
{
  servo.write(180);                  // sets the servo position according to the scaled value
  delay(15);
  SoftwareServo::refresh();
delay(1000);
  servo.write(0);                  // sets the servo position according to the scaled value
  delay(15);
  SoftwareServo::refresh();
delay(1000);
}
 

« Last Edit: January 22, 2013, 12:31:34 pm by digistump »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #9 on: January 16, 2013, 04:11:43 pm »
to clarify you want to grab SoftwareServo.zip from that page

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #10 on: January 16, 2013, 04:15:45 pm »

THIS WORKS - with this library http://playground.arduino.cc/ComponentLib/servo

Actually this code - untested
refresh has to be called every 50ms to keep servos updated

Code: [Select]

#include <SoftwareServo.h>

SoftwareServo servo;

void setup()
{
 
  servo.attach(0);

}

void loop()
{
  servo.write(180);                  // sets the servo position according to the scaled value

delay_refresh(1000);

  servo.write(0);                  // sets the servo position according to the scaled value

delay_refresh(1000);
}


void delay_refresh(int delaytime){

   for(int x=0;x<delaytime;x=x+25){

      delay(25);
      SoftwareServo::refresh();
   
   }

}
« Last Edit: January 22, 2013, 12:32:14 pm by digistump »

runberde

  • Newbie
  • *
  • Posts: 5
Servo Library not supported? [Solved - see here for Servo example!]
« Reply #11 on: January 16, 2013, 04:19:57 pm »
Yeah, that worked!!! Thank you!!!

Rboyer

  • Newbie
  • *
  • Posts: 6
Re: Servo Library not supported? [Solved - see here for Servo example!]
« Reply #12 on: January 21, 2013, 02:31:06 pm »
One minor note and one, perhaps, larger note. Before all that, Eric, nicely done. Fully met my expectations.


1) I needed to add #include <Arduino.h> at the beginning of the SofwareServo.cpp file to get it to compile. Didn't see any notes to that effect and I wonder if it has to do with my environment settings, or something else. Despite MANY years of embedded development, I'm absolutely new to Arduino so for me the IDE is a double edged sword - I like that it makes things so simple, but when something isn't working, it hides a lot of what's going on under the hood.


2) I noticed that the Servo8Bit files don't match. That is, the header file refers to the class Servo8Bit, but the Servo8Bit.cpp file has the class named ServoSequencer. Might need to look at that.


Regards,
Roger

Rboyer

  • Newbie
  • *
  • Posts: 6
Re: Servo Library not supported? [Solved - see here for Servo example!]
« Reply #13 on: January 21, 2013, 02:41:57 pm »
... or I could read down to the bottom of the file and realize that there is, in fact, a Servo8Bit class around line 795 ... disregard point #2 above ...

Rboyer

  • Newbie
  • *
  • Posts: 6
Re: Servo Library not supported? [Solved - see here for Servo example!]
« Reply #14 on: January 22, 2013, 12:27:10 pm »
With the benefit of the O'Scope at the office, I'm noting some troubling behavior with the Servo8Bit code above. Did it ever run for anyone on Digispark or as an Arduino library?


When I do nothing more than:
Code: [Select]
#include <Servo8Bit.h>


Servo8Bit servo;


void setup()
{
  pinMode(3,OUTPUT);
  digitalWrite(3, LOW);
//  servo.attach(5);
}


void loop()
{
//  servo.write(0);                  // sets the servo position according to the scaled value
  delay(50);
  digitalWrite(3, HIGH);
 
//  servo.write(45);                  // sets the servo position according to the scaled value
  delay(50);
  digitalWrite(3, LOW);
}


I never see pin 3 toggle. Remove the instantiation "Servo8Bit servo;" and still nothing. (Of course, if I remove the #include as well, then I do see pin 3 toggle).


After looking through the code, I thought it might be something wrong with modifying the vector table so I wrapped the timer compare ISRs (lines 704 - 746) in #if 0/#endif and still nothing. It looks as if setup() isn't even being called because pin 3 hangs high. Stuck here - any clues?