Dave,
The original Arduino Servo library used PWM on AVR devices to drive the servos, but it was replaced (2012?) with the modern library, which uses timers. The new library provides the advantage of allowing any pin to control a servo—the old one was limited, I think, to only pins 8 and 9—but introduced the sort of jitter I think you're seeing, because Servo and SoftwareSerial have competing interrupt/timer needs.
There's a library floating around called PWMServo that’s basically just a repackaging of the old library. I don’t know whether it would even work with ATTiny, but it might provide some reference for you.
Mikal Hart
--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/DB7PR07MB47484F1DAE53005F90A6B50BD3A89%40DB7PR07MB4748.eurprd07.prod.outlook.com.
--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/DB7PR07MB47488C4DA80DE4D3524E1501D3A89%40DB7PR07MB4748.eurprd07.prod.outlook.com.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/CO1PR11MB4930AD03E417D55B42E1E839CCA89%40CO1PR11MB4930.namprd11.prod.outlook.com.
Sadly PWMServo doesn't support the ATTiny series and converting it to do so is way beyond my abilities :-(
I'm sure that using the hardware PWM ability of the ATTiny84 would solve my problem.
Dave.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/CO1PR11MB4930AD03E417D55B42E1E839CCA89%40CO1PR11MB4930.namprd11.prod.outlook.com.
--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/DB7PR07MB47488C4DA80DE4D3524E1501D3A89%40DB7PR07MB4748.eurprd07.prod.outlook.com.
Yes, it's the ATTinyCore ... I wasn't aware there was an alternative ;-)
Regards,
Dave
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/B30494DD-4633-456E-B715-D1F45C49719B%40ajsystems.co.nz.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/DB7PR07MB4748B747EBBFFFAA35CF9737D3AA9%40DB7PR07MB4748.eurprd07.prod.outlook.com.
Servo.h uses the hardware PWM AFAIK so interrupts shouldnt affect it ?
Problem solved !! :-)
I tried a few of the suggestions made here with varying degrees
of success, none of them 100%, sadly.
However, since I am already "bit banging" the stepper motor and it occurred to me to try that approach on the servo.
I tried the following :-
void moveServo(int posn) { // posn is angle in degrees
0-120
int pulse = map(posn,0,120,1000,2000); // calc required pulse
width
int loops = (abs(posn) * 10) + 1; // Always need at least 1
for (int i=0;i<loops;i++)
{
digitalWrite(8, 1); // start pulse
delayMicroseconds(pulse);
digitalWrite(8, 0); // end of pulse
delayMicroseconds(10000); // Split because it is limited
to 16383 uSec as per Arduino ref
delayMicroseconds(10000 - pulse);
}
}
Originally I thought that I'd need a chain of pulses to get the servo to the target position - however, I discovered that the 9G servos (well the ones I have, at least) only need a single pulse of the appropriate width !! which made the code a lot faster and smaller ending up as :-
void moveServo(int posn) { // posn is angle in degrees
int pulse = map(posn,0,120,1000,2000); // calc required pulse
width
digitalWrite(8, 1); // start pulse
delayMicroseconds(pulse);
digitalWrite(8, 0); // end of pulse
delayMicroseconds(10000); // Split because it is limited to
16284 uSec
delayMicroseconds(10000 - pulse);
}
and I suspect that the last two delays could be dropped but I'll probably leave them in as a safety measure to prevent the pulses getting too close.
Anyway, with SoftwareSerial sending and receiving data I see no "twitches" :-)
I suspect that the "1 pulse" feature is specific to the 9G servo
so may not be suitable for other types.
Thanks for all the advice,
Dave
--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/040C1513-53A5-4B89-B300-566873891560%40me.com.
The good news is this is probably better than what you were doing to start with anyway.
From: devel...@arduino.cc <devel...@arduino.cc> On Behalf Of Dave
Sent: Friday, October 1, 2021 9:24 PM
To: devel...@arduino.cc
Subject: Re: [Developers] Problem with softwareserial on ATTint84
Problem solved !! :-)
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/DB7PR07MB4748911A953C33AAFC9D98BCD3AC9%40DB7PR07MB4748.eurprd07.prod.outlook.com.
--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/040C1513-53A5-4B89-B300-566873891560%40me.com.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/DB7PR07MB4748911A953C33AAFC9D98BCD3AC9%40DB7PR07MB4748.eurprd07.prod.outlook.com.
Maybe just remove the delays all together and write it to use a counter and if statements testing time elapsed.
From: devel...@arduino.cc <devel...@arduino.cc> On Behalf Of Jon Perryman
Sent: Saturday, October 2, 2021 10:17 PM
To: devel...@arduino.cc
Subject: Re: [Developers] Problem with softwareserial on ATTint84
This is a terrible solution but if it works for you then great. It's far better than the first. Expect the servo to twitch.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/CAByJhJkuu72Sdj_0VRJVG_WobtO%2BpGPJ8yeSK140EQy3SyK9QQ%40mail.gmail.com.
I agree that it's not ideal, but it works and satisfies my requirements.
The serial I/O is trivial (1 byte received, 3 or 4 times per second and one byte sent (an acknowledgement) at the same rate - strictly 1/2 duplex), much more important is the consistency of the servo position.
Since there is no PWMServo that works for the ATTiny84 I have little or no choice unless I am able to spend a lot of time trying to get PWMServo working on the 8MHz ATTiny and dealing with the steep (for me) learning curve.
Those servos do NOT like a pulse repetition rate of more than 50Hz, I know, I tried so a delay is needed after the 1-2mS pulse. I may change it to use "millis()" to keep track of when the last pulse was issued and enforce a delay if its less than 20mS.
Dave
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/CAByJhJkuu72Sdj_0VRJVG_WobtO%2BpGPJ8yeSK140EQy3SyK9QQ%40mail.gmail.com.
I guess what I was saying is you don’t need to do a delay if you keep track of current puls pseudo code is like
StartTime (starting time in milliseconds)
curTiome (current time in miliiseconds)
delayTime (time to delay in milliseconds)
loop{
currentTime set the current time
if ((currentTime – startTime) > delayTime){
do your servo stuff
}
}
This gets rid of the use of the delay function which is a good thing.
Sent: Sunday, October 3, 2021 12:39 AM
Subject: Re: [Developers] Problem with softwareserial on ATTint84
I agree that it's not ideal, but it works and satisfies my requirements.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/DB7PR07MB4748C11355126EE1C80CF986D3AD9%40DB7PR07MB4748.eurprd07.prod.outlook.com.
unless I am able to spend a lot of time trying to get PWMServo working on the 8MHz ATTiny
--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/287CC454-2D01-4F20-9BC8-F946E10BDC74%40me.com.