Digispark as multiple servo driver.
Posted: 09 Jul 2019, 13:11
I will have a go at programming the Digispark as a multiple servo driver, to be used for instance onboard a model as a sequencer for a retractable landing gear with -doors or such.
I have done similar projects before, but these were based on the 16-bit ProMini or Nano boards, so I could use the Servo library from the Arduino IDE. The Digispark is based on the ATtiny85, which has an 8-bit processor and requires a different library. I found one on the net: http://www.cunningturtle.com/attiny4585-servo-library/ , installed it and made use of it in a very simple sketch, just driving a single servo to a fixed position. I avoided the use of Delay(), to prevent any clashes in the timing. Alas, no luck, none of the pins showed any pulses when checked with a servo and Phil_G's pulse tester.
Next, I wrote a simple sketch using the standard IDE Delay() function, similar to the familiar Blinky, but with writeMicroseconds() set to 1500 high and 18500 low periods to create a PWM output. That worked, but things were not as expected:
- the output pin had been specified as 3 (later PB3), but the output appeared on PB1 instead. Note that pin #3 on the ATtiny85 is specified as PB4, not PB1. Go figure
- the pulses came out as 750, with a frame time of 10000, so only half the value specified. I programmed the Digispark with the timer set at 8 MHz. In order to double the delay periods I guess I have to set it at 4 MHz, but the only other options were 1 MHZ and 16 MHz. I tried both, but both did not produce a readable result on the pulse checker, probably because they were out of the normal PWM range.
I could continue on that route by simply multiplying the delays by 2, or try to follow the suggestions Phil made here, I will see where it gets me.
Cheers,
Max.
I have done similar projects before, but these were based on the 16-bit ProMini or Nano boards, so I could use the Servo library from the Arduino IDE. The Digispark is based on the ATtiny85, which has an 8-bit processor and requires a different library. I found one on the net: http://www.cunningturtle.com/attiny4585-servo-library/ , installed it and made use of it in a very simple sketch, just driving a single servo to a fixed position. I avoided the use of Delay(), to prevent any clashes in the timing. Alas, no luck, none of the pins showed any pulses when checked with a servo and Phil_G's pulse tester.
Next, I wrote a simple sketch using the standard IDE Delay() function, similar to the familiar Blinky, but with writeMicroseconds() set to 1500 high and 18500 low periods to create a PWM output. That worked, but things were not as expected:
- the output pin had been specified as 3 (later PB3), but the output appeared on PB1 instead. Note that pin #3 on the ATtiny85 is specified as PB4, not PB1. Go figure
- the pulses came out as 750, with a frame time of 10000, so only half the value specified. I programmed the Digispark with the timer set at 8 MHz. In order to double the delay periods I guess I have to set it at 4 MHz, but the only other options were 1 MHZ and 16 MHz. I tried both, but both did not produce a readable result on the pulse checker, probably because they were out of the normal PWM range.
I could continue on that route by simply multiplying the delays by 2, or try to follow the suggestions Phil made here, I will see where it gets me.
Cheers,
Max.