Author Topic: Digispark Puppet Control!  (Read 3916 times)

Slugbut

  • Newbie
  • *
  • Posts: 1
Digispark Puppet Control!
« on: January 07, 2017, 06:26:14 am »
Hi,

I've been looking at the Digispark and the button Shield but before I buy them I wanted to know if this would work?

I would like to be able to mount the digispark and button inside the head of the puppet so that the puppeteer could press the button and make the servo move an eyelid mechanism, so that the puppet "blinks" a press to close and a release of the button to return the servo.
Is this possible please?

Once programmed, would the digispark automatically remember the programming for the next performance?

I know, a total newb!!

Any help would be great,

Thanks,

Jon

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Digispark Puppet Control!
« Reply #1 on: January 07, 2017, 05:10:59 pm »
So just to confirm: button released (normal state) means eye(s) open, button pressed means eye(s) closed?

Yes, that sounds straightforward enough. Once the Digispark is programmed, it will remember the program until is is erased. I would think you would power it with a USB powerbank for simplicity, and switch it on/plug it in at the start of the performance, and then off again/unplug when you're finished, and also unplug it whenever it needs charging.

Sounds like fun...  :D


exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Digispark Puppet Control!
« Reply #2 on: January 07, 2017, 06:30:24 pm »
Pete, spent a little time researching this and yes the basic code should be straight forward but what Servo lib to use is will be an issue. From what little I could gather, the standard Servo lib uses a 16bit timer and the Digispark (as an Attiny85 I think only has and 8 bit timer(s)). I tried to put together a simple example this afternoon and had the compiler complain when using the Servo lib with Digisark board selected.

There are a couple of other libs available that are targeted at the Attiny, Servo8Bit and SoftwareServo.  However, I think they only support 8Mhz and 1Mhz clocks. And so it goes. I've never selected the Digispark 8Mhz board option in the IDE and don't want to without knowing the consequence (e.g. no USB access). Another route is to mod the Servo8Bit lib to support 16Mhz clock (actually 16.5Mhz for a USB connected Digispark) and 16Mhz when externally powered (again I think). Pretty sure configuring for 16Mhz would be straight forward and perhaps the 16.5Mhz will just be inaccurate. I'm curious enough to try and mod the Servo8bit but do not want to brick my Digispark. I'd be learning as I go and I'm less likely to use a Digispark to drive a servo but it would be nice to have.

Perhaps the above is why there is no Digispark servo example in the lib.

I have limited knowledge with respect to clock related stuff but high curiousty (a dangerous combo). In any case (unless I'm totally off on this) I think the clock related stuff will come into play. Perhaps I'm over thinking this and I'm either wrong or someone else has already solved the problem.

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Digispark Puppet Control!
« Reply #3 on: January 07, 2017, 11:23:12 pm »
OK, since my last post...

1. Established a baseline to prove my servo works (first time using it) on an UNO using the Sweep example. Check.
2. Mod to Servo8Bit lib files to set prescaler to 128 TIMER0 for 16Mhz and 16.5Mhz (I know). Sweep example compiles but no go. BTW Digispark returns F_CPU 16500000L always regardless of power USB or VIN. when IDE has Digispark default 16.5Mhz board selected.
3. Tried SoftwareServo lib strait up no changes. Sweep example compiles but again no go. And... it only supports 8Mhz according to the docs/comments.

Also do know if this is a power issue. I tried pulling from the Digispark's 5V for the servo and also external 5V direct to the servo with grounds tied. No luck. Could perhaps try an Oak at 3.3v to see if the servo can handle lower power. BTW I have the servo that comes in the Oak kit (SG90 Micro Servo).

Haven't tried a straight Attiny85 at 8Mhz but that might work. I'd have to pull one out and use my little wire ISP to program it. Both Servo8Bit ad SoftwareServo libs where intended for the Attiny at 8Mhz although Servo8Bit supposedly supports 1Mhz.

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Digispark Puppet Control!
« Reply #4 on: January 08, 2017, 01:01:02 am »
Yeah, the Servo8bit just jitters for me if I try it using the No USB - 8Mhz option... I suspect it doesn't set the clock the way the library wants it... I really don't know... I can't be bothered looking into that one.

The SimpleServo library that is part of the DigisparkArduinoIntegrations package still works though, and you can leave the Digispark in the default 16.5Mhz variant. You'll want both the .h and .cpp files, and the keywords.txt if you want the Arduino IDE to do its syntax highlighting thing. Shove the three files in a SimpleServo folder in your sketchbook library folder and you'll be good to go with the example I've included below.

AFAIK, the No USB options simply mean that - not using the DigiUSB, DigiKeyboard, and using a non-USB clock speed. Micronucleus is still there doing it's thing, so you don't lost the ability to reprogram your Digispark... ;)

Code: [Select]
#include <SimpleServo.h>

SimpleServo servo;

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

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

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

Edit: Library and example attached for ease...  ;)
« Last Edit: January 08, 2017, 01:17:54 am by PeterF »

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Digispark Puppet Control!
« Reply #5 on: January 08, 2017, 10:27:02 am »
Yeah, you basically posted the Sweep example same one I used with no luck with the SoftwareServo library. I'll have to take a second look. I may have grabbed it from somewhere else and not the DigisparkArduinoInegrations package.

Quote
AFAIK, the No USB options simply mean that - not using the DigiUSB, DigiKeyboard, and using a non-USB clock speed. Micronucleus is still there doing it's thing, so you don't lost the ability to reprogram your Digispark...

Ah. Thanks for the clearing up the confusion on selecting other Digispark options. Unless I missed something, the Wiki wasn't explicit enough for me on this so I opted not to take the chance on trying 8Mhz.

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Digispark Puppet Control!
« Reply #6 on: January 08, 2017, 11:11:24 am »
OK, with the correct lib (SimpleServo) it works at the 16.5Mhz default for Digispark (sort of). For whatever reason I do not get the full 180 sweep. Perhaps more like 0 to 160-170. The servo is 0-180 capable.  Tabling for now as this pull me off my project. Good to know it works if I need it. I'll figure out the lack of full sweep some other time. Digispark... get back in the box.