I am looking for solution for something wrong happen in my programme i have configuration for control RC motor over RasPi using Wiring Pi here is code


// header files for wiring to servo WIringPi
#include <wiringPi.h>
#include <softPwm.h>

#define PIN 0

//main programme that inittiate all socket for server
int main()
int i;
        //declaration for Wiring COnfiguration
                printf("Setup to servo fail");
                printf("Servo setup Done \n");


        printf("started \n");

 for (;;)
        printf("start a loop");
        for (i = 0 ; i <=180  ; ++i)
                softPwmWrite (PIN, i) ;
                printf("\n Loop : %d ",i );
                delay (100) ;
        delay (300) ;

        for (i = 180 ; i >= 0 ; --i)
                softPwmWrite (PIN, i) ;
                printf("\n Loop : %d",i);       
                delay (100) ;
delay (10) ;

i dont know what is wrong with this code

When It takes angle as 5 it start moving and moves total 180 degree when input integer i = 25

so its like

i=5 then 0 degree and i=25 then 180 degree

If anyone can help what is wrong?

  • Servos expect pulses in the (approximate) range 1000 µs to 2000 µs. How long are the pulses being generated by the code? – joan Feb 22 '16 at 8:31

I have run the program whilst monitoring the pulses with my piscope.

When softPwmWrite is called with a parameter i then pulses of 100*i µs are generated.

This means your servo is responding to pulses in the range 500 µs (i=5) to 2500 µs (i=25).

Sending pulses outside that range will be damaging the servo (some servos will strip their gears).

I suggest you constrain the calls to softPwmWrite to be between 5 and 25.

  • Thanks joan for your valuable suggestion but the issue is my input is coming form another source that is going to control motor i am still confused how to make it possible as you explain totally blank. By d way thanks for your valuable response I appreciate your help Thanks Nitin amru – nitinmaru Feb 24 '16 at 9:01
  • Okay i have calculated in between value is something like this Kindly do me a favour and please check it Angle_to_move=5+Input*(0.1111) SO this will map input between 5 to 25 Kindly check once and let me know your opinion – nitinmaru Feb 24 '16 at 9:36
  • wiringPi is the wrong tool for the job. Use servoblaster or my pigpio. However, first of all, you need to understand how servos are controlled. Look them up on wiki. – joan Feb 24 '16 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.