I'm trying to get my raspi zero to move an SG90 PWM driven servo. I have achieved this with python already using the gpiozero library, so I know my hardware works but I am trying to do it with C using the wiringPi library. when I compile and run the executable (using sudo) I get no errors and everything seems to work, but the servo doesn't move at all.
I assumed I was using the wrong pin number at first. I found this post Raspberry pi Software Driven PWM using C++ and I used the table offered in one of the answers. The pin I'm using is physical pin 11, the 6th pin up from the square pin 1, aka GPIO17. I've tried using 11 with wiringPiSetupPhys(), 17 with wiringPiSetupGpio(), and 0 with wiringPiSetup(), getting the same result each time. I initially tried writing 50 and then changed it to 10000, but both times got nothing
here's my code:
#include <stdio.h>
#include <wiringPi.h>
#include <softPwm.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#define PWM_PIN_NUM 17
int main(){
if(wiringPiSetupGpio()){
printf("Failed to setup wiringPi\n");
}
pinMode(PWM_PIN_NUM, OUTPUT);
if(softPwmCreate(PWM_PIN_NUM, 0, 100)){
printf("Failed to init pwm pin\n");
}
printf("Successfully setup wiringPi and init pwm pin\n");
softPwmWrite(PWM_PIN_NUM, 10000);
sleep(1);
printf("%s: %d\n", strerror(errno), errno);
}
it always outputs "sucessfully setup etc etc" and errno is always 0
sudo pigpiod
thenpigs s 17 1000
,pigs s 17 2000
to move your servo.