ATTiny85; Stepper wont rotate

Hello everyone,

I want to control a Servo (SG90) with my Digispark ATTiny85. The problem is, that the servo doesnt move (It sometimes jitters a bit when i pull the PWM pin out and put it back in, but thats it). I already checked all the cables and also swapped them. I also tried different pins on the digispark but that also didnt work.

Heres my code:

#include <SoftRcPulseOut.h>

SoftRcPulseOut ser;

#define REFRESH_PERIOD_MS 20
#define NOW 1

int pos = 0;

void setup(){
  ser.attach(1);
}

void loop(){
  ser.write(80);
  delay(1000);
  ser.write(10);
  delay(1000);
}

I would be very grateful if someone would help me

I assume/hope you are using some kind of servo driver module/chip, since it's unrealistic to expect you can run a servo directly from an ATtiny pin. Can you link to the driver you're using?

Thanks for the reply. No, i am not using a driver module. Ive already seen many videos where they do it directly from the ATTiny: ATTiny85 Servo Control Led Blinking Installation Alternative to Arduino - YouTube

Ok, looks like your particular servo has a simple integrated driver circuit built into it, so it should work.

Have you read this in the specification of the library you use?

static uint8_t refresh(bool force = false);    // must be called at least every 50ms or so to keep servo alive
                              // you can call more often, it won't happen more than once every 20ms

You mean this?

   delay(REFRESH_PERIOD_MS);
    SoftRcPulseOut::refresh(NOW)

I added it to my code, but it still doesnt work:

#include <SoftRcPulseOut.h>

SoftRcPulseOut ser;

#define REFRESH_PERIOD_MS 20
#define NOW 1

int pos = 0;

void setup(){
  ser.attach(1);
}

void loop(){
  for(pos = 0; pos < 180; pos += 1)
  {
    ser.write(pos);
    delay(REFRESH_PERIOD_MS);
    SoftRcPulseOut::refresh(NOW);
  }
  
  for(pos = 180; pos >= 1; pos -= 1)
  {
    ser.write(pos);
    delay(REFRESH_PERIOD_MS);
    SoftRcPulseOut::refresh(NOW);
  }
}

What are you using for the servo power supply, which must be able to supply 4.8 to 6V at 1 Ampere?

Did you connect the all the grounds?

Have you tried with my ATTinyCore using the included Servo (or Servo_ATTinyCore if you have a Servo library in your libraries folder - write as if you were sing servo, except include Servo_ATTinyCore.h intead of Servo.h) library? It supports the digispark/micronucleus t85's and and is believed to work.....

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.